Skip to main content
GameDev.net gamedev.net
🔒 Locked

Fullscreen toggling and taskbar

Started by Black Knight Sep 20, 2009 at 12:23 AM 2 replies 1.6k views
Original Post
Black Knight
Black Knight
I have some code that switches between fullscreen and windowed mode.It basically changes the window style.Here is the code that makes the window go fullscreen:

//NOte: ChangeDisplaySettings is called before this point with a supported setting.
//change to fullscreen style
			SetWindowLongPtr(m_hWnd,GWL_EXSTYLE,WS_EX_APPWINDOW);
			SetWindowLongPtr(m_hWnd,GWL_STYLE,WS_POPUP);
			
			//SetWindowPos needs to be called after SetWindowLongPtr to make sure changes are applied
			SetWindowPos(m_hWnd,HWND_TOP,0,0,0,0,SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE);
			
			//maximize the window
			ShowWindow(m_hWnd,SW_MAXIMIZE);
			SetFocus(m_hWnd);

And this code is for going back to windowed mode :

//need to call SW_RESTORE twice for some weird reason
			ShowWindow(m_hWnd,SW_RESTORE);
			
			//go back to normal resolution
			ChangeDisplaySettings(NULL,0);
						
			//change back to overlapped window style
			SetWindowLongPtr(m_hWnd,GWL_EXSTYLE,WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
			SetWindowLongPtr(m_hWnd,GWL_STYLE,WS_OVERLAPPEDWINDOW);
			
			//SetWindowPos needs to be called after SetWindowLongPtr to make sure changes are applied
			SetWindowPos(m_hWnd,HWND_TOP,0,0,0,0,SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE);
			ShowWindow(m_hWnd,SW_RESTORE);
			SetFocus(m_hWnd);

			//for some weird(2) reason after coming back from fullscreen mode the icon on the title bar disappears
			// so i set it again here
			HICON icon = (HICON)GetClassLongPtr(m_hWnd,GCL_HICON);					
			SendMessage(m_hWnd,WM_SETICON,ICON_BIG,(LPARAM)icon);
			SendMessage(m_hWnd,WM_SETICON,ICON_SMALL,(LPARAM)icon);

Everything works except for a minor detail.After i come back to windowed mode my applications button at the taskbar looks like it does not have focus.But the application has focus and takes input mouse presses etc.When I alt-tab or click from the taskbar then the taskbar updates itself and it shows my app as focused. Any idea what might be wrong?
Black Knight
Black Knight
This is the app I'm having this issue with.It requires OpenGL3.2 support.Pressing F1 toggles between fullscreen and windowed mode.

Link

Erik Rufelt
Erik Rufelt
Try adding SWP_DRAWFRAME to your SetWindowPos flags.

Though it doesn't seem to make a difference when I test it now..
This is how I do it:
if(g_fullscreen) {	g_fullscreen = false;	SetWindowLongPtr(hWnd, GWL_style, WS_OVERLAPPEDWINDOW | WS_VISIBLE);	SetWindowPos(hWnd,HWND_NOTOPMOST,g_wrect.left,g_wrect.top,g_wrect.right-g_wrect.left,g_wrect.bottom-g_wrect.top,SWP_DRAWFRAME|SWP_FRAMECHANGED);}else {	g_fullscreen = true;	GetWindowRect(hWnd, &g_wrect);	SetWindowLongPtr(hWnd, GWL_style, WS_POPUP | WS_SYSMENU | WS_VISIBLE);	SetWindowPos(hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_DRAWFRAME|SWP_FRAMECHANGED);	ShowWindow(hWnd,SW_MAXIMIZE);}
Black Knight
Black Knight
I will try it out when I'm back at home maybe it makes a difference.Thanks for the tip.

This might be useful too :

http://msdn.microsoft.com/en-us/library/dd145221(VS.85).aspx

But I guess it should be handled automatically.

Topic Locked

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

Sign in to reply to this topic.