Einzelnen Beitrag anzeigen

PremiumPils

Registriert seit: 26. Sep 2004
21 Beiträge
 
Delphi 7 Personal
 
#8

Re: Ferngesteuertes Schließen einer Anwendung

  Alt 10. Jan 2005, 22:43
Zitat:
In dem du eine WM_QUIT Nachricht an den Thread schickst.
Beendet WM_QUIT, oder schließt es. Sprich, kommt der Thread noch dazu, seine Daten zu speichern?

Zitat:
Wie beendet man das Programm als Benutzer?
Ja - normal halt, da es sich um ein normales Delphi Windows Programm handelt, welches, wenn man es ins Tray minimiert im Task-Manager aus der Anwendungen-Liste verschwindet, und nur noch in der Prozesse-Liste ist. Dann funktioniert es wohl nicht mehr wie es soll.

Der Benutzer kann das Programm+zugehöriges Fenster mit einem klick auf das Tray-Icon wiederherstellen. Dann einfach nur noch auf das X im System Menu oben drücken, und es ist auch beendet.

Anbei einmal die beiden Funktionen, wie ich sie ursprünglich benutze:

Delphi-Quellcode:
function OwnFunctionAppKill2(MyEXE : string; MyWarteZeit:Integer) : boolean;
var
  MyHandle : HWND;
  MyZaehler : Integer;
begin
  Result := false;
  if OwnFunctionAppIsRunning2(MyHandle,MyEXE) then
  begin
    for MyZaehler := 1 to (MyWarteZeit * 4) do
    begin
      Sleep(250);
      Application.ProcessMessages;
      if not OwnFunctionAppIsRunning2(MyHandle,MyEXE) then
      begin
        Result := true;
        break;
      end
      else
      begin
        Result := false;
        PostMessage(MyHandle, WM_CLOSE, 0, 0);
      end;
    end;
  end
  else
  begin
    Result := true;
  end;
end;
{--------------------------------------------------------------------------------------------------------------}
{--------------------------------------------------------------------------------------------------------------}
function OwnFunctionAppIsRunning2(var MyHandle : HWND; MyEXE : String) : Boolean;
  function GetWindowByAppName(ApplicationName: String): Cardinal;
    function GetAppProcID(ApplicationName : String):Cardinal;
    var
      bContinue: BOOL;
      aSnapshotHandle: THandle;
      aProcessEntry32: TProcessEntry32;
    begin
      result := 0;
      aSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
      aProcessEntry32.dwSize := SizeOf(aProcessEntry32);
      bContinue := Process32First(aSnapshotHandle, aProcessEntry32);
      while Integer(bContinue) <> 0 do
      begin
        if LowerCase(aProcessEntry32.szExeFile) = LowerCase(ApplicationName) then result := aProcessEntry32.th32ProcessID;
        bContinue := Process32Next(aSnapshotHandle, aProcessEntry32);
      end;
      CloseHandle(aSnapshotHandle);
    end;
    function GetHandleFromProcID(aProcID : Cardinal) : Cardinal;
       function EnumWindowsProc(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
       begin
         TList(lParam).Add(Pointer(hWnd));
         Result := True;
       end;
    var
      List: TList;
      ProcessId: DWORD;
      I: Integer;
    begin
      Result := 0;
      List := TList.Create;
      try
        if EnumWindows(@EnumWindowsProc, Longint(List)) then
        begin
          for I := 0 to List.Count - 1 do
          begin
            GetWindowThreadProcessId(Longint(List.Items[I]), ProcessId);
            if aProcID = ProcessId then
            begin
              Result := Longint(List.Items[I]);
              Break;
            end;
          end;
        end;
      finally
        List.Free;
      end;
    end;
  begin
    result := GetHandleFromProcID(GetAppProcID(ApplicationName));
  end;
begin
  MyHandle := GetWindowByAppName(MyEXE);
  if (MyHandle <> 0 ) then Result := true
                      else Result := false;
end;
  Mit Zitat antworten Zitat