Sign in to follow this  
fabry

wrong behaviour when toggle from fullscreen to window mode

Recommended Posts

fabry    100
Hi, I'm developing a 2d game engine with directx and cpp language. I have a strange behaviour when I switch from fullscreen to window mode. As the application starts (in window mode) I have a client area and the backbuffer size of 800x600 and the window size of 806x625, then I switch to fullscreen and I have the client area size, the backbuffer size and the window size of 800x600 and it's still fine but when I switch back to window mode, the size of the window is wrong: the clint area and the backbuffer size is 800x587 and the window size is 806x612, that is the width is correct but the height is 13px less than what i expect. Here is my code:
//.....
//It's time to change screen mode

//Set the windowRect with the client area size
RECT windowRect;
DWORD dwStyle;

windowRect.left = (long)0;
windowRect.top = (long)0;
windowRect.right = (long)g_engine->Get_screen_width();
windowRect.bottom = (long)g_engine->Get_screen_height();


if(this->full_screen_mode){
        dwStyle = WS_POPUP;
	::ShowCursor(FALSE);

	//Calculate window size from client area and dw_style
	::AdjustWindowRect(&windowRect, dwStyle, FALSE);

	//Change window style/dimension and flush changes
	::SetWindowLongPtr(this->hWnd, GWL_STYLE, dwStyle);
	::SetWindowPos(this->hWnd, NULL, 0, 0, 
	     windowRect.right - windowRect.left, windowRect.bottom - windowRect.top,		//width, height
	SWP_NOMOVE | /*SWP_NOSIZE |*/ SWP_NOZORDER | SWP_FRAMECHANGED);							
}
else{
	dwStyle = (WS_OVERLAPPEDWINDOW | WS_VISIBLE) & ~WS_THICKFRAME  & ~WS_MAXIMIZEBOX;
	::ShowCursor(TRUE);

        //Calculate window size from client area and dw_style

	::AdjustWindowRect(&windowRect, dwStyle, FALSE);

	//Change window style/dimension and flush changes (must call ShowWindow winapi also)
	::SetWindowLongPtr(this->hWnd, GWL_STYLE, dwStyle);
	::SetWindowPos(this->hWnd, HWND_NOTOPMOST, 0, 0, 
		windowRect.right - windowRect.left, windowRect.bottom - windowRect.top,		//width, height
		SWP_NOMOVE | /*SWP_NOSIZE |*/ SWP_FRAMECHANGED);
	::ShowWindow(this->hWnd, SW_NORMAL);							
}

//Reset device
result = this->d3ddev->Reset(&this->p_d3dpp);
if(result == D3D_OK){
....
//.....

I don't understand why the call to ::SetWindowPos(...) set the height of the window to 612 istead of 625. The dwstyle used for the CreateWindow call is the same used to switch the screen mode Thank you for your help Fabrizio

Share this post


Link to post
Share on other sites
Evil Steve    2017
You should reset the device and then change the window style and size, not the other way around. Aside from that, it looks fine. How are you checking the size of the client area and window? GetClientRect() and GetWindowRect()?

Share this post


Link to post
Share on other sites
fabry    100
Hi Steve
thank you for your answer
yes i use ::GetClientRect(this->hWnd, &rect) and ::GetWindowRect(this->hWnd, &windowRect)

I've also tried to reset the device for first, then change the window style/size and then reload all resources but when I'm in fullscreen mode the screen flashes showing me for few time windows, buttons, icons that are behind the "fullscreen window" and when i press the left mouse button i loose the focus and switch to the os.

Fabrizio

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this