Results 1 to 4 of 4

Thread: Get the icons of all open windows displayed in the taskbar

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2008
    Posts
    60

    Get the icons of all open windows displayed in the taskbar

    I need to get the icons of all open windows that are displayed in the taskbar. I posted a previous thread similar to this in which I asked how to get a full file path from an hWnd number, but it turns out the solution in that thread is not going to work for me.

    The solution in that thread was to use GetModuleFileName. After much experimentation and reading about GetModuleFileName I discovered that instead I would have to use GetModuleFileNameEx, which after hours of research I still haven't been able to find a working example of, nor do I know that it would work anyway as I've read threads on other forums where people have been unable to make these API's work for this situation. (Some info on why this wont work: A Thread, Info about Handles and Proccess IDs). According to those two links I would have to use process loops, which I have no idea how to do.

    I also found this example which does almost what I'm wanting to do, but it only returns the path of the top level window and I'm at a loss on how to convert it to give me the path of windows that are not top level.

    Just for clarification on what I'm trying to do, I'm creating my own custom version of the windows taskbar and I need to be able to extract the icons of all the open windows that are displayed in the real windows taskbar so I can put them on the simulated taskbar tabs.

    I've been searching for days for a way to accomplish this but I'm not turning up anything that works. If anyone can point me in the right direction or give me ideas for alternative methods of going about doing this I would really appreciate it.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Get the icons of all open windows displayed in the taskbar

    I assume you can already get the hWnds of the taskbar windows?

    If so, SendMessage API using WM_GETICON can return the small/large icon used in that window. You can then draw the icon using DrawIconEx API or convert it to a stdPicture object (search this forum using key term: HandleToPicture).

    Note: Not sure if the handle passed is actual handle or copy. If copy, you'll need to destroy it at some point.

    Edited: Testing appears to show the icon is not a copy. If you will want a copy for your own purposes, use CopyImage API on the returned handle.
    Last edited by LaVolpe; Sep 2nd, 2011 at 01:19 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2008
    Posts
    60

    Re: Get the icons of all open windows displayed in the taskbar

    I hate to ask, but could you post an example of how this is done? I've spent the past 24 hours or so researching and trying everything I know to make it work but meeting with nothing but failure. I'd post examples of what I've tried but they would run on for pages lol.

    Edit: And yes, I can the hWnd numbers.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Get the icons of all open windows displayed in the taskbar

    Code:
    Dim hIcon As Long
    hIcon = SendMessage(targetHwnd, WM_GETICON, 0&, ByVal 0&) ' try small icon first
    If hIcon = 0& Then
        hIcon = SendMessage(targetHwnd, WM_GETICON, 1&, ByVal 0&) ' try large icon
    End If
    If hIcon = 0& Then 
        ' do whatever, you are not getting the associated icon
    Else
        ' you have an icon handle. do with what you need
    End If
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width