Code example to check only one program instance
Add the following code to your WinMain() function to check that only one instance of a program is running. The code snippet first checks to see if the application exists, if it does the application will be brought to the foreground.
In this example we have a win32 based Borland TApplication with the name "Application_name" (i.e. Application->Title = "Application_name").Show Plain Text
- WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
- HWND HWnd;
- if ((HWnd = FindWindow("TApplication", "Application_name")) != NULL)
- ShowWindow(HWnd, SW_RESTORE);
- return 0;