Author Topic: [Coding] Taskbar internals (part 1)  (Read 1218 times)

fixer

  • Administrator
  • Hero Member
  • *****
  • Posts: 1526
[Coding] Taskbar internals (part 1)
« on: September 20, 2017, 12:57:52 pm »
Have you ever wondered how taskbar shows windows? Maybe you tried to code you own taskbar? Then this blogpost is for you. There is quite a few information about it on the internet. From a couple of articles from trusted sources like Raymond Chen here https://blogs.msdn.microsoft.com/oldnewthing/20071008-00/?p=24863 to other custom solutions with lots of hacks based on window classes.

While Raymond Chen article is really interesting, it doesn't quite cover the topic what windows are shown on taskbar, it's more likely about Alt+Tab list of windows. And it turns out they're quite different. So let's get straight to the pseudocode and then we'll discuss it.

Windows are enumerated using EnumWindows with this callback function:
Code: [Select]
if(_IsWindowNotDesktopOrTray(hWnd))
{
if(IsWindowVisible(hWnd))
{
WinExStyle=GetWindowLong(hWnd, GWL_EXSTYLE);
if((GetWindow(hWnd, GW_OWNER)==NULL || (WinExStyle & WS_EX_APPWINDOW)) &&
!(WinExStyle & WS_EX_TOOLWINDOW))
{
        AddToTheTaskbarList(hWnd);
}
}
}

As you can see, this code is quite simple and straighforward. _IsWindowNotDesktopOrTray is there to check for IsWindow() and skip a couple of service windows like desktop or taskbar itself. Other functions are standard API functions and can be found in MSDN.

This code is true for Windows XP, but 7 and 10 are the same with slight differences for example to support new immersive windows with additional checks like !IsShellManagedWindow() || ShellManagedWindowHelper::ShouldTreatShellManagedWindowAsNotShellManaged() and GetClassWord(GCW_ATOM)!=g_SecondaryTaskbarAtom || !g_SecondaryTaskbarAtom.

In the next part we'll discuss how taskbar decides which tile to highlight when a window becomes active.
« Last Edit: February 10, 2018, 12:57:37 am by fixer »