Skip to main content
gamedev.net
🔒 Locked

Help switching window modes

Started by WebsiteWill Nov 22, 2003 at 11:18 AM 4 replies 750+ views
Original Post
WebsiteWill
WebsiteWill
Hello. I am trying to implement the ability to change between fullscreen and windowed display modes. I can currently start the app in either mode correctly. If switching from windowed to fullscreen everything is fine. Then entire screen clears to blue and the window sets to WS_POPUP. But in going from fullscreen back to windowed, the whole window area gets cleared to blue instead of just the clients area. The Menu bar and such are there because they react to mouse clicks but they do not show. When I start the app I go through the normal windows process of creating a window 640x480 on an 800x600 display. In setting up DirectX I initialize two separate D3DPRESENT_PARAMS. One for windowed and one for fullscreen. These remain during runtime to make it easier to switch between them. I then call CreateDevice with the appropriate set of PRESENT_PARAMS. This part works groovy. I have these functions for changing modes.
void cGraphicsManager::ToggleFullscreen()
{
    if(m_bWindowed)
    {
	m_bWindowed = false;
	AdjustWindowForChange();
	Reset3DEnvironment();		
    }
    else
    {
	m_bWindowed = true;
	AdjustWindowForChange();
	Reset3DEnvironment();		
    }
}

void cGraphicsManager::AdjustWindowForChange()
{
    if( m_bWindowed )
    {
        // Set windowed-mode style

        SetWindowLong( cGlobalApp.GethWnd(), GWL_EXSTYLE,  
                       m_dwWindowStyle );
    }
    else
    {
        // Set fullscreen-mode style

        SetWindowLong( cGlobalApp.GethWnd(), GWL_EXSTYLE, 
                       m_dwFullscreenStyle );
    }
}

void cGraphicsManager::Reset3DEnvironment()
{
    HRESULT hr;

    // Reset the device

    if(m_bWindowed)
    {
        hr = m_pd3ddCurrentDevice->Reset(&m_ppWindowed);
	if(hr != D3D_OK)
	{
		MessageBox(cGlobalApp.GethWnd(),
                           "Reset", "Reset3DEnvironment",
                           MB_YESNO);
	}
	SetWindowPos(cGlobalApp.GethWnd(), HWND_TOP, m_iXPos, 
                     m_iYPos, m_iWindowWidth, m_iWindowHeight,
                     SWP_SHOWWINDOW);
    }
    else
    {
	hr = m_pd3ddCurrentDevice->Reset(&m_ppFullscreen);
	if(hr != D3D_OK)
	{
		MessageBox(cGlobalApp.GethWnd(), "Reset",
                           "Reset3DEnvironment", MB_YESNO);
	}
    }	
}
Any ideas here? Thanks, Webby
S1CA
S1CA
Silly question maybe, but have you remembered to use AdjustWindowRectEx() to ensure the client area for the windowed mode window is the same size as the device surface [rather than the surface being the same size as the whole window and D3D clipping to that].


Additionally, have you handled the WM_PAINT, WM_SIZE, WM_NCHITTEST and WM_CLOSE messages in the same way as the sample framework in the SDK?. All of those messages will be relevent to the switching in one way or another.

--
Simon O''Connor
3D Game Programmer &
Microsoft DirectX MVP
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
Supernat02
Supernat02
How are you changing from full screen to windowed? Are you changing the window''s width and height back to the "Restored" state first?
Chris ByersMicrosoft DirectX MVP - 2005
WebsiteWill
WebsiteWill
message proc gets WM_KEYDOWN. I check it for a key. This calls
cGlobalApp.Togglefullscreen() which in turn calls cGraphicsManager.Togglefullscreen().
cGraphicsManager.Togglefullscreen is above. It does AdjustWindowForChange()which AFAICT sets the window to a new style like WS_POPUP or WS_OVERLAPPEDWINDOW which I have stored in a variable from initialization.
This is followed by a call to Reset3DEnvironment() which calls device->Reset and passes in the proper presentation_parameter structure I filled in at Init (I keep one foe windowed and one for fullscreen as a class member for this reason. If switching from fullscreen to windowed I also follow up with a call to SetWindowPos.

It''s obvious that I am drawing to the entire window instead of just the client area but I''m not certain how to solve this. From what I can tell, I''m doing identical to the SDK minus a lot of extra stuff that I don''t need (Dialog boxes and such).

The windowed mode I want will be a fixed size. I will not be allowing the users to select any arbitrary size. They will have the option of resizing up or down within certain limits. The reason I am doing this is is to make the UI easier to manage. Ideally, the game will be fullscreen only but I need windowed mode for debugging reasons so I want it as simple as possible. This means allowing for a window that gives a client area of fixed sizes. For instance I want the user area to be fixed to 640x480 or 800x600. So the overall window size will be that plus size for the Title bar.

Thanks for any help,
Webby
WebsiteWill
WebsiteWill
Anyone know of any tutorials for windowed/fullscreen switching updated for DirectX 9? The ones listed here are for 7 I think and obviously do things a bit differently. I''m still not finding what''s up with my code. AFAICT I''m doing the switching just like the sample code on the SDK does...

Think I may post all my code later for someone to take a look at. It''s bound to be something very silly.

Thanks,
Webby
WebsiteWill
WebsiteWill
Problem solved. Yayyyy!

It appears that I was swapping the values between
GetWindowRect and GetClientRect.

Makes all the difference but darned near impossible to track down.

Webby

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.