获取分辨率(100分)

  • 主题发起人 主题发起人 银河
  • 开始时间 开始时间

银河

Unregistered / Unconfirmed
GUEST, unregistred user!
请问各位大侠,<br>delphi里面要调用哪个API函数来获取当前计算机的分辨率呢?[?]
 
x:=getsystemmetrics(sm_cxscreen);<br>&nbsp; y:=getsystemmetrics(sm_cyscreen);<br>
 
var <br>sx,sy:Integer; <br>begin <br>sx := GetSystemMetrics(SM_CXSCREEN); //分辨率宽 <br>sy := GetSystemMetrics(SM_CYSCREEN); //分辨率高
 
要得到显示器的分辨率,由下列程序得到:<br>var<br>x:longint;<br>a:string;<br>begin<br>x := GetSystemMetrics(SM_CXSCREEN);<br>Str(x,a);<br>Label1.Caption := '显示器水平分辨率' + a;<br>x := GetSystemMetrics(SM_CYSCREEN);<br>Str(x,a);<br>Label2.Caption := '显示器垂直分辨率' + a;<br>end;<br><br><br>&nbsp;改变分辨率<br><br>function Resolution(X,Y:word):boolean;<br>var<br>&nbsp; DevMode:TDeviceMode;<br>&nbsp; begin<br>&nbsp; &nbsp; Result:=EnumDisplaySettings(nil,0,DevMode);<br>&nbsp; &nbsp; if Result then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; DevMode.dmFields:=DM_PELSWIDTH Or DM_PELSHEIGHT;<br>&nbsp; &nbsp; &nbsp; DevMode.dmPelsWidth:=X;<br>&nbsp; &nbsp; &nbsp; DevMode.dmPelsHeight:=Y;<br>&nbsp; &nbsp; &nbsp; Result:=ChangeDisplaySettings(DevMode,0)=DISP_CHANGE_SUCCESSFUL;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; if Resolution(800,600) then ShowMessage('800×600模式!');<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; if Resolution(1280,1024) then ShowMessage('1280X1024模式!');<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>begin<br>&nbsp; if Resolution(1024,768) then ShowMessage('1024X768模式!');<br>end;
 
也可以用Screen.width/Screen.Height来取得
 
[:D]多谢多谢!<br>
 
多人接受答案了。
 
后退
顶部