GetAltTabInfo usage?
I'm not able to use GetAltTabInfo. Probably a stupid mistake but what's wrong with this?
HWND taskSwitcher = FindWindow(L"TaskSwitcherWnd", L"Task Switching");
ALTTABINFO altTabInfo = {};
altTabInfo.cbSize = sizeof(ALTTABINFO);
GetAltTabInfo(taskSwitcher, -1, &altTabInfo, NULL, 0);
I have verified that taskSwitcher is the task switching window after the call to FindWindow (whether it is visible or not). All fields of altTabInfo remain 0 after the call to GetAltTabInfo except cbSize which was set to 40 by the assignment to sizeof(ALTTABINFO). I'm trying this on a windows 7 machine.
Alternative methods to extract the number of windows?
Thanks
Edit: Ok, I just realized I may get some error info. The result value of the GetAltTabInfo call is indeed 0 and GetLastError gives me either 1400 (Invalid window handle) or 1168 (Element not found) if I specify NULL for the hwnd parameter (it was after all defined to be __in_opt). So I guess 开发者_开发技巧I'm passing the wrong window. What is the right one if not the one returned by FindWindow(L"TaskSwitcherWnd", L"Task Switching")? MSDN only tells me about the hwnd parameter that "This window must be the application-switching window".
You always have to check for errors when you use Win32 API functions. GetAltTabInfo returns BOOL, call GetLastError() when it returns FALSE:
BOOL ok = GetAltTabInfo(hWnd, -1, &altTabInfo, NULL, 0);
if (!ok) {
int err = GetLastError();
Log(err); // Or whatever you use
return false;
}
I'll think you'll see error 1400, "Invalid window handle". On my machine, none of the window handles enumerated by EnumWindows() are accepted. I'd draw the conclusion that this API is no longer usable when you've got Aero enabled. I can't find independent confirmation for this.
i don't know for GetAltTabInfo, but you may use EnumWindow()
to search for top-level windows and count them. that should tell you how many windows there are in the Alt-Tab window...
For what it's worth, as mokubai knew at https://superuser.com/questions/72946/disable-or-delay-alt-tab-aero-peek-effect-in-windows-7 , you can actually get the old style alt tab window visible even with win 7 aero enabled (left alt + tap right alt + tab (..I'm not kidding!!)). With that window visible the hwnd parameter in the GetAltTabInfo is irrelevant and in these circumstances you will still be able to get the Alt tab info.
精彩评论