2

I'm quite new to the Windows API and I'm trying to find the handles of all the windows which appear in the taskbar.

So far, I have managed to:

  • Get the handles of all windows
  • Get the title of a window
  • Check whether a window is visible
  • Check whether a window exists
  • Minimise a window
  • Get the child windows of a window
  • Get the desktop window

I have tried getting all child windows of the desktop window, which gives me nearly 900 window handles! So I tried to filter them down, by getting only visible windows and only windows whose title is longer than 0 characters, but I'm still way off - with 68 windows??

So could some Win API expert enlighten me as to how you do this please :-) and also possibly explain why there are so many windows?

Edit:

private static bool HasAppWindowStyle(IntPtr handle)
{
    return (GetWindowLong(handle, GWL_EXSTYLE) & WS_EX_APPWINDOW) != 0;
}
Nobody
  • 4,731
  • 7
  • 36
  • 65
  • 1
    Why `==0` and not `!=0`. I don't know how the values of this API are defined, but intuitively I'd use `!=0` – CodesInChaos Dec 08 '10 at 19:09
  • possible duplicate of [What API function do I need to use to know if a windows is beeing shown in the taskbar?](http://stackoverflow.com/questions/3484650/what-api-function-do-i-need-to-use-to-know-if-a-windows-is-beeing-shown-in-the-ta) – Anders Dec 09 '10 at 15:18

3 Answers3

2

Did you see FindWindowEx sample? Also you can filter them to have a text on it, I think the windows you are see is the Desctop items (I'm not sure) but remove some item from desktop and see the changes.

Saeed Amiri
  • 22,252
  • 5
  • 45
  • 83
1

Top-level windows that you find with EnumWindows and have taskbar buttons will have the WS_VISIBLE and WS_EX_APPWINDOW style flags turned on.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Hans: I am still getting ~25 windows, is that correct? I only have two windows in my taskbar. Some of them have empty titles and I'm also getting windows with titles like `Start`... I get the same number of windows when I check each has the appwindow style as when I don't (do all windows that have the visible style, also have the appwindow style?) I posted my method above. – Nobody Dec 08 '10 at 18:43
  • 2
    No, this is not correct, the algorithm is much more complicated than this. – Anders Dec 09 '10 at 15:16
1

The exact algorithm is not documented, I came up with some pseudo code in this answer that does an ok job.

Community
  • 1
  • 1
Anders
  • 97,548
  • 12
  • 110
  • 164
  • Thanks Anders. I can't believe this isnt more well documented... I mean, I thought this would be a common task. I even expected a specific API method like `EnumTaskbarWindows` or something. I will update when I find something that works. – Nobody Dec 09 '10 at 15:43
  • I was getting confused because for some reason my `Title` property's `get` was timing out for some windows. Anyway, it works if I get the parent process' name instead. Good enough. – Nobody Dec 13 '10 at 13:55