EnumWindows does not detect windows

随声附和 提交于 2019-12-14 00:03:01

问题


I am trying to use EnumWindows to print out the titles of all visible windows.

It was working at first, EnumWindows was calling the callback function createWindow() multiple times with each call of EnumWindows. But without adding any meaningful code it stopped working and now only calls createWindow() once with a handle of a not visible window.

Here is my code:

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;
}

There are no recorded error messages. GetLastError returns 0.


回答1:


Your callback returns FALSE so EnumWindows() stops enumerating windows. Have it return TRUE instead.



来源:https://stackoverflow.com/questions/52602526/enumwindows-does-not-detect-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!