![]() |
SetForegroundWindow vs. CoolTrayIcon.ShowMainForm
Ich nutze Mutex, um den Mehrfachstart eines Tools zu verhindern. Mein Programmstart sieht folgendermaßen aus:
Delphi-Quellcode:
Funktioniert soweit alles wunderbar. Das Tool benutzt das CoolTrayIcon und kann darüber komplett in die Taskbar minimiert werden. Um es wiederherzustellen wäre dann ein Klick auf Icon nötig, der die ShowMainForm-Methode der Komponente auslöst.
Mutex := CreateMutex(nil, True, cMutexID);
// +++ identify an already running app +++ if (Mutex <> 0) and (GetLastError = 0) then begin // +++ none was found, so proceed as usual +++ {...} end else begin // +++ look for the running app windows handle +++ Application.Initialize; repeat HAPPLICATION := FindWindow(PChar('TSPMTmain'), nil); until HAPPLICATION <> Application.Handle; // +++ found it, so activate the running app +++ if HAPPLICATION <> 0 then begin Windows.ShowWindow(HAPPLICATION, SW_Normal); Windows.SetForegroundWindow(HAPPLICATION); end; Halt; end; Obiger Code aktiviert allerdings das vorhandene Fenster via API und umgeht dabei die notwendige CoolTrayIcon-Methode. Folge: Das Tool wird nicht in der Taskleiste angezeigt und lässt sich auch nicht mehr minimieren - erst ein Klick aufs TrayIcon stellt das Fenster korrekt wieder her ... Gibt es eine einfache Möglichkeit das CoolTrayIcon.ShowMainForm des anderen Prozesses auszulösen? Oder muss ich dafür doch extra Messages einrichten? |
Re: SetForegroundWindow vs. CoolTrayIcon.ShowMainForm
Hast du schon eine Lösung gefunden?
|
Re: SetForegroundWindow vs. CoolTrayIcon.ShowMainForm
Falls das hier jmd. interessiert, die Lösung:
Delphi-Quellcode:
Im OnRestore Ereignis der Anwendung (ApplicationEvents benutzen!) kann man dann festlegen, dass das TrayIcon verschwindet.
repeat
appH := FindWindow(PChar('TMform'), nil); until appH <> Application.Handle; if appH <> 0 then begin ParentH := GetWindowLong(appH, GWL_HWNDPARENT); Windows.ShowWindow(appH, SW_Normal); postmessage(ParentH,WM_SYSCOMMAND,SC_RESTORE,0); Windows.SetForegroundWindow(appH); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:30 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz