views:

411

answers:

2

I am looking for a way to programmatically get the current taskbar icons (not the system tray) for each program that is in the taskbar.

I haven't had much luck with MSDN or Google, because all of the results relate to the system tray.

Any suggestions or pointers would be helpful.

EDIT: I tried Keegan Hernandez's idea but I think I might have done something wrong. The code is below (c++).

#include <iostream>
#include <vector>
#include <windows.h>
#include <sstream>
using namespace std;
vector<string> xxx;
bool EnumWindowsProc(HWND hwnd,int ll)
{
    if(ll=0)
    {
        //...
        if(IsWindowVisible(hwnd)==true){
        char tyty[129];
        GetWindowText(hwnd,tyty,128);
        stringstream lmlm;
        lmlm<<tyty;
        xxx.push_back(lmlm.str());
        return TRUE;
        }
    }
}
int main()
{
    EnumWindows((WNDENUMPROC)EnumWindowsProc,0);
    vector<string>::iterator it;
    for(it=xxx.begin();it<xxx.end();it++)
    {cout<< *it <<endl;}
    bool empty;
    cin>>empty;
}
A: 

Hopefully this is enough to get you started:

WinAPI has a function EnumWindows which will call a callback function for each HWND that is currently instantiated. To use it write a callback of the form:

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);

Then call EnumWindows(EnumWindowsProc, lParam) so that the API will call your callback for each window, where hwnd represents one specific window.

To determine if each window is visible and therefore on the taskbar, you can use the function IsWindowVisible(HWND) on each HWND that the callback receives. If you're lucky you can get whatever other information you need from the HWNDs passed to that callback.

Jay Keegan
Not every window/program will appear in the taskbar. In C# you can do that easily...
PoweRoy
A: 

There are several problems with your code, please see my corrections. Turn the warnings up (or read the build output) on your compiler, it should have warned (or did warn) you about these!

#include <iostream>
#include <vector>
#include <windows.h>
#include <sstream>
using namespace std;
vector<string> xxx;
// The CALLBACK part is important; it specifies the calling convention.
// If you get this wrong, the compiler will generate the wrong code and your
// program will crash.
// Better yet, use BOOL and LPARAM instead of bool and int.  Then you won't
// have to use a cast when calling EnumWindows.
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM ll)
{
    if(ll==0) // I think you meant '=='
    {
        //...
        if(IsWindowVisible(hwnd)==true){
        char tyty[129];
        GetWindowText(hwnd,tyty,128);
        stringstream lmlm;
        lmlm<<tyty;
        xxx.push_back(lmlm.str());
        //return TRUE; What if either if statement fails?  You haven't returned a value!
        }
    }
    return TRUE;
}
int main()
{
    EnumWindows(EnumWindowsProc,0);
    vector<string>::iterator it;
    for(it=xxx.begin();it<xxx.end();it++)
    {cout<< *it <<endl;}
    bool empty;
    cin>>empty;
}
Nick Meyer
You also need to check the ex window styles, exclude toolbar windows and include appwindow's
Anders