Win32: full-screen and hiding taskbar?

You have to hide taskbar and menubar to see fullscreen immediately.

Up vote 4 down vote favorite 1 share g+ share fb share tw.

I have a window, which I SetWindowPos(window, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED); It covers the whole screen, ok, but it takes a while (0.5 sec) to cover the taskbar as well. Is there a way to come over the taskbar immediately? I found that setting HWND_TOPMOST does it immediately, but it stays above all the other windows, even if I switch the app - this is something I don't want.

Also, if I first hide the window and then show it, it somehow forces the window to redraw and covers the taskbar immediately, but it flickers (because of the hiding). Is there another way? Winapi fullscreen taskbar link|improve this question asked Mar 4 '10 at 20:23Lars Kanto10528 78% accept rate.

You have to hide taskbar and menubar to see fullscreen immediately. Here is the code (uses WTL), call SetFullScreen(true) to go into full screen mode: template class CFullScreenFrame { public: bool m_fullscreen; LONG m_windowstyles; WINDOWPLACEMENT m_windowplacement; CFullScreenFrame() : m_fullscreen(false), m_windowstyles(0) { } void SetFullScreen(bool fullscreen) { ShowTaskBar(!fullscreen); T* pT = static_cast(this); if (fullscreen) { if (!m_fullscreen) { m_windowstyles = pT->GetWindowLongW(GWL_STYLE); pT->GetWindowPlacement(&m_windowplacement); } } // SM_CXSCREEN gives primary monitor, for multiple monitors use SM_CXVIRTUALSCREEN. RECT fullrect = { 0 }; SetRect(&fullrect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); WINDOWPLACEMENT newplacement = m_windowplacement; newplacement.

ShowCmd = SW_SHOWNORMAL; newplacement. RcNormalPosition = fullrect; if (fullscreen) { pT->SetWindowPlacement(&newplacement); pT->SetWindowLongW(GWL_STYLE, WS_VISIBLE); pT->UpdateWindow(); } else { if (m_fullscreen) { pT->SetWindowPlacement(&m_windowplacement); pT->SetWindowLongW(GWL_STYLE, m_windowstyles); pT->UpdateWindow(); } } m_fullscreen = fullscreen; } void ShowTaskBar(bool show) { HWND taskbar = FindWindow(_T("Shell_TrayWnd"), NULL); HWND start = FindWindow(_T("Button"), NULL); if (taskbar! = NULL) { ShowWindow(taskbar, show?

SW_SHOW : SW_HIDE); UpdateWindow(taskbar); } if (start! = NULL) { // Vista ShowWindow(start, show? SW_SHOW : SW_HIDE); UpdateWindow(start); } } }; You also have to add some code to WM_CLOSE message: case WM_CLOSE: ShowTaskBar(true); There is one caveat with this solution, if your application crashes or is killed through task manager, then user losses taskbar on his system permanently!

(unless he runs your application again, goes into fullscreen and exits, then he will see the taskbar again). Earlier in my answer I pointed to "atlwince. H" but that function worked only on Windows CE, the one I pasted above works fine with XP, Vista and 7.

Yup, HWND_TOPMOST does it for me. Here is a section of code that makes full-screen work well (and quick) for me: bool enterFullscreen(HWND hwnd, int fullscreenWidth, int fullscreenHeight, int colourBits, int refreshRate) { DEVMODE fullscreenSettings; bool isChangeSuccessful; RECT windowBoundary; 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(hwnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST); SetWindowLongPtr(hwnd, GWL_STYLE, WS_POPUP | WS_VISIBLE); SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, fullscreenWidth, fullscreenHeight, SWP_SHOWWINDOW); isChangeSuccessful = ChangeDisplaySettings(&fullscreenSettings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL; ShowWindow(hwnd, SW_MAXIMIZE); return isChangeSuccessful; } Note that this will change the resolution if you tell it the wrong settings. This is what I usually want, but if you don't like that, you can find out your resolution by using (where mainWindow is returned from something like CreateWindow() or CreateWindowEx()): windowHDC = GetDC(mainWindow); fullscreenWidth = GetDeviceCaps(windowHDC, HORZRES); fullscreenHeight = GetDeviceCaps(windowHDC, VERTRES); colourBits = GetDeviceCaps(windowHDC, BITSPIXEL); refreshRate = GetDeviceCaps(windowHDC, VREFRESH); When you want to get out of full-screen you do something like this: bool exitFullscreen(HWND hwnd, int windowW, int windowY, int windowedWidth, int windowedHeight, int windowedPaddingX, int windowedPaddingY) { bool isChangeSuccessful; SetWindowLongPtr(hwnd, GWL_EXSTYLE, WS_EX_LEFT); SetWindowLongPtr(hwnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE); isChangeSuccessful = ChangeDisplaySettings(NULL, CDS_RESET) == DISP_CHANGE_SUCCESSFUL; SetWindowPos(hwnd, HWND_NOTOPMOST, windowX, windowY, windowedWidth + windowedPaddingX, windowedHeight + windowedPaddingY, SWP_SHOWWINDOW); ShowWindow(hwnd, SW_RESTORE); return isChangeSuccessful; } I set my code to change between full-screen and windowed mode using a hotkey, and I keep the windowed mode variables as global, so that when changing to windowed mode, it stays put. This code also has the advantage of running in the equivalent of "exclusive mode" (I'm using XP, and haven't tried it on the newer versions of windows), which means it'll be much, much faster.

Let me know if I've made any mistakes from condensing the code (from my much bigger code).

Thanks for the reply. I think the reason why it works is that you resize the window at least twice "SetWindowPos() and ShowWindow()" (I don't know that "ChangeDisplaySettings()"). The problem is, what happens if I'm already in "SW_MAXIMIZE" and what to go full-screen?

– Lars Kanto Mar 11 '10 at 12:12 I read somewhere that there is kind of "cache" of the window manager. So I was hoping there is a way to force it to refresh or otherwise tell it that it should repaint the taskbar beneath. – Lars Kanto Mar 11 '10 at 12:14 In other words, it seems to me that "SW_MAXIMIZE" does something besides the resizing and I would like to know what... – Lars Kanto Mar 11 '10 at 12:18 Sorry for my late reply.

As far as I know, "SW_MAXIMIZE" just tells windows that you want as much screen as possible (just like the button on the top-left of a window next to the close button). The code I provided relies on the combination of function calls I used, rather than just the setting in ShowWindow(). If you're already in "SW_MAXIMIZE", this code still works.

– Warpspace Mar 13 '10 at 13:18 As for repainting the taskbar, that's considered a separate program, and you're not supposed to (can't? ) handle it's repainting. If you're programming for Windows Mobile, however, you can find the "taskbar" and hide/move (I do both) it.

Use "FindWindow(TEXT("HHTaskBar"), NULL);" to find it (it returns a window handle), and then call ShowWindow() or MoveWindow() to modify it (and remember to restore it on exit). I'm not sure if there's an equivalent for normal windows, though. – Warpspace Mar 13 '10 at 13:18.

I believe the taskbar will get out of the way when its shell hook tells it about a "rude app", this might take a little while. What if you start out with the window HWND_TOPMOST and make it not top most after 1 second?

Raymond Chen describes the "correct" way to do this at his blog: blogs.msdn.com/b/oldnewthing/archive/200... Fiddling with the task bar window explicitly is not recommended behaviour.

Right click on the taskbar choose Properties uncheck the checkbox that says "Keep the taskbar on top of other windows". The taskbar belongs to the user, It's up to them to care about having it take 1/2 second to auto-hide when you app goes full screen. If they want to change that behavior then they can change it.

If you are working in an embedded system, then you may have a legitimate reason to hide the taskbar. But in that case, there's no reason not to simply configure the taskbar to not always be on top. You could also have a look at SystemParametersInfo if you want to change some of these settings in your code.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions