1

簡単な C++ コードを使用して、Windows で開いているすべてのウィンドウの情報 (x、y、幅、高さ、およびタイトル) を取得しようとしています (以下を参照)。

#include <iostream>
#include <windows.h>
using namespace std;

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int     iCmdShow)
{
    EnumWindows(EnumWindowsProc, NULL);
    //system("PAUSE");
    return 0;
}

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
char class_name[255];
char title[255];
int tmpWidth;
int tmpHeight;
HWND currenthwnd;
RECT WindowRect;

GetClassName(hwnd,class_name, sizeof(class_name));
GetWindowText(hwnd,title,sizeof(title));
GetWindowRect(hwnd,&WindowRect);

//if(WindowRect.left>-50 && title != "" && title != NULL && strlen(title)>0){
    tmpHeight = WindowRect.bottom - WindowRect.top;
    tmpWidth = WindowRect.right - WindowRect.left;
    cout <<"@@##@@"<<title<<",(@@#@@)";
    cout <<WindowRect.left<<",(@@#@@)";
    cout <<WindowRect.top<<",(@@#@@)";
    cout <<tmpWidth<<",(@@#@@)";
    cout <<tmpHeight<<",(@@#@@)";
    currenthwnd=GetForegroundWindow();
    if (currenthwnd!=hwnd){
       cout <<title<<",(@@#@@)false";
    }else{
       cout <<title<<",(@@#@@)true";
    }
 //}

 return TRUE;
}

しかし、このコードで問題が発生しました。Get-Process 関数を使用して PowerShell も試しましたが、この関数は開いているすべてのウィンドウではなく、既存のすべてのプロセスを返します。

開いているすべてのウィンドウの高さでタイトル x,y を取得するにはどうすればよいですか?

ご協力いただきありがとうございます

4

1 に答える 1

2

powershell では、WASPモジュールを使用して、次のように記述できます。

Get-Process | Where-Object {$_.MainWindowTitle -ne ""}  | 
% {$_.processname + "-" + $_.mainwindowtitle;
       Get-WindowPosition -Window $_.handle }

これは、実際の PowerShell ウィンドウの結果の例です。

powershell - Posh - Admin
Location : {X=4,Y=44}
Size     : {Width=885, Height=129}
X        : 4
Y        : 44
Width    : 885
Height   : 129
Left     : 4
Top      : 44
Right    : 889
Bottom   : 173
IsEmpty  : False
于 2012-09-21T11:49:54.810 に答える