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 Anwendung im Tray = Rechner fährt nicht runter??? (https://www.delphipraxis.net/118202-anwendung-im-tray-%3D-rechner-faehrt-nicht-runter.html)

Schucki 2. Aug 2008 17:53


Anwendung im Tray = Rechner fährt nicht runter???
 
Also eigendlich klappt das so wie ich es wollte.
Anwendung wird minimiert und neben der Uhr angezeigt. Toll... ;)


Delphi-Quellcode:
procedure HideTheApplication;
begin
  ShowWindow(Application.Handle, SW_HIDE);
  frmMain.TrayIconMain.Visible:=True;
end;

procedure ShowTheApplication;
begin
  frmMain.TrayIconMain.Visible:=False;
  ShowWindow(Application.Handle, SW_SHOW);
  Application.Restore;
end;

procedure TfrmMain.ApplicationEventsMinimize(Sender: TObject);
begin
  HideTheApplication;
end;
Was allerdings nicht geht und deshalb meld ich mich hier zu Wort ist wenn die Anwendung neben der Uhr liegt und ich den Rechner runterfahren möchte.

Dann muß ich die Anwendung erst aus dem Tray holen, diese dann beenden und dann nochmal auf Runterfahren drücken.

Warum ist das so? Wie kann meine Anwendung mitbekommen das Feierabend ist?

Gruß Frank

SaFu 2. Aug 2008 18:00

Re: Anwendung im Tray = Rechner fährt nicht runter???
 
Probier dasmal

Delphi-Quellcode:
function MyExitWindows(RebootParam: Longword): Boolean;
var
  TTokenHd: THandle;
  TTokenPvg: TTokenPrivileges;
  cbtpPrevious: DWORD;
  rTTokenPvg: TTokenPrivileges;
  pcbtpPreviousRequired: DWORD;
  tpResult: Boolean;
const
  SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
begin
  if Win32Platform = VER_PLATFORM_WIN32_NT then
  begin
    tpResult := OpenProcessToken(GetCurrentProcess(),
      TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
      TTokenHd);
    if tpResult then
    begin
      tpResult := LookupPrivilegeValue(nil,SE_SHUTDOWN_NAME,TTokenPvg.Privileges[0].Luid);
      TTokenPvg.PrivilegeCount := 1;
      TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      cbtpPrevious := SizeOf(rTTokenPvg);
      pcbtpPreviousRequired := 0;
      if tpResult then
        Windows.AdjustTokenPrivileges(TTokenHd,False,TTokenPvg,cbtpPrevious,rTTokenPvg,pcbtpPreviousRequired);
    end;
  end;
  Result:= ExitWindowsEx(RebootParam, 0);
end;


MyExitWindows(EWX_POWEROFF or EWX_FORCE);

Gruß Sascha

worker 2. Aug 2008 19:15

Re: Anwendung im Tray = Rechner fährt nicht runter???
 
Ein einfaches
Delphi-Quellcode:
procedure TForm1.WMQueryEndSession(var Message: TWMQueryEndSession);
begin
   inherited;
   Message.Result := 1;
end;
tut's auch ;)


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:23 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