Process:
1. Create a mutex when the program is initialized
2, detect the exclusion of the error code returned to see if there is this mutex
3, if the same mutex already exists, then release the created mutex handle, and reset the mutex, and then exit the program
The specific code is as follows:
Copy Code code as follows:
Create mutexes
HANDLE M_hmutex = CreateMutex (NULL, FALSE, _t ("D3gphonedlg"));
Check for error codes
if (GetLastError () = = error_already_exists) {
Disposes the handle and resets the mutex if there is an existing mutex
CloseHandle (M_hmutex);
M_hmutex = NULL;
::P Ostmessagew (Hwnd_broadcast, Wm_d3gphonedlg_msg, 1, 2);//Notify Open program, activate window
Program exit
Cdialog::oncancel ();
}
"EOF" Prevents a program from creating multiple instances * *
This code is tested in the WinCE MFC program and placed in the OnInitDialog () function of the program.
When you are testing, you can start by commenting out the words that activate the window.