笔记本手动关闭显示器(附测试代码)

这篇博客介绍了如何使用Delphi编写代码来手动控制笔记本显示器的关闭和开启。通过发送WM_SYSCOMMAND消息,当点击按钮时关闭显示器,而当检测到键盘或鼠标活动时则自动打开显示器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用 Colse LCD,运行就关闭显示器,有鼠标或者键盘事件就会打开

 

unit OpenCloseMonitor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    ButtonCloseMonitor: TButton;
    procedure FormCreate(Sender: TObject);
    procedure ButtonCloseMonitorClick(Sender: TObject);
  private
    procedure OnAppMessage(var Msg: TMsg; var Handled: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ButtonCloseMonitorClick(Sender: TObject);
begin
  // 关闭显示
  SendMessage(Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 1);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Width := Screen.Width;
  Height := Screen.Height;

  ButtonCloseMonitor.Align := alClient;
  Application.OnMessage := OnAppMessage;
end;

procedure TForm1.OnAppMessage(var Msg: TMsg; var Handled: Boolean);
begin
  case Msg.message of
  WM_CHAR:
    begin
      // 打开显示
      SendMessage(Handle, WM_SYSCOMMAND, SC_MONITORPOWER, -1);
      Application.Terminate;
    end;
  end;
end;

end.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值