unit shut;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Classes, FMX.Forms, FMX.
Platform.Win, FMX.Types,
FMX.Layouts, FMX.Memo;
type
TForm1 =
class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FHwnd: HWND;
FOldWndProc: LONG;
{ Private-Deklarationen }
public
function WndProc(Hwnd: HWND; Msg:UINT; wParam: WPARAM; lParam: LPARAM): LRESULT;
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
function WindowProc(Hwnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT;
stdcall;
begin
Result := Form1.WndProc(Hwnd, Msg, wParam, lParam);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FHwnd := FmxHandleToHwnd(
Handle);
FOldWndProc := GetWindowLongPtr(FHwnd, GWL_WNDPROC);
SetWindowLongPtr(FHwnd, GWL_WNDPROC, NativeInt(@WindowProc));
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
SetWindowLongPtr(FHwnd, GWL_WNDPROC, FOldWndProc);
end;
function TForm1.WndProc(Hwnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT;
var TempList : TSTringList;
begin
Result := 0;
If Msg = WM_EndSession
then
begin
// BEREICH WAS BEIM SHUTDOWN PASSIEREN SOLL / Unabhängig von OnClose!
sleep(10000);
TempList := TStringList.Create;
TEmpList.Add('
TEST');
TempList.SaveToFile(ExtractFilePath(ParamStr(0))+'
Shutdown.txt');
TempList.Free;
end;
Result := CallWindowProc(Ptr(FOldWndProc), Hwnd, Msg, wParam, lParam);
end;
end.