procedure TFormBDE.ActivateDisplay;
var
B, M: BOOL;
U: TLastInputInfo;
P: TWindowPlacement;
H: HWND;
F
{,C}: DWORD;
begin
// Bildschirm an (Screensaver oder Standby)
U.cbSize := SizeOf(U);
TDM1.LogEvent('
WM_SYSCOMMAND+SC_MONITORPOWER: ' + IntToStr(FMonitorState) + '
-> ' + BoolToStr(
not ((FMonitorState = -1)
or (FMonitorState = 2)), True));
TDM1.LogEvent('
GetLastInputInfo: ' + BoolToStr(GetLastInputInfo(U), True) + '
' + IntToStr(GetTickCount - U.dwTime));
M :=
// Monitor im Standby
not ( (FMonitorState = -1
{MONITOR_ON})
or (FMonitorState = 2
{MONITOR_OFF})
)
// seit x Stunden keine Benutzeraktion
or ( GetLastInputInfo(U)
and (GetTickCount - U.dwTime > 1 * MinsPerHour * MSecsPerMin)
);
if M
then
SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, -1
{MONITOR_ON});
// MONITOR_ON=-1, MONITOR_STANDBY=1, MONITOR_OFF=2
{$REGION 'Bildschirm anfordern'}
// ES_SYSTEM_REQUIRED = CPU anfordern (kein automatisches Standby/Hibernate/Shutdown)
// ES_DISPLAY_REQUIRED = Anzeige anfordern (kein Bildschirmschoner oder Monitor-Standby)
if miNoStandby.Checked
and FeigRFIDReader.Enabled
then
SetThreadExecutionState(ES_DISPLAY_REQUIRED
or ES_SYSTEM_REQUIRED)
else
SetThreadExecutionState(ES_DISPLAY_REQUIRED);
//
Sleep(55);
if miNoStandby.Checked
and FeigRFIDReader.Enabled
then // eigentlich könnte der ExecutionState auch erst beim Logout zurückgesetzt werden -> DisableAufZeitIoVisuals
SetThreadExecutionState(ES_SYSTEM_REQUIRED)
else
SetThreadExecutionState(0);
{$ENDREGION}
TDM1.LogEvent('
SystemParametersInfo ' + BoolToStr(SystemParametersInfo(SPI_GETSCREENSAVERRUNNING
{16}, 0, @B, 0), True) + '
' + BoolToStr(B, True));
//TDM1.LogEvent('GetDevicePowerState ' + BoolToStr(GetDevicePowerState(Self.Monitor.Handle, @B), True) + ' ' + BoolToStr(B, True));
// GetDevicePowerState : https://docs.microsoft.com/de-de/windows/desktop/api/winbase/nf-winbase-getdevicepowerstate
// Retrieves the current power state of the specified device. >>>This function cannot be used to query the power state of a display device.<<<
if (SystemParametersInfo(SPI_GETSCREENSAVERRUNNING
{16}, 0, @B, 0)
and B)
// Bildschirmschoner ist aktiv -> Bildschirmschoner wieder aus, sobald MONITOR_STANDBY
or M
{(GetDevicePowerState(Self.Monitor.Handle, @B) and not B)}
then
begin // Monitor NICHT angeschaltet -> siehe WM_SYSCOMMAND+SC_MONITORPOWER
TDM1.LogEvent('
do Keybd_Event');
//Mouse_Event(MOUSEEVENTF_MOVE, +1, 0, 0, 0);
//Mouse_Event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
Keybd_Event(VK_LCONTROL, 1, 0, 0);
Keybd_Event(VK_LCONTROL, 1, KEYEVENTF_KEYUP, 0);
end;
// Fenster auf (minimiert oder im Hintergrund)
TDM1.LogEvent('
IsIconic(Application) ' + BoolToStr(IsIconic(Application.Handle), True));
if IsIconic(Application.Handle)
then
Application.Restore;
TDM1.LogEvent('
IsIconic(MainForm) ' + BoolToStr(IsIconic(Application.MainForm.Handle), True));
if {Application.MainForm.WindowState = wsMinimized} IsIconic(Application.MainForm.Handle)
then
begin
TDM1.LogEvent('
do Application.MainForm.Restore');
P.length := SizeOf(P);
TDM1.LogEvent('
GetWindowPlacement ' + BoolToStr(GetWindowPlacement(Application.MainForm.Handle, @P), True));
if GetWindowPlacement(Application.MainForm.Handle, @P)
then
begin
P.showCmd := SW_RESTORE;
if P.flags
and WPF_RESTORETOMAXIMIZED <> 0
then
P.showCmd := SW_MAXIMIZE;
SetWindowPlacement(Application.MainForm.Handle, @P);
end
else
SendMessage(Application.MainForm.Handle, WM_SYSCOMMAND, SC_RESTORE, 0);
end;
TDM1.LogEvent('
IsIconic(Self) ' + BoolToStr(IsIconic(Self.Handle), True));
if {Self.WindowState = wsMinimized} IsIconic(Self.Handle)
then
begin
TDM1.LogEvent('
do Self.Restore');
P.length := SizeOf(P);
TDM1.LogEvent('
GetWindowPlacement ' + BoolToStr(GetWindowPlacement(Self.Handle, @P), True));
if GetWindowPlacement(Self.Handle, @P)
then
begin
P.showCmd := SW_RESTORE;
if P.flags
and WPF_RESTORETOMAXIMIZED <> 0
then
P.showCmd := SW_MAXIMIZE;
SetWindowPlacement(Self.Handle, @P);
end
else
SendMessage(Self.Handle, WM_SYSCOMMAND, SC_RESTORE, 0);
end;
// BDE aktiv (hat keinen Fokus)
Application.BringToFront;
Self.BringToFront;
H := Self.Handle;
if Self.FormStyle = fsMDIChild
then
H := Application.MainForm.Handle;
TDM1.LogEvent('
GetForegroundWindow ' + BoolToStr(GetForegroundWindow <> H, True));
if GetForegroundWindow <> H
then
begin
TDM1.LogEvent('
do SetForegroundWindow');
//C := GetWindowThreadProcessId(H, nil);
F := GetWindowThreadProcessId(GetForegroundWindow,
nil);
TDM1.LogEvent('
GetForegroundWindow ' + BoolToStr(
{C}GetCurrentProcessId <> F, True));
if {C}GetCurrentProcessId <> F
then
begin
AttachThreadInput(F,
{C}GetCurrentProcessId, True);
B := SetForegroundWindow(H);
AttachThreadInput(F,
{C}GetCurrentProcessId, False);
TDM1.LogEvent('
SetForegroundWindow ' + BoolToStr(B, True));
if B
then
SetForegroundWindow(H);
end
else
SetForegroundWindow(H);
end;
end;