views:

714

answers:

1

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

+6  A: 

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);
arul
How can I pass a changing title to that function? I mean, the windows that i need to get the handle of can have up to 4 different titles with fix parts. So the "window name goes here" can take 4 different strings.
wonderer
Never mind... i didn't read the code correctly before. Let me try it
wonderer
That worked. Thanks!
wonderer