Source: Let the program run only one
Many people have discussed this problem, which is done with the existing shared memory feature in the Victor serial control. when the program runs the second time, it simply activates the first run window instead of running a program.
Need to be implemented in the main program, belowthe blue partIs the added content:
#include <vcl.h> #pragma hdrstop
#include "yb_base.h"
//---------------------------------------------------------------------------
Useform ("UnitTestMain.cpp", Form1);
//---------------------------------------------------------------------------
WINAPI WinMain (hinstance, HINSTANCE, LPSTR, int)
{
//Two programs cannot have the same flag, programs with the same flag can only run one
tsharedmemory Appmark ("victor_20030526_2131", 4096); //Use shared memory to Set program flags
if (appmark.exists) //The program is already running
{
Appmark.activeappwnd (); //Activate a program window that is already running
return 0; //Exit program
}
Appmark.clearbuffer (); //Clear Cache
Try
{
Application->initialize ();
Application->createform (__classid (TFORM1), &form1);
Appmark.appinfo->hmainwnd = application->handle; //Handle is saved in shared memory
Application->run ();
}
catch (Exception &exception)
{
//.... Omit for future content
Let the program run only one C + + Builder implementation at the same time (go)