Retrieving main window handle

  • Thread starter Thread starter fdmaxey
  • Start date Start date
F

fdmaxey

I am currently using one process to find if another MDI windows process
is running. If it is SendMessage is used to display a given screen.

I use GetProcessesByName to determine if the target windows process was
running. If not, it is started.

Once the target process started, the MainWindowHandle is retrieved and
used by SendMessage to direct the target process to display a given
screen.

All well and good. As of late however, we seem to be running into
problems because GetProcessesByName is taking prohibitive amounts of
time and even returning an error.

SystemManager can be employed to get the process data much faster and
more reliably, but it doesn't include the main window handle.

Is there any way that I can determine the main window handle of the
target process by any other method than GetProcessesByName?


Frank Maxey
 
Does the process have a unique window class name or title? If so,
FindWindow will get you the handle based on that with virtually no overhead.
You can use a number of programs out there to find the class and title...if
you have VS, you may have Spy++ installed which is what I use.

http://msdn.microsoft.com/library/d...indowreference/windowfunctions/findwindow.asp

and

http://www.pinvoke.net/default.aspx/user32.FindWindow

There are other ways too...but this is the simplest IF the window class name
and title are pretty unique.

HTH
-sb
 
Thanks for the reply.

Unfortunately, being an MDI form, the main window title is not unique.
The beginning text is the same, but the ending text will change
depending on the child window that is currently active.

There is an API, I believe, which retrieves all windows. I could simply
check the starting text for the window title I need. It seems a bit
kludgy, though.

Frank Maxey
 
Back
Top