FindWindow
only finds the window if it has the exact specified title, not just a substring.
Alternatively you can:
search for the window class name:
HWND hWnd = FindWindow("MozillaWindowClass", 0);
enumerate all windows and perform custom pattern searches on the titles:
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
char buffer[128];
int written = GetWindowTextA(hwnd, buffer, 128);
if (written && strstr(buffer,"Mozilla Firefox") != NULL) {
*(HWND*)lParam = hwnd;
return FALSE;
}
return TRUE;
}
HWND GetFirefoxHwnd()
{
HWND hWnd = NULL;
EnumWindows(EnumWindowsProc, &hWnd);
return hWnd;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…