Use mutex to avoid procedures to run

xiaoxiao2021-03-06  185

1. Add a variable in the CWINAPP class

Handle hmutex;

2. Add the following code in InintInstance ():

CString szclassname = "shutdown";

HMutex = OpenMuteX (Mutex_all_Access, False, SzclassName);

IF (hmutex == null)

HMutex = Createmutex (Null, True, SzclassName);

Else

{

Messagebox (0, "program has been opened, can't run! / T", "Warning", MB_ok | MB_ICONERROR);

Return False;

}

3. Add the following code in ExitInstance ():

IF (hmutex! = NULL)

ReleaseMutex (HMUTEX);

转载请注明原文地址:https://www.9cbs.com/read-128309.html

New Post(0)