I have read through tons of post here on this subject and looked at numerous code examples and for the life of me, I can't get this to work correctly. As far as I can tell, I'm not doing anything different then what I have been seeing.
I start out in windowed mode and then change it to full screen mode and then change it back to windowed mode. Even though I'm resetting the styles via "SetWindowLong" and then calling "SetWindowPos", I'm left with a window with no window frame.
I've tested this ever way I can think of. Any idea of what I might be missing?
I define the styles in the constructor as class members...
CXWindow::CXWindow() :
...
windowedStyle(WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX),
windowedExStyle(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE),
fullScreenStyle(WS_POPUP|WS_VISIBLE),
fullScreenExStyle(WS_EX_TOPMOST)
This is how I create the window.
void CXWindow::CreateXWindow( const HINSTANCE hInst )
{
uint dwExStyle;
uint dwStyle;
RECT rect;
// Set the rect
SetRect( &rect, 0, 0, (int)CSettings::Instance().GetSize().w, (int)CSettings::Instance().GetSize().h );
if( CSettings::Instance().GetFullScreen() )
{
dwExStyle = fullScreenExStyle;
dwStyle = fullScreenStyle;
}
else
{
// Setup the styles
dwExStyle = windowedExStyle;
dwStyle = windowedStyle;
}
// Create the window
hWnd = CreateWindowEx( dwExStyle,
CSettings::Instance().GetGameWndClassName().c_str(),
"",
dwStyle,
rect.left,
rect.top,
rect.right,
rect.bottom,
NULL,
NULL,
hInst,
NULL );
if( hWnd == NULL )
throw NExcept::CCriticalException("Create Window Error",
boost::str( boost::format("There was an error creating the game window.\n\n%s\nLine: %s") % __FUNCTION__ % __LINE__ ));
if( !CSettings::Instance().GetFullScreen() )
{
// Adjust the rect so that the client size of the window is the exact size of the needed resolution
AdjustWindowRectEx( &rect, GetWindowStyle(hWnd), GetMenu(hWnd) != NULL, GetWindowExStyle(hWnd) );
// Position the window in the center of the screen
SetWindowPos( hWnd,
HWND_NOTOPMOST,
(GetSystemMetrics( SM_CXSCREEN ) - (rect.right-rect.left)) / 2,
(GetSystemMetrics( SM_CYSCREEN ) - (rect.bottom-rect.top)) / 2,
rect.right - rect.left,
rect.bottom - rect.top,
SWP_NOACTIVATE );
}
} // CreateXWindow
I call this prior to resetting the DirectX device. I've even recalled it after the device was reset.
void CXWindow::ResetWindowStyle()
{
if( CSettings::Instance().WasScreenModeChanged() )
{
uint dwExStyle = windowedExStyle;
uint dwStyle = windowedStyle;
if( CSettings::Instance().GetFullScreen() )
{
dwExStyle = fullScreenExStyle;
dwStyle = fullScreenStyle;
}
// Change the windows styles
SetWindowLong( hWnd, GWL_STYLE, dwStyle);
SetWindowLong( hWnd, GWL_EXSTYLE, dwExStyle);
}
} // ResetWindowStyle
This is what I call after the device reset. One odd thing to note is that in this function, "AdjustWindowRectEx" does not change the rect like it does when the window was first created. The rect remains unchanged.
void CXWindow::ResetWindowSize()
{
RECT rect;
// Set the rect
SetRect( &rect, 0, 0, (int)CSettings::Instance().GetSizeChange().w, (int)CSettings::Instance().GetSizeChange().h );
if( CSettings::Instance().WasResolutionChanged() || CSettings::Instance().WasScreenModeChanged() )
{
if( CSettings::Instance().WasResolutionChanged() )
{
// Recalculate the default size and ratio
CSettings::Instance().CalcRatio( CSettings::Instance().GetSizeChange() );
// Recalculate the projection matrixes
CalcProjMatrix( CSettings::Instance().GetSizeChange(),
CSettings::Instance().GetDefaultSize() );
}
if( !CSettings::Instance().WasScreenModeChanged() )
{
// Adjust the rect so that the client size of the window is the exact size of the needed resolution
AdjustWindowRectEx( &rect, GetWindowStyle(hWnd), GetMenu(hWnd) != NULL, GetWindowExStyle(hWnd) );
// Position the window in the center of the screen
SetWindowPos( hWnd,
HWND_TOP,
(GetSystemMetrics( SM_CXSCREEN ) - (rect.right-rect.left)) / 2,
(GetSystemMetrics( SM_CYSCREEN ) - (rect.bottom-rect.top)) / 2,
rect.right - rect.left,
rect.bottom - rect.top,
SWP_FRAMECHANGED|SWP_SHOWWINDOW );
}
}
} // ResetWindow