Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Reliably using FindWindow?

I have an EXE and I use a mutex to prevent multiple instances from running at the same time.  If the user invokes another instance and the app is running already, then I use FlashWindowEx() to draw attention to the EXE. 

To obtain the HWND for the flash, I use FindWindow, passing the class name and window name.  With winforms, the class name is (on .NET 1.1)


The window name param matches the windows Text/Caption.  The problem is that I'd like to be able to have the caption change in the app, and not be hardcoded to a specific string.

I realize setting the class name is not possible since WinForms manages this underneath, however; is there a better way to looking up the window?  EnumWindows perhaps?


Sunday, September 26, 2004

The way I do this in VB6 is as follows:
- Call SetProp to set a unique tag on the main window
- Call EnumWindows to enumerate windows, and call GetProp to test if the unique tag exists.

Monday, September 27, 2004

Thanks Joe, I ended up finding a way without pinvoking user32 stuff thankfully.  By using System.Diagnostics.Process.GetProcesses() I can locate my own process instance, and check the process ID and exit out if it doesn't match.

Monday, September 27, 2004

*  Recent Topics

*  Fog Creek Home