0

I'm trying to create a Windows Taskbar replacement in C# because I'm disgusted by the Win10 one. A problem I'm having though is that I can't get a correct enumeration of the windows.

Basically the code down below doesn't give me any UWP windows. Also it gets windows from other virtual desktops. How can I get a list of handles to windows that is equal to or similar to the list of windows in the taskbar?

Here is the current code I'm using (HWND == System.IntPtr and BOOL = System.Boolean):

static HWND GetLastActivePopupOfWindow(HWND root)
{
    HWND lastPopup = GetLastActivePopup(root);
    if (IsWindowVisible(lastPopup))
        return lastPopup;
    if (lastPopup == root)
        return HWND.Zero;
    return GetLastActivePopupOfWindow(lastPopup);
}

static BOOL IsAltTabWindow(HWND hwnd)
{
    if (!IsWindowVisible(hwnd))
        return false;

    HWND root = GetAncestor(hwnd, 3);

    if (GetLastActivePopupOfWindow(root) == hwnd)
    {
        Window wi = new Window(hwnd);

        MessageBox.Show(wi.ClassName + "\r\n" + wi.Title);

        if (wi.ClassName == "Shell_TrayWnd" ||                          //Windows taskbar
            wi.ClassName == "WorkerW" ||
            wi.ClassName == "ProgMan" ||
            wi.ClassName == "ThumbnailDeviceHelperWnd" ||
            wi.ClassName == "Windows.UI.Core.CoreWindow" ||             //Empty UWP apps
            wi.ClassName == "DV2ControlHost" ||                         //Windows startmenu, if open
            (wi.ClassName == "Button" && wi.Title == "Start") ||        //Windows startmenu-button.
            wi.ClassName == "MsgrIMEWindowClass" ||                     //Live messenger's notifybox i think
            wi.ClassName == "SysShadow" ||                              //Live messenger's shadow-hack
            wi.ClassName.StartsWith("WMP9MediaBarFlyout") ||
            wi.Title.Length == 0)              //WMP's "now playing" taskbar-toolbar
            return false;

        return true;
    }

    return false;
}
  • I think an answer to this question is highly subjective / speculative. – Thomas Weller Feb 07 '20 at 14:02
  • And why do you rename `bool` to `BOOL`? The nice C# code looks like C code now. – Thomas Weller Feb 07 '20 at 14:05
  • 1
    There are plenty of articles around that describe which Windows appear on the taskbar. Some research will reveal these articles. Of course you aren't going to succeed with your current approach. You'll miss all the windows that register using the taskbar api. Perhaps you should try to conquer your disgust. Much more chance of success that way. – David Heffernan Feb 07 '20 at 14:05

0 Answers0