簡単な 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 を取得するにはどうすればよいですか?
ご協力いただきありがとうございます