FindWindow with partial window title (Windows, C)

浪子不回头ぞ 提交于 2019-12-07 20:13:15

问题


Is there any API similar to FindWindow() but that searches the windows by partial title? The reason is that I need to the handle to a window that has a fix part on the title but the other part changes constantly. So for example the window title could be:

DataBase read: XYDB

or

DataBase read: WZDB

in the examples the fix part is "DataBase read:"

Code appreciated. Thanks


回答1:


An example using EnumWindows:

BOOL CALLBACK WorkerProc(HWND hwnd, LPARAM lParam) {
    static TCHAR buffer[50];

    GetWindowText(hwnd, buffer, 50);
    if(_tcsstr(buffer, "window name goes here")) {
        // do something with hwnd here
        return FALSE;
    }

    return TRUE;
}

And then call it like this:

EnumWindows(WorkerProc, NULL);


来源:https://stackoverflow.com/questions/1268314/findwindow-with-partial-window-title-windows-c

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