我正在寻找一种方法以编程方式获得每个程序,它是在任务栏的当前任务栏图标(未在系统盘)。

我还没有与MSDN或谷歌的运气,因为所有的结果都涉及到系统托盘中。

任何建议或指针将是有益的。

编辑: 我想基冈埃尔南德斯的想法,但我想我可能做错了。该代码是下面(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;
}
有帮助吗?

解决方案

有几个问题你的代码,请参阅我的修正。打开警告向上(或阅读构建输出)你的编译器,它应该警告(或没有警告),你了解这些!

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

其他提示

希望这是足以让你开始:

WinAPI的具有这样的功能EnumWindows的它将调用对当前实例化每个HWND的回调函数。要使用它编写的形式的回调:

BOOL CALLBACK EnumWindowsProc(HWND HWND,LPARAM lParam的);

然后调用EnumWindows的(EnumWindowsProc,lParam的),使得API将调用为每个窗口,在这里的hwnd表示一个特定的窗口回调。

要确定每个窗口是可见的,并因此在任务栏上,可以在每个HWND使用函数IsWindowVisible(HWND)回调接收。如果幸运的话,你可以让你从传递给回调HWNDs需要的任何其他信息。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top