Home > Back-end >  BCB6 program how to repetitive call open don't open the window?
BCB6 program how to repetitive call open don't open the window?

Time:10-27

RT, I use c + + builder now developed A medium-sized program, need to call the B form in A form, after the call B open form, while minimizing artificially in A form click call again B form, not to repeat to open, how to form B B form of minimizing the original front display?

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:

refer to 6th floor sololie response:
C/C + + code
?



12345678910111213141516171819202122232425262728293031323334353637383940

HANDLE hMutex; Const char * TXT="ha ha";//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -...

The positive solution is to open exe

CodePudding user response:

Demon elder brother said to, I just did not give an indicative code
WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int)
{
HANDLE hMutex=CreateMutex (NULL, False, "FormA");//create a mutex
If (hMutex==NULL | | : : GetLastError ()==ERROR_ALREADY_EXISTS)
{
ShowMessage (" Exits ");
HANDLE hWindow=FindWindow (NULL, "FormA");//get the already running instance handle
SendMessageA (hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);//back to minimize the former instance
The SetForegroundWindow (hWindow);//the first instance is active
Application - & gt; The Terminate ();//end of this instance
}
Try
{
Application - & gt; The Initialize ();
Application - & gt; CreateForm (__classid (TForm1), & amp; Form1);
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;
}
  • Related