Hi:
I'm using C++Builder 10.1, making a Win64, UNICODE, VCL with Styles (Auric) application.
I want to have a program that runs only once at time.
I've solved that part.
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
WM_REGISTERED_my_showRestore = RegisterWindowMessage(_T("myShowRestoreMessage));
HANDLE mailMutex = CreateMutex(NULL, true, _T("myAppMutex"));
if( ERROR_ALREADY_EXISTS == GetLastError() )
{
// Program already running somewhere
if (__argc == 1) {
HWND hWnd = FindWindow(NULL, _T("myVCLApplication"));
if ( hWnd ) {
//ShowWindowAsync( hWnd, SW_SHOW); // Make the window visible if it was hidden
ShowWindow( hWnd, SW_SHOW); // Make the window visible if it was hidden
//ShowWindowAsync( hWnd, SW_RESTORE); // Next, restore it if it was minimized
ShowWindow( hWnd, SW_RESTORE); // Make the window visible if it was hidden
SetForegroundWindow(hWnd); // Finally, activate the window
//::SendMessage(hWnd, WM_REGISTERED_my_showRestore, 0, 0);
//::SendMessage(HWND_BROADCAST, WM_REGISTERED_my_showRestore, 0, 0);
::PostMessage(hWnd, WM_REGISTERED_my_showRestore, 0, 0);
// ::PostMessage(hWnd, WM_USER+2000, 0, 0);
}
}
...
When the second instance runs I detect the previous instance and I want to SHOW / RESTORE that window.
However I wasnt able to receive the message in the main Form.
I've tried using:
* TApplicationEvent (capturing OnMessage)
* Application->OnMessage = AppMessage;
* TForm1::WndProc(TMessage &message)
but in all cases I wasnt able to receive the message.
Any hints?
I've tested the same calling code with a OWLNext based application and it worked like charm, but for some reason the Form dont receive the message.
Thanks in advance.
Sebas
Application->OnMessage = AppMessage;