Prevent procedure from running repeatedly

xiaoxiao2021-03-06  44

/ / -------------------------------------------------------------------------------------------- --------------------------- # include #pragma hdrstop // ----------- -------------------------------------------------- -------------- USEFORM ("Unit1.cpp", Form1); // ----------------------- -------------------------------------------------- --WinaPi WinMain (Hinstance, Hinstance, LPSTR, INT) {// ******* Change ****** HWND HMUTEX; try {// Try to open this program unique Mutex identification object hmutex = OpenMutex ( Mutex_all_access, 0, "Prevent Program Repeat"); // If successful, it means that the program has been in executing to get this program or refer to the front, iF (hmutex) {// Looking for the program name Returns Handle Hwnd Han = FindWindow (NULL, "FORM1"); if (han) {// Tip has been repeatedly opened this program showMessage ("This program is turned on!"); // Get the Handle of the Form1 window displayed on the desktop And mention the front hwnd tophWnd = getTopWindow (HAN); if (Tophw) :: setForegroundWindow (Tophwnd); Else :: setForeGroup DINDOW (HAN);} Return 1;} // If this program has no special MUTEX identification object, Establish a new identification object Else Createmutex (0, 0, "prevention program repeated operation"); // **************** TRY {Application-> Initialize (); Application-> Createform (__ classid (tform1), & form1); Application-> Run ();} catch (exception & exception) {Application-> showexception (& Exception);} catch (...) {Try {throw Exception ("");} CatCH (Exception & Exception) {Application-> Showexception (& Exception);}} // ****** Change *****} // When the program ends, release MUTEX identification object __finally {: ReleaseMutex (hmutex);} // *************** RETURN 0;

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

New Post(0)