0

On Windows 10, you can press Win+Tab to get a "Task View" view of all your windows. I'm trying to check if this is active at any given time. I have tried using a Low Level Keyboard Hook with WH_KEYBOARD_LL but this only allows me to detect the keypress, not if the switcher is active. I've looked at the Windows DWM API and haven't found anything else either.

I have also tried using EnumWindows() and EnumChildWindows(GetDesktopWindow(), ...) and did not find any difference in the output between having the task view shown and hidden.

Is there any accurate method to detect if this is being shown?

Glenn Smith
  • 912
  • 1
  • 17
  • 37
  • 1
    There is no API for that particular purpose. Why do you need this? It sounds like a possible [XY problem](https://meta.stackexchange.com/questions/66377/). – Remy Lebeau Oct 09 '17 at 20:40
  • Writing a gesture recognition program that sends a Win+Tab to open the task view with a gesture, but only if it's not open already. – Glenn Smith Oct 09 '17 at 20:42
  • 1
    You can detect it via `FindWindow` passing the special class name of the switcher. Unfortunately, you can't use the usual method (Spy++) to learn the class name, because using Spy++ will close the switcher. So instead do this: Make the gesture, instead of sending Win+Tab, do a `EnumWindows` writing the window list to a file. Do the gesture with the switcher open, then look in the file to see what you found. Once you know the class name for the switcher, you can skip `EnumWindows` and just do `FindWindow`. – Ben Voigt Oct 09 '17 at 20:50
  • Also note "#32771 The class for the task switch window." in the documentation at https://msdn.microsoft.com/en-us/library/windows/desktop/ms633574(v=vs.85).aspx#system but I rather suspect that's for the older (Alt+Tab) switcher. I don't know if the class for the new switcher is documented but you can find out yourself. – Ben Voigt Oct 09 '17 at 20:53
  • Been trying that, but the results are basically identical with the exception of some unnamed windows. – Glenn Smith Oct 09 '17 at 20:59
  • 1
    Use `GetWindowThreadProcessId` to check if these windows belong to explorer.exe which is the process responsible for the task switcher I believe. Use `GetClassName` to determine the class name. – zett42 Oct 10 '17 at 12:27
  • I have noticed that `Shell_TrayWnd` is not a child of GetDesktopWindow() when task view is open. Will try using that as an indicator. – Glenn Smith Oct 10 '17 at 20:26

1 Answers1

1

Here's a solution that works very consistently with my version of Windows (1709 build 16299.125) and doesn't require the processor-heavy approach of a call to EnumChildWindows:

bool isTaskView() {
    //Get foreground window's name
    HWND fgWindow = GetForegroundWindow();
    TCHAR windowName[MAX_PATH] = L"";
    GetWindowText(fgWindow, windowName, MAX_PATH);
    //Compare with magic string name of Task View's window
    std::wstring nameStr(windowName);
    return nameStr == L"Task View";
}
Glenn Smith
  • 912
  • 1
  • 17
  • 37