【发布时间】:2018-10-02 05:33:42
【问题描述】:
我正在尝试使用 EnumWindows 打印出所有可见窗口的标题。
起初它是有效的,EnumWindows 每次调用 EnumWindows 都会多次调用回调函数 createWindow()。但如果没有添加任何有意义的代码,它就会停止工作,现在只使用不可见窗口的句柄调用一次 createWindow()。
这是我的代码:
int main()
{
int row = 2;
int col = 2;
vector<Window> detectedWindows((row * col) + 4);
EnumWindows(&createWindow, (LPARAM)&detectedWindows);
}
BOOL CALLBACK createWindow(HWND input, LPARAM storage)
{
if (IsWindowVisible(input))
{
TCHAR titleTchar[30];
GetWindowText(input, titleTchar, 30);
wcout << titleTchar << endl;
CString titleCstr = titleTchar;
CT2CA converting(titleCstr);
string title(converting);
cout << title << endl;
}
return 0;
}
没有记录的错误消息。 GetLastError 返回 0。
【问题讨论】: