Chen did say it was pseudo-code, but this produces the titles of the windows in the Alt-Tab list for me.
Code:
#include <windows.h>
#include <iostream>
BOOL IsAltTabWindow(HWND hwnd)
{
LONG_PTR exStyles = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
// Start at the root owner
HWND hwndWalk = hwnd;
// appwindows treated as no owner, so don't try and find one
if(!(exStyles & WS_EX_APPWINDOW))
{
hwndWalk = GetAncestor(hwnd, GA_ROOTOWNER);
}
// See if we are the last active visible popup
HWND hwndTry = hwndWalk;
while ((hwndTry = GetLastActivePopup(hwndWalk)) != hwndTry) {
if (IsWindowVisible(hwndTry)) break;
hwndWalk = hwndTry;
}
// tool windows are treated as not visible so they'll never appear in the list
// fail them here
return (hwndWalk == hwnd) && !(exStyles & WS_EX_TOOLWINDOW);
}
BOOL CALLBACK Enum(HWND hwnd, LPARAM lParam)
{
if(IsAltTabWindow(hwnd) && IsWindowVisible(hwnd))
{
WCHAR buf[260];
GetWindowText(hwnd, buf, ARRAYSIZE(buf));
std::wcout << L"Alt-tab window with title " << buf << L" found\n";
}
return TRUE;
}
int __cdecl main()
{
EnumWindows(&Enum, 0);
}