This works, just add it to the beginning of WinMain.
Code:
/* Vars */
HANDLE hMutex; // Mutex Handle
HWND hwndShow; // Find Window HWND
/* Create A Mutex To Register Program Is Running */
hMutex = CreateMutex(
NULL,
FALSE,
"myMutex"
);
/* If Program Is Already Running, Show Program & Stop */
if (hMutex) {
if (GetLastError() == ERROR_ALREADY_EXISTS) {
// Replace WINCLASS_HERE with name of your class
hwndShow = FindWindow(WINCLASS_HERE, NULL);
if (hwndShow) {
// Minimize The Program So It Can Be Restored
ShowWindow(hwndShow, SW_MINIMIZE);
UpdateWindow(hwndShow);
// Restore The Program In Its Original State
ShowWindow(hwndShow, SW_RESTORE);
UpdateWindow(hwndShow);
}
ExitProcess(1);
}
}
Make sure to change the code to reflect your Window class. You don't have to include the SW_MINIMIZE ShowWindow, its just there to make sure the window shows no matter how many other maximized windows you have.