Trey
Trey

Reputation: 554

Calling FindWindowEx with program WIndowClass

I'm trying to use FindWindowEx to determine whether a certain program is running or not.

FindWindow(NULL, "Mozilla Firefox");

This works fine as long as I'm on firefox's start page. A workaround I found was:

FindWindow(NULL, "MozillaWindowClass");

But that left me wondering if that was specifically crafted for firefox, but it turns that it appeareantly works for other applications:

FindWindow(NULL, "OllyDbgWindowClass");

So my question is can I just use FindWindow with an argument like "programXWindowClass" for any program? Are there any exceptions to this?

Is "programXWindowClass" guaranteed to exist?

Upvotes: 0

Views: 106

Answers (2)

IInspectable
IInspectable

Reputation: 51511

There is no requirement for a caller to RegisterClassEx to follow any particular pattern, that maps a window class name to any other information (like the application name). Any caller can pick any valid window class name they like.

Keep in mind two notable consequences of this:

  • A window class name need not be unique to any given application. All UWP applications use the window class "Windows.UI.Core.CoreWindow" by default, for example.
  • A window class name can change across different versions of an application, or even different invocations of an application.

Upvotes: 3

David Heffernan
David Heffernan

Reputation: 613491

Is "programXWindowClass" guaranteed to exist?

No. What you observed is merely a coincidence in naming.

Upvotes: 1

Related Questions