Hi,ich will eine Fremdanwendung aus meiner heraus schliessen. Dazu habe ich folgendes gefunden: (http://www.delphi-fundgrube.de/)
Beitext: Man braucht dazu das Instanzen-Handle der zu beendenden Anwendung.
---------------------------------------
unit CloseApp;
interface
uses WinTypes;
procedure CloseAppFromInst(HInst: THandle);
implementation
uses WinProcs, Messages;
{ Callback function that has each top-level window passed to it. }<br>
{ Return true to continue enumerating, false to stop. }<br>
function EnumWindowsProc(Handle: HWND; Info: Pointer): boolean;<br>
{$IFDEF WIN32} stdcall; {$ELSE} export; {$ENDIF}<br>
begin<br>
Result := TRUE; { continue enumeration }<br>
{ Does this app have the same instance as what we are looking for? }<br>
{$IFDEF WIN32}<br>
if GetWindowLong(Handle, GWL_HINSTANCE) = LongInt(Info) then begin<br>
{$ELSE}<br>
if GetWindowWord(Handle, GWW_HINSTANCE) = LongInt(Info) then begin<br>
{$ENDIF}<br>
PostMessage(Handle, WM_CLOSE, 0, 0); { Close the app }<br>
Result := FALSE; { stop enumerating windows, we are done. }<br>
end;<br>
end;<br>
procedure CloseAppFromInst(HInst: THandle);<br>
begin<br>
EnumWindows(@EnumWindowsProc, LongInt(HInst));<br>
end;<br>
end.<br>
---------------------------------------
Meine Frage nun, wie kann ich den Instanzen-Handler ermitteln??
thx!
Beitext: Man braucht dazu das Instanzen-Handle der zu beendenden Anwendung.
---------------------------------------
unit CloseApp;
interface
uses WinTypes;
procedure CloseAppFromInst(HInst: THandle);
implementation
uses WinProcs, Messages;
{ Callback function that has each top-level window passed to it. }<br>
{ Return true to continue enumerating, false to stop. }<br>
function EnumWindowsProc(Handle: HWND; Info: Pointer): boolean;<br>
{$IFDEF WIN32} stdcall; {$ELSE} export; {$ENDIF}<br>
begin<br>
Result := TRUE; { continue enumeration }<br>
{ Does this app have the same instance as what we are looking for? }<br>
{$IFDEF WIN32}<br>
if GetWindowLong(Handle, GWL_HINSTANCE) = LongInt(Info) then begin<br>
{$ELSE}<br>
if GetWindowWord(Handle, GWW_HINSTANCE) = LongInt(Info) then begin<br>
{$ENDIF}<br>
PostMessage(Handle, WM_CLOSE, 0, 0); { Close the app }<br>
Result := FALSE; { stop enumerating windows, we are done. }<br>
end;<br>
end;<br>
procedure CloseAppFromInst(HInst: THandle);<br>
begin<br>
EnumWindows(@EnumWindowsProc, LongInt(HInst));<br>
end;<br>
end.<br>
---------------------------------------
Meine Frage nun, wie kann ich den Instanzen-Handler ermitteln??
thx!
Comment