1

Is there any way to find a window by an incomplete name?

For instance, how would you find a Google Chrome window which can have many title names?
like Stack Overflow - Google Chrome

FindWindow function would work great if the window would always have the same name as a function like the one below would solve it.

HWND chrome = FindWindow(NULL,_T("Stack Overflow - Google Chrome"));
SetForegroundWindow(chrome);

But, what happens if the name changes constantly (like browsers)? How can I find a window by searching for a fixed starting / ending?

I am looking for is something like FindWindow(NULL,_T("something here - Google Chrome").
Is there any way to do it?

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
zurfyx
  • 31,043
  • 20
  • 111
  • 145

1 Answers1

3

You can use the window classname instead of the window title. For instance, you can find Firefox with

HWND firefox = FindWindow(_T("MozillaWindowClass"), NULL);

You can use any window spy type application like WinSight, WinSpy++, or (the one I used to find the Firefox window class) AutoHotkey's Window Spy utility.

For more info, see the MSDN documentation for FindWindow.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • 4
    +1. But if you need even tighter control (e.g. due to false positives from other apps, or if the class name isn't always consistent (unlikely)), then you can instead use [`EnumWindows()`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms633497%28v=vs.85%29.aspx) and manually search for the desired window. – Adam Rosenfield Oct 17 '13 at 19:47