ReHIPS forum

English Subforum => Developers' Blog => Topic started by: fixer on September 23, 2017, 12:36:24 PM

Title: [Coding] Taskbar internals (part 2)
Post by: fixer 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.

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.