拷贝下面的代码<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> { Private declarations }<br> public<br> swidth,sheight:integer;<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br><br>function DynamicResolution(X, Y: word): BOOL;var lpDevMode: TDeviceMode;begin<br> Result := EnumDisplaySettings(nil, 0, lpDevMode); if Result then begin<br> lpDevMode.dmFields := DM_PELSWIDTH Or DM_PELSHEIGHT;<br> lpDevMode.dmPelsWidth := X; lpDevMode.dmPelsHeight := Y;<br> Result := ChangeDisplaySettings(lpDevMode, 0) = DISP_CHANGE_SUCCESSFUL;<br>end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>//if DynamicResolution(640, 480) then ShowMessage('Now is 640*480');<br>DynamicResolution(640, 480)<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>//if DynamicResolution(800, 600) then ShowMessage('Now is 800*600');<br>DynamicResolution(800, 600)<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>swidth:=screen.width;<br>sheight:=screen.height;<br><br>if (screen.width<>800) and (screen.height<>600) then<br>DynamicResolution(800,600);<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>DynamicResolution(swidth, sheight);<br>end;<br><br>end.