delphi如何改变系统的分辨率?

bcap163 2004-11-04 04:14:57
如题!我搜了一下没有发现 先谢过!!!
...全文
120 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Rex_love_Burger 2004-11-04
  • 打赏
  • 举报
回复
var
DeviceMode: TDeviceMode;result:integer;
begin
EnumDisplaySettings(nil, Cardinal(-1), DeviceMode);
result:=DeviceMode.dmDisplayFrequency;
showmessage(inttostr(result)+'hz'); {捕获屏幕刷新率}

var
DeviceMode:TDeviceMode;result,iFrequency:integer;
begin
iFrequency:=85;
EnumDisplaySettings(nil,Cardinal(-1), DeviceMode);
DeviceMode.dmDisplayFrequency:=Cardinal(iFrequency);
result:=ChangeDisplaySettings(DeviceMode,CDS_UPDATEREGISTRY);
end; {改
bcap163 2004-11-04
  • 打赏
  • 举报
回复
刷新率呢?唉 没办法 有的弱
bcap163 2004-11-04
  • 打赏
  • 举报
回复
果然高手如云!!!非常感谢!!以后就跟大家混了~~~~~~~~~~~
zhangheaaa 2004-11-04
  • 打赏
  • 举报
回复
Windows提供给我们两个API函数,可以动态调整显示器的分辨率,他们是EnumDisplaySettings() 和ChangeDisplaySettings(),下面这个例子就是了

function DynamicResolution(X, Y: word): BOOL;
var
lpDevMode: TDeviceMode;
begin
Result := EnumDisplaySettings(nil, 0, lpDevMode);
if Result then
begin
lpDevMode.dmFields := DM_PELSWIDTH Or DM_PELSHEIGHT;
lpDevMode.dmPelsWidth := X;
lpDevMode.dmPelsHeight := Y;
Result := ChangeDisplaySettings(lpDevMode, 0) = DISP_CHANGE_SUCCESSFUL;
end
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if DynamicResolution(640, 480) then

ShowMessage('Now is 640*480');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if DynamicResolution(800, 600) then
ShowMessage('Now is 800*600');
end;
/////////////////////////////////////
{Delphi 引入的定义是错误的,必须手工引入}
function ChangeDisplaySettings(lpDevMode: PDeviceMode;
dwFlags: DWORD): Longint; stdcall;

var
Form1: TForm1;
DevModeArray: TList; // 显示模式信息结构列表

implementation

uses Math;
{$R *.DFM}

{引入函数}
function ChangeDisplaySettings; external user32 name 'ChangeDisplaySettingsA';

procedure TForm1.FormCreate(Sender: TObject);
var
DevModeCount: Integer; // tracks the number of display modes
DevModeInfo: ^TDevMode; // a pointer to display mode information
begin
DevModeArray := TList.Create;

DevModeCount := 0;

GetMem(DevModeInfo, SizeOf(TDevMode));

{枚举显示模式}
while EnumDisplaySettings(NIL, DevModeCount, DevModeInfo^) do
begin
DevModeArray.Add(DevModeInfo);

Inc(DevModeCount);

ListBox1.Items.Add(IntToStr(DevModeInfo^.dmPelsWidth)+'x'+
IntToStr(DevModeInfo^.dmPelsHeight)+', '+
IntToStr(Trunc(IntPower(2, DevModeInfo^.dmBitsPerPel)))+
' colors');

GetMem(DevModeInfo, SizeOf(TDevMode));
end;

FreeMem(DevModeInfo, SizeOf(TDevMode));

ListBox1.ItemIndex := 0;
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
iCount: Integer;
begin
for iCount := 0 to DevModeArray.Count-1 do
FreeMem(DevModeArray.Items[iCount], SizeOf(TDevMode));
DevModeArray.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
ModeChange: Longint; //表明是否需要重起
begin
{change the display mode}
ModeChange:=ChangeDisplaySettings(DevModeArray[ListBox1.ItemIndex],
CDS_UPDATEREGISTRY);

{可否动态改变分辨率}
if ModeChange=DISP_CHANGE_SUCCESSFUL then
ShowMessage('动态改变成功');
if ModeChange=DISP_CHANGE_RESTART then
ShowMessage('需要重起');
end;
zhangheaaa 2004-11-04
  • 打赏
  • 举报
回复
要得到显示器的分辨率,由下列程序得到:
var
x:longint;
a:string;
begin
x := GetSystemMetrics(SM_CXSCREEN);
Str(x,a);
Label1.Caption := '显示器水平分辨率' + a;
x := GetSystemMetrics(SM_CYSCREEN);
Str(x,a);
Label2.Caption := '显示器垂直分辨率' + a;
end;
ksaiy 2004-11-04
  • 打赏
  • 举报
回复
function Resolution(X,Y:word):boolean;
var
DevMode:TDeviceMode;
begin
Result:=EnumDisplaySettings(nil,0,DevMode);
if Result then
begin
DevMode.dmFields:=DM_PELSWIDTH Or DM_PELSHEIGHT;
DevMode.dmPelsWidth:=X;
DevMode.dmPelsHeight:=Y;
Result:=ChangeDisplaySettings(DevMode,0)=DISP_CHANGE_SUCCESSFUL;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if Resolution(800,600) then ShowMessage('800×600模式!');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if Resolution(1280,1024) then ShowMessage('1280X1024模式!');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if Resolution(1024,768) then ShowMessage('1024X768模式!');
end;
相关推荐
发帖
Windows SDK/API

1177

社区成员

Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
帖子事件
创建了帖子
2004-11-04 04:14
社区公告
暂无公告