4

I need to find a list of items that are currently displayed in the Windows task bar.

I know how to get a list of active processes or top-level windows but that won't do. Some appear in the task bar, some don't. It is possible for an app to have the top level window and still not appear in the task bar.

I have tried to enumerate through all child windows of the task bar but that didn't get me very far either.

I don't mind if I get a list of window (or icon) handles or a list of processes.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Harald
  • 1,007
  • 1
  • 14
  • 27
  • Can you tell us *why* you need this? Why do you need the windows visible in the task bar, rather than a list of all the top-level windows? – Cody Gray - on strike Dec 18 '11 at 07:10
  • I need to determine when a 3rd party app that I spawn gets into a certain state. That state is associated with that app becoming visible in the task bar. It is running already but not visible in the task bar until it gets into the state I am interested in. – Harald Dec 18 '11 at 07:17
  • Can you show us some code to show what you have so far so we can help you debug? – M.Babcock Dec 18 '11 at 07:17
  • I don't yet have an approach to the problem and therefor no code that needs modifying. – Harald Dec 18 '11 at 07:21
  • @Harald: Please be sure to do you due diligence on **YOUR** issues before posting on SO. If you haven't even tried to solve your problem then your question doesn't belong here. – M.Babcock Dec 18 '11 at 07:30
  • 2
    If you're only interested in one app, use Spy++ to examine its state and figure out how it makes itself appear in the taskbar. Chances are, it's modifying either the `WS_EX_APPWINDOW` or `WS_EX_TOOLWINDOW` styles. Then you can use a simplified version of the approach I detail in my answer to enumerate all the top-level windows, and check to see if the one you're interested in is now visible in the taskbar. – Cody Gray - on strike Dec 18 '11 at 07:30
  • @M.Babcock: Please read the OP. You'll find that I have tried several approaches. – Harald Dec 18 '11 at 07:38
  • @Harald "I don't yet have an approach to the problem and therefor no code that needs modifying." - If that is true then it is obvious that you have done little research of your problem. There is information all over the google-net which describes the process of doing what you are asking. Please be sure to ask yourself how **you** can solve the problem before depending on others to solve the problem for you. – M.Babcock Dec 18 '11 at 07:48
  • 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-t) – Anders Dec 18 '11 at 07:53
  • @M.Babcock: Your comments are unfounded. Of course I have googled and of course I have tried approaches that I thought could work. Neither yielded a result. If what you claim is true and a simple google search brings a result, why don't you do just that and report back? – Harald Dec 18 '11 at 07:57
  • @CodyGray: The two WS_EX style you mentioned are mostly unrelated to the problem. Using WS_EX_TOOLWINDOW to hide a window from the task bar is not a good solution and most apps don't use that approach. The proper way to hide an app in the task bar is to use the ITaskbarList COM interface. If you have a window handle you can use that interface to hide any app. Unfortunately, that interface does not enumerate or otherwise list the apps in the task bar. – Harald Dec 18 '11 at 08:02
  • Yes, I'm quite aware of the correct approach. The correct approach doesn't involve enumeration the apps in the task bar. You've moved past that long ago. – Cody Gray - on strike Dec 18 '11 at 08:21
  • I found a solution: [A tool to order the window buttons in your taskbar](http://www.codeproject.com/KB/shell/taskbarsorter.aspx) As part of the tool the visible buttons need to be determined. Just what I was looking for. – Harald Dec 18 '11 at 23:37
  • I deleted my answer because it was wrong, but the top contained a cautionary tale about this very approach that's worth repeating: Using `FindWindow` to get at the taskbar window and searching through its child windows isn't a very good solution. For starters, it's not portable. Not all versions of Windows use the same name for the taskbar's window, and there's no guarantee that future versions of Windows will implement everything the same way, either. For example, Microsoft could even stop implementing the taskbar with child windows altogether, thoroughly breaking your code. – Cody Gray - on strike Dec 19 '11 at 09:02
  • You have to be *very* careful with taking advantage of undocumented features like this. Microsoft never published those window names given in the article; they're found by trial and error using Spy++. Taking advantage of such features is therefore, generally a bad idea, at least if you care that your code continues to work. You'll have to be ever vigilant. I hope this is just an internal app designed for one Windows version only. – Cody Gray - on strike Dec 19 '11 at 09:03
  • I am aware of the possible issues. But since there is no official solution for it, the unofficial one has to do (like so often in Windows development). I tested it under WinXP, Vista and Win7 and it works on all of them (32 and 64bit) without modification. That's good enough for me for now. I'll just have to see how it holds up on future versions. – Harald Dec 19 '11 at 23:44
  • @Harald It doesn't hold in Windows7. – polkovnikov.ph Oct 27 '14 at 09:39
  • If I have the *exact* same question but for Windows 10, should I make a new post? – Jeffmagma Dec 02 '21 at 19:48

0 Answers0