CodePudding user response:
FormB - & gt; WindowState=wsNormal;CodePudding user response:
//"how B form not to open the"
The static BYTE b=0;
Void __fastcall TForm1: : btn1Click (TObject * Sender)
{
TAboutBox * AboutBox=new TAboutBox (Application);
If (b==0)
AboutBox - & gt; Show ();
B++;
}
CodePudding user response:
Embarrassed, we all did not understand what I mean, I have a problem, the expression of what I mean is almost for the first time. Double-click the inspector exe, then the window is opened, a second double-click the inspector again. Exe, the program will not repeat, first open can be carried in the front, from the background out,CodePudding user response:
Open the Form before judgment about.If (Application - & gt; FormB FindComponent (" ")!=NULL)
{
A new show out
}
The else
{
Directly show
}
CodePudding user response:
Use the mutex, application starts trying to open the mutually exclusive:If can't open, you create a mutex and continues to run, to create a memory mapping, the main form of handle to Shared memory,
If can open, there is a instance, open the memory mapping, an instance from the Shared memory read main window handle, "bringing it to the front desk, and then the process exits,
CodePudding user response:
HANDLE hMutex;
Const char * TXT="ha ha";
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
USEFORM (" shell. The CPP, "FormMain);
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int)
{
Try
{
HMutex=CreateMutex (NULL, FALSE, TXT);
//check the error code
If (GetLastError ()==ERROR_ALREADY_EXISTS)
{
The CloseHandle (m_hMutex);
The exit (EXIT_SUCCESS);
}
Application - & gt; The Initialize ();
Application - & gt; Title="ha ha";
Application - & gt; CreateForm (__classid (TFormMain), & amp; FormMain);
Application - & gt; The Run ();
}
The catch (Exception & amp; The exception)
{
Application - & gt; ShowException (& amp; The exception);
}
The catch (... )
{
Try
{
Throw Exception (" ");
}
The catch (Exception & amp; The exception)
{
Application - & gt; ShowException (& amp; The exception);
}
}
return 0;
}
CodePudding user response:
WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int){
Try
{
The HWND HWND;
HWnd=FindWindowEx (NULL, NULL, NULL, "software");
If (hWnd!=NULL)//find the old process
{
ShowWindow (hWnd, SW_SHOW);//show the old process
//ShowWindow (hWnd, SW_RESTORE);//BringWindowToTop (hWnd);//
The SetForegroundWindow (hWnd);//front the old process
return 0;//out of the current process
CodePudding user response: