I try to retrieve some information(x,y,width,height and title) for all opened window on Windows with a simple C++ code(see below):
#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;
}
But I encountered some issue with this code, I also try with PowerShell with Get-Process function, but this function doesn’t return all opened windows but all existing process.
How can I retrieve title, x,y, with, heigth of all opened window ?
Thanks for your help
In powershell you can use the WASP Module and wrote something like this:
This is a result example for my actual powershell windows: