Author Topic: [Coding] Taskbar internals (part 2)  (Read 1296 times)

fixer

  • Administrator
  • Hero Member
  • *****
  • Posts: 1526
[Coding] Taskbar internals (part 2)
« on: September 23, 2017, 12:36:24 pm »
In the previous taskbar internals part we discussed how taskbar list of windows is filled. Now let's talk about how taskbar chooses the main window.

As you probably know a process can have a lot of windows, some may have some owner/parent-child - relation, some may not be related at all. There may be only 1 taskbar tile for a whole bunch of windows. So how does taskbar pick just one window for thumbnail preview? Or activates the one and only window when you click that tile?

This part really has some relation with Raymond Chen's blog I mentioned earlier. Let's get straight to the pseudocode.

Code: [Select]
LastActiveWnd=GetLastActivePopup(GetAncestor(hWnd, GA_ROOTOWNER));
if(LastActiveWnd!=NULL && LastActiveWnd!=hWnd && IsWindowVisible(LastActiveWnd) && IsWindowEnabled(LastActiveWnd))
{
for(OwnerWnd=LastActiveWnd; OwnerWnd!=NULL; OwnerWnd=GetWindow(OwnerWnd, GW_OWNER))
{
if(OwnerWnd==hWnd)
{
if(_IsWindowNotDesktopOrTray(OwnerWnd))
hWnd=LastActiveWnd;
break;
}
}
}

This code is true for Windows XP, but 7 and 10 are pretty much the same.
« Last Edit: February 10, 2018, 12:57:15 am by fixer »