質問

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

すべての結果がシステムトレイに関連しているため、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;
}
役に立ちましたか?

解決

コードにはいくつかの問題があります。私の修正をご覧ください。コンパイラの警告を上げ(またはビルド出力を読み取る)(またはビルド出力を読み取る)、これらについて警告した(または警告した)はずです!

#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には、現在インスタンス化されている各HWNDのコールバック関数を呼び出す関数enumwindowsがあります。それを使用するには、フォームのコールバックを書きます:

bool callback enumwindowsproc(hwnd hwnd、lparam lparam);

次に、enumwindows(enumwindowsproc、lparam)を呼び出して、APIが各ウィンドウのコールバックを呼び出すようにします。ここで、HWNDは特定のウィンドウを表します。

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top