在程序运行时,取消系统的关闭显示器和屏保

方法1

procedure WMSysCommand(var Msg : TWMSysCommand); message WM_SYSCOMMAND;
[pascal]
// SWITCH OFF THE SCREENSAVER AND THE MONITOR POWER SAVER IF THEY TRY TO CUT IN
procedure TForm1.WMSysCommand(var Msg : TWMSysCommand);
begin
//catch the message and turn it off
if (Msg.CmdType = SC_MONITORPOWER) or (Msg.CmdType = SC_SCREENSAVE) then
begin
Msg.Result := -1;
end
else
inherited;///Otherwise do whatever is supposed to be done
end;
[/pascal]

方法2:

type
EXECUTION_STATE = DWORD;
const
ES_SYSTEM_REQUIRED = DWORD($00000001);
ES_DISPLAY_REQUIRED = DWORD($00000002);
ES_USER_PRESENT = DWORD($00000004);
ES_CONTINUOUS = DWORD($80000000);
function SetThreadExecutionState(esFlags: EXECUTION_STATE): EXECUTION_STATE; stdcall; external kernel32;

 

Lazarus中,Windows没有定义SetThreadExecutionState,需自己定义,然后

SetThreadExecutionState(ES_DISPLAY_REQUIRED or ES_CONTINUOUS); // this will fix current state and disable screensaver

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据