[Coding] Taskbar internals (part 3)

Started by fixer, February 17, 2018, 02:00:01 PM

Previous topic - Next topic

fixer

In the previous taskbar internals parts we talked about how taskbar shows tabs and how taskbar chooses the main window.

You probably noticed that taskbar is usually shown above all windows. Even if you try to drag some window over taskbar, the window'll be displayed below. But if you open some full-screen application like a game or a video player, taskbar magically goes away letting the application take the whole screen and you to enjoy it. So how does it work?

Actually all the magic does taskbar, applications don't have to do practically anything especially some weird stuff like trying to hide taskbar themselves. So how does taskbar detect should it hide or not and how does it hide?

Hiding and reverting back is pretty simple, it uses SetWindowPos API with flags HWND_BOTTOM and HWND_TOPMOST to hide (actually to place taskbar below other windows) and to show back respectively.

Taskbar also gets notifications on different events like windows being activated. It then makes several checks including is this window visible, if window style includes WS_CAPTION and WS_THICKFRAME (depending on this check it checks either client-area rectangle or full window rectangle equals full monitor size), is it the same monitor taskbar is on and some additional checks like is it not desktop or live preview window. And there is one more additional check here as follows:

HWND hFGWindow=GetForegroundWindow();
if(GetWindowThreadProcessId(hWnd,NULL)==GetWindowThreadProcessId(hFGWindow,NULL))
    return TRUE;
else if(SHIsParentOwnerOrSelf(hWnd,hFGWindow)==S_OK)
    return TRUE;
return FALSE;


The last check is more for not to show taskbar when some subwindows of full-screen window are opened.
So basically taskbar checks if the active window wants to take the whole monitor area and if it does just goes to the bottom not to interfere.

BTW, the same checks go for the taskbar autohide, it doesn't show itself when a full-screen application is currently on screen.