AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Remove tray icon when killing program

Ein Thema von WojTec · begonnen am 17. Okt 2013 · letzter Beitrag vom 25. Jan 2014
 
Der schöne Günther

Registriert seit: 6. Mär 2013
6.199 Beiträge
 
Delphi 10 Seattle Enterprise
 
#10

AW: Remove tray icon when killing program

  Alt 18. Okt 2013, 10:27
That might indeed sound pretty complicated but there are a lot of free code snippets for "How do I find a window handle if I only have the process ID?". It's also what I'd strongly suggest since TerminateProcess is pretty much like shooting someone in the head... from behind.

Always give the other application a fair change to shut down and clean up. This also includes the remaining unwanted tray icon (blood splatter?).

Here's an excerpt of how I search for the Window handle of a process I only have the ID of for later sending a WM_CLOSE message. I believe it has a few shortcomings like only returning the first window that matches but it always served me well.

Delphi-Quellcode:
   TEnumInfo = record
      ProcessID: DWORD;
      HWND: THandle;
   end;

   //Prozess-ID muss stimmen. Das Fenster muss nicht aktiviert oder sichtbar sein!
   function EnumWindowsProc(Wnd: DWORD; var EI: TEnumInfo): Bool; stdcall;
   var
      PID: DWORD;
   begin
      GetWindowThreadProcessID(Wnd, @PID);
      Result := (PID <> EI.ProcessID);
      //or IsWindowVisible(WND)) or (not IsWindowEnabled(WND));

      if not Result then EI.HWND := WND; //Die Enumeration durch alle Fenster
      // geht NUR weiter, wenn diese Funktion TRUE liefert!
   end;

   //Wird kein Fenster gefunden, ist die Rückgabe 0
   function FindFirstWindow(PID: DWORD): DWORD;
   var
      EI: TEnumInfo;
   begin
      EI.ProcessID := PID;
      EI.HWND := 0;
      EnumWindows(@EnumWindowsProc, Integer(@EI));
      Result := EI.HWND;
   end;
Most of it was probably "borrowed" from this very forum.

You can then just get the Windowhandle
evilWindowHandle := FindFirstWindow(evilProcess.dwProcessId); and send a WM_CLOSE: PostMessage(evilWindowHandle, WM_CLOSE, LPARAM(False), WPARAM(False));
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:04 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