Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi SetForegroundWindow vs. CoolTrayIcon.ShowMainForm (https://www.delphipraxis.net/107427-setforegroundwindow-vs-cooltrayicon-showmainform.html)

Master-of-Magic 27. Jan 2008 16:37


SetForegroundWindow vs. CoolTrayIcon.ShowMainForm
 
Ich nutze Mutex, um den Mehrfachstart eines Tools zu verhindern. Mein Programmstart sieht folgendermaßen aus:

Delphi-Quellcode:
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;
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.

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?

API 18. Feb 2008 06:21

Re: SetForegroundWindow vs. CoolTrayIcon.ShowMainForm
 
Hast du schon eine Lösung gefunden?

TonyR 27. Apr 2008 16:09

Re: SetForegroundWindow vs. CoolTrayIcon.ShowMainForm
 
Falls das hier jmd. interessiert, die Lösung:
Delphi-Quellcode:
   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;
Im OnRestore Ereignis der Anwendung (ApplicationEvents benutzen!) kann man dann festlegen, dass das TrayIcon verschwindet.


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