unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TfrmMain = class(TForm)
btn800600: TButton;
btn640480: TButton;
procedure btn640480Click(Sender: TObject);
procedure btn800600Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function DynamicResolution(X, Y: Word): BOOL;
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
function TfrmMain.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 TfrmMain.btn640480Click(Sender: TObject);
begin
if DynamicResolution(640, 480) then
begin
ShowMessage(’現在的分辨率是640*480’);
end;
end;
procedure TfrmMain.btn800600Click(Sender: TObject);
begin
if DynamicResolution(800, 600) then
begin
ShowMessage(’現在的分辨率是800*600’);
end;
end;
end.
保存文件,然後按F9鍵運行程序,程序運行的初始畫面如圖2所示。
在程序運行過程中,用戶可以通過單擊“800*600”和“640*480”按鈕把屏幕分辨率分別更改為“800*600”和“640*480”,如圖3所示。
圖2 程序運行的初始畫面
圖3 程序運行結果