Determining If a Previous Instance of a Process Is Running

Makers of certain target devices, such as Pocket PC, recommend that only a single instance of your application run at any time. In the event the user attempts to start a second instance, the second instance should terminate and bring the first instance to the foreground. The code in Listing 5.6 shows how to use FindWindow to locate the main application window of the first instance. The function FindWindow is passed the class name of the window. The second parameter is the window title, which is passed as NULL so that any window title will result in a match.

If FindWindow returns NULL, then this is the first instance of the application, and the application can continue executing. A non- ...

Get Windows® CE 3.0 Application Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.