遍历窗口
遍历顶层窗口
在windows系统,使用EnumWindows()遍历顶层窗口。具体使用细节如下。
typedef struct _ENUMWINDOWSTEST
{
int32_t testX;
float testY;
}ENUMWINDOWSTEST;
/**
*@brief 定EnumWindows()的回调函数。每遍历一个窗口,调用一次。
*@param[in] hwnd:所获取的句柄。
*@param[in] lParam:EnumWindows()第二个参数的输入。
*/
static BOOL CALLBACK EnumWindowsCallback(HWND hwnd, LPARAM lParam )
{
char windowText[256];
GetWindowText(hwnd, windowText, 256);
printf("Window Text is: %s\n", windowText);
static int32_t count = 0;
ENUMWINDOWSTEST *windowTest = (ENUMWINDOWSTEST *)lParam;
windowTest->testX = count;
count++;
return TRUE;//返回TRUE,EnumWindows()继续遍历窗口。FALSE停止遍历。
}
void main()
{
ENUMWINDOWSTEST testStruct;
testStruct.testX = 999999;
printf("testX = %d\n", testStruct.testX);
EnumWindows(EnumWindowsCallback, (LONG)&testStruct);
printf("testX = %d\n", testStruct.testX);
cin.get();
}