Attila,
That solution is OK but it actually makes use of the taskbar to achieve full screen functionality. You don’t need anything that intrusive to accomplish what you want. Here’s an example I just got working:
CCEGLView.h
bool enterFullscreen(int fullscreenWidth=0, int fullscreenHeight=0);
bool exitFullscreen(int windowX, int windowY, int windowedWidth, int windowedHeight, int windowedPaddingX, int windowedPaddingY);
int getFullscreenWidth();
int getFullscreenHeight();
CCEGLView.cpp
int CCEGLView::getFullscreenWidth()
{
return GetDeviceCaps(m_hDC, HORZRES);
}
int CCEGLView::getFullscreenHeight()
{
return GetDeviceCaps(m_hDC, VERTRES);
}
bool CCEGLView::enterFullscreen(int fullscreenWidth, int fullscreenHeight)
{
DEVMODE fullscreenSettings;
bool isChangeSuccessful;
if(fullscreenWidth == 0 || fullscreenHeight == 0)
{
fullscreenWidth = GetDeviceCaps(m_hDC, HORZRES);
fullscreenHeight = GetDeviceCaps(m_hDC, VERTRES);
}
int colourBits = GetDeviceCaps(m_hDC, BITSPIXEL);
int refreshRate = GetDeviceCaps(m_hDC, VREFRESH);
EnumDisplaySettings(NULL, 0, &fullscreenSettings);
fullscreenSettings.dmPelsWidth = fullscreenWidth;
fullscreenSettings.dmPelsHeight = fullscreenHeight;
fullscreenSettings.dmBitsPerPel = colourBits;
fullscreenSettings.dmDisplayFrequency = refreshRate;
fullscreenSettings.dmFields = DM_PELSWIDTH |
DM_PELSHEIGHT |
DM_BITSPERPEL |
DM_DISPLAYFREQUENCY;
SetWindowLongPtr(m_hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST);
SetWindowLongPtr(m_hWnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, fullscreenWidth, fullscreenHeight, SWP_SHOWWINDOW);
isChangeSuccessful = ChangeDisplaySettings(&fullscreenSettings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL;
ShowWindow(m_hWnd, SW_MAXIMIZE);
resize(fullscreenWidth, fullscreenHeight);
return isChangeSuccessful;
}
bool CCEGLView::exitFullscreen(int windowX, int windowY, int windowedWidth, int windowedHeight, int windowedPaddingX, int windowedPaddingY)
{
bool isChangeSuccessful;
SetWindowLongPtr(m_hWnd, GWL_EXSTYLE, WS_EX_LEFT);
SetWindowLongPtr(m_hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE);
isChangeSuccessful = ChangeDisplaySettings(NULL, CDS_RESET) == DISP_CHANGE_SUCCESSFUL;
SetWindowPos(m_hWnd, HWND_NOTOPMOST, windowX, windowY, windowedWidth + windowedPaddingX, windowedHeight + windowedPaddingY, SWP_SHOWWINDOW);
ShowWindow(m_hWnd, SW_RESTORE);
return isChangeSuccessful;
}
Example usage in main.cpp:
// Create the application instance
AppDelegate app;
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
// Set the frame size to the full screen value
eglView->setFrameSize(eglView->getFullscreenWidth(), eglView->getFullscreenHeight());
// Enter full screen mode with the resolution size specified at exact fit
eglView->setDesignResolutionSize(1024, 768, kResolutionExactFit);
eglView->enterFullscreen(0, 0);
int ret = CCApplication::sharedApplication()->run();
I haven’t even used the exitFullscreen function yet, so that may be a bit funky. I’d suggest caching off the specified sizes instead of passing them in. You have to set the screen size to the full resolution width/height at the moment. It’s the only way I could get around OpenGL not going crazy and losing its ability to render when you enter fullscreen mode. I’m sure there’s a way around that, but I’m not a graphic engineer. I mostly hang out in server land.