简体   繁体   中英

accessing windows taskbar icons in c++

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;
}

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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM