Okay I still need some help with this. For the life of me I cannot determine how to switch back and forth between windowed and fullscreen (exclusive) mode. When the user hits the key, this function is called:
Code:
BOOL DXAppWin::ChangeDisplayMode(BOOL bFullScreen, int nWidth, int nHeight, int nBPP) {
// only do this when we're active
if (!IsActive())
return FALSE;
// do not render any frames until we're done
m_bActiveApp = FALSE;
// print a debug message
if (bFullScreen)
PrintDebugMsg(TRUE, TRUE, _T("Changing game display to fullscreen mode (%dx%dx%d)"),
m_nWidth, m_nHeight, m_nBitsPerPixel);
else
PrintDebugMsg(TRUE, TRUE, _T("Changing game display to windowed mode (%dx%d)"),
m_nWidth, m_nHeight);
// release all DirectDraw surfaces (m_lpFront and m_lpBack)
DDReleaseSurfaces();
// set the new display data
if (nWidth > 0)
m_nWidth = nWidth;
if (nHeight > 0)
m_nHeight = nHeight;
if (nBPP > 0) {
switch (nBPP) {
case 8:
case 16:
case 24:
m_nBitsPerPixel = nBPP;
break;
case 32:
default:
m_nBitsPerPixel = 32;
break;
}
}
m_bFullScreen = bFullScreen;
// finalize the mode change by reinitializing the surfaces
while (true) {
if (!DDSetCoopLevel()) break;
if (!DDSetDisplayMode()) break;
if (!DDCreateSurfaces()) break;
if (!InitBitmap()) break;// just set old pointers to the new surfaces
// determine the new window style
int nWndStyle = m_bFullScreen ? WS_POPUPWINDOW :
WS_OVERLAPPEDWINDOW & ~(WS_MAXIMIZEBOX | WS_THICKFRAME);
// change the window style
::SetWindowLong(m_hWnd, GWL_STYLE, nWndStyle);
if (!m_bFullScreen) {
// move window to the top left corner
SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
m_bActiveApp = TRUE;
return TRUE;
}
// something failed so reactivate the app, then close it
m_bActiveApp = TRUE;
Close();
return FALSE;
}
If you can provide me with any assistance, please do (sample code is very welcome). Thanks.
[edit]
By the way, when I run this the way it is I am almost successful going from windowed to fullscreen. The only problem is that nothing gets drawn to the screen except GDI drawing and filling the back surface with a color.
Going from fullscreen to windowed is a much different story. The entire game screen disappears and I see some of my desktop (and other running apps) but with pieces of it blacked out and the game continues running (I know because I hear the music and the game responds to my mouse and keyboard input correctly) but there is no window anywhere to be seen.
[/edit]
[edit]
Okay, I've _finally_ figured it out. It was simply that my bitmaps were screwed once I did the mode switch and I wasn't properly handling them. So now before the mode switch I release all the bitmap surfaces and after the mode switch I recreate them. I don't actually know if that's quite proper, but it seems to work.
[/edit]