Determining if a Window Has a Taskbar Button

后端 未结 3 1495
旧巷少年郎
旧巷少年郎 2020-12-13 22:18

I am looking for a way to check if a given window has a taskbar button. That is, given a handle to a window, I need a TRUE if the window is in the taskbar, and FALSE otherwi

3条回答
  •  一整个雨季
    2020-12-13 22:45

    Windows uses heuristics to decide whether or not to give a taskbar button to a window, and sometimes there is a delay before it can decide, so doing this 100% accurately is going to be quite hard. Here's a rough start on the rules. There are modern style flags that make it easy to know, but when those styles are missing the taskbar is reduced to guessing.

    First off, you will need both of the the window style flags.

    LONG Style = GetWindowLong(hwnd, GWL_STYLE);
    LONG ExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
    

    Now the rules, there are three rules that are certain.

    • if ExStyle & WS_EX_APPWINDOW, then TASKBAR
    • if ExStyle & WS_EX_TOOLWINDOW, then NOT_TASKBAR
    • if Style & WS_CHILD then NOT_TASKBAR

    The rest are guesses:

    • Style & WS_OVERLAPPED suggests TASKBAR
    • Style & WS_POPUP suggests NOT_TASKBAR especially if GetParent() != NULL
    • ExStyle & WS_EX_OVERLAPPEDWINDOW suggests TASKBAR
    • ExStyle & WS_EX_CLIENTEDGE suggests NOT_TASKBAR
    • ExStyle & WS_EX_DLGMODALFRAME suggests NOT_TASKBAR

    I'm sure that there are other rules for guessing, and in fact that the guessing rules have changed from version to version of Windows.

提交回复
热议问题