gpt4 book ai didi

delphi - 如何以编程方式更改特定显示器的分辨率?

转载 作者:行者123 更新时间:2023-12-03 15:50:27 24 4
gpt4 key购买 nike

如何以编程方式更改特定显示器的分辨率?例如,可以通过编程方式更改辅助显示器分辨率吗?

最佳答案

以下函数可能是您的起点。它尝试将 Index 参数(如果存在)指定的索引的显示设备的分辨率更改为 Width 指定的宽度和高度(以像素为单位), 高度参数。如果找到给定索引的显示设备并且已成功更改其分辨率,则该函数返回 True,否则返回 False。

您尚未指定是否要永久更改分辨率(如果要存储设置更改),还是仅临时更改。以下示例暂时执行此操作,但如果您在第二个中使用 ChangeDisplaySettingsEx ,则可以非常简单地更改此行为函数调用 dwflags 参数的 CDS_UPDATEREGISTRY 值:

function ChangeMonitorResolution(Index, Width, Height: DWORD): Boolean;
var
DeviceMode: TDeviceMode;
DisplayDevice: TDisplayDevice;
begin
Result := False;
ZeroMemory(@DisplayDevice, SizeOf(DisplayDevice));
DisplayDevice.cb := SizeOf(TDisplayDevice);
// get the name of a device by the given index
if EnumDisplayDevices(nil, Index, DisplayDevice, 0) then
begin
ZeroMemory(@DeviceMode, SizeOf(DeviceMode));
DeviceMode.dmSize := SizeOf(TDeviceMode);
DeviceMode.dmPelsWidth := Width;
DeviceMode.dmPelsHeight := Height;
DeviceMode.dmFields := DM_PELSWIDTH or DM_PELSHEIGHT;
// check if it's possible to set a given resolution; if so, then...
if (ChangeDisplaySettingsEx(PChar(@DisplayDevice.DeviceName[0]),
DeviceMode, 0, CDS_TEST, nil) = DISP_CHANGE_SUCCESSFUL)
then
// change the resolution temporarily (if you use CDS_UPDATEREGISTRY
// value for the penultimate parameter, the graphics mode will also
// be saved to the registry under the user's profile; for more info
// see the ChangeDisplaySettingsEx reference, dwflags parameter)
Result := ChangeDisplaySettingsEx(PChar(@DisplayDevice.DeviceName[0]),
DeviceMode, 0, 0, nil) = DISP_CHANGE_SUCCESSFUL;
end;
end;

如何将辅助显示设备(索引为 1 的设备)的分辨率更改为 800x600 的示例:

procedure TForm1.Button1Click(Sender: TObject);
begin
if ChangeMonitorResolution(1, 800, 600) then
ShowMessage('Resolution of display device with index 1 has been changed!')
else
ShowMessage('Display device with index 1 doesn''t exist, doesn''t support ' +
'resolution 800x600 or changing failed due to a reason, which you might ' +
'know if the author of this function wouldn''t be so lazy!');
end;

关于delphi - 如何以编程方式更改特定显示器的分辨率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15101977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com