频道分类

delphi 开关显示器操作

作者:admin 来源: 日期:2018/2/15 0:33:43 人气: 标签:

 
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Timer1: TTimer;
    Edit1: TEdit;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
  EDD_GET_DEVICE_INTERFACE_NAME = 1;
  ENUM_REGISTRY_SETTINGS = DWORD(-2);

procedure TForm1.Button1Click(Sender: TObject);
var
  Display: TDisplayDevice;
  DevMode: TDevMode;
begin
  Display.cb := SizeOf(TDisplayDevice);
  EnumDisplayDevices(nil, 1,Display, EDD_GET_DEVICE_INTERFACE_NAME);
  ZeroMemory(@DevMode, SizeOf(TDevMode));
  DevMode.dmSize := SizeOf(TDevMode);
  DevMode.dmBitsPerPel := 32;
  DevMode.dmFields := DM_BITSPERPEL or DM_PELSWIDTH or DM_PELSHEIGHT or DM_DISPLAYFREQUENCY or DM_DISPLAYFLAGS or DM_POSITION;
  ChangeDisplaySettingsEx(pwidechar(@Display.DeviceName[0]),DevMode, 0, CDS_UPDATEREGISTRY or CDS_NORESET, nil);
  ChangeDisplaySettingsEx(nil, PDevMode(nil)^, 0, 0, nil);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  Display: TDisplayDevice;
  DevMode: TDevMode;
begin
  Display.cb := SizeOf(TDisplayDevice);
  EnumDisplayDevices(nil, 1 ,Display, EDD_GET_DEVICE_INTERFACE_NAME);
  EnumDisplaySettings(pwidechar(@Display.DeviceName[0]),ENUM_REGISTRY_SETTINGS, DevMode);
  DevMode.dmFields := DM_BITSPERPEL or DM_PELSWIDTH or DM_PELSHEIGHT or DM_DISPLAYFREQUENCY or DM_DISPLAYFLAGS or DM_POSITION;
  ChangeDisplaySettingsEx(pwidechar(@Display.DeviceName[0]),DevMode, 0, CDS_UPDATEREGISTRY or CDS_NORESET, nil);
  ChangeDisplaySettingsEx(nil, PDevMode(nil)^, 0, 0, nil);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Button2.Click;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  Display: TDisplayDevice;
  DevMode: TDevMode;
begin
//获取显卡信息
  Display.cb := SizeOf(TDisplayDevice);
  EnumDisplayDevices(nil, 1,Display, EDD_GET_DEVICE_INTERFACE_NAME);
  Memo1.Lines.Add(pwidechar(@Display.DeviceString[0]));
  Memo1.Lines.Add(pwidechar(@Display.DeviceName[0]));
  Memo1.Lines.Add(pwidechar(@Display.DeviceKey[0]));

end;

end.