?
Hm, also bei mir funktioniert das, unter Verwendung von TApplicationEvents, auch ohne benutzerdefinierte Nachricht...
//aus der Projekt.cpp
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
HANDLE hInstanceMutex = ::CreateMutex(NULL, TRUE, "TESTTI.MUTEX");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
if (hInstanceMutex)
CloseHandle(hInstanceMutex);
Application->Title = "";
HWND hPrevApp = ::FindWindow(NULL, "TESTTI");
if (hPrevApp)
{
PostMessage(hPrevApp, WM_SYSCOMMAND, SC_RESTORE, 0); // Falls minimiert
SetForegroundWindow(hPrevApp); // kein schöner Stil, aber bringt das Fenster in den Vordergrund...
}
return 0;
}
try
{
Application->Initialize();
Application->Title = "TESTTI";
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
ReleaseMutex(hInstanceMutex);
CloseHandle(hInstanceMutex);
return 0;
}
//---------------------------------------------------------------------------
// die beiden ApplicationEvents:
void __fastcall TForm1::ApplicationEvents1Minimize(TObject *Sender)
{
ShowWindow(Application->Handle, SW_HIDE);
TrayIcon1->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ApplicationEvents1Restore(TObject *Sender)
{
TrayIcon1->Visible = false;
ShowWindow(Application->Handle, SW_SHOW);
}
//---------------------------------------------------------------------------