2

タスクバーにある各プログラムの現在のタスクバー アイコン (システム トレイではない) をプログラムで取得する方法を探しています。

すべての結果がシステム トレイに関連しているため、MSDN や Google ではうまくいきませんでした。

どんな提案や指針も役に立ちます。

編集: キーガン・ヘルナンデスのアイデアを試してみましたが、何か間違ったことをしたのではないかと思います。コードは以下 (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;
}
4

2 に答える 2

1

うまくいけば、これはあなたが始めるのに十分です:

WinAPI には、現在インスタンス化されている各 HWND のコールバック関数を呼び出す関数 EnumWindows があります。これを使用するには、次の形式のコールバックを記述します。

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);

次に、EnumWindows(EnumWindowsProc, lParam) を呼び出して、API がウィンドウごとにコールバックを呼び出すようにします。ここで、hwnd は 1 つの特定のウィンドウを表します。

各ウィンドウが表示されているかどうか、つまりタスク バーに表示されているかどうかを判断するには、コールバックが受け取る各 HWND で関数 IsWindowVisible(HWND) を使用できます。運が良ければ、そのコールバックに渡された HWND から必要なその他の情報を取得できます。

于 2009-07-23T04:20:56.723 に答える
0

コードにいくつかの問題があります。私の修正を参照してください。コンパイラで警告を表示(またはビルド出力を読み取る)すると、これらについて警告(または警告)する必要があります。

#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;
}
于 2009-07-23T18:11:58.813 に答える