library setscn;
uses Windows;
var NewDevMode: TDEVMODE;
function setdisplaymode(pwidth,pheight:integer):
longint;stdcall;export;
begin
With NewDevMode do
begin
dmSize := 122;
dmFields := DM_PELSWIDTH Or DM_PELSHEIGHT ;
dmPelsWidth := pwidth ;
dmPelsHeight := pheight ;
end;
result:=ChangeDisplaySettings(NewDevMode,0);
end;
Function getscreenwidth():longint;stdcall;export;
begin
result:=GetDeviceCaps(hinstance, HORZRES);
end;
function getscreenheight():longint;stdcall;export;
begin
result:=GetDeviceCaps(hinstance, VERTSIZE);
end;
exports
setdisplaymode index 1,
getscreenwidth index 2,
getscreenheight index 3;
begin
end.
---- 编译以上代码,生成一个名为setscn.dll的动态连接库,将其拷贝到windows的system目录下,便大功告成。
---- 二、为setscn创建引入程序单元
---- 为了在Delphi语言中成功调用上述函数,我们需要编写以下引入程序单元。
{Import unit for setscn.Dll}
unit scnimport;
interface
function setdisplaymode(pwidth,pheight:integer):longint;
function getscreenwidth():longint;
function getscreenheight():longint;
implementation
function setdisplaymode(pwidth,pheight:integer):longint;
external 'setscn' index 1;
function getscreenwidth():longint;external 'setscn' index 2;
function getscreenheight():longint;external 'setscn' index 3;
end.
---- 三、不同语言中的声明及调用:
---- 1、 VB中声明及调用:
---- VB中声明:
Private Declare Function setdisplaymode Lib
"setscn.dll" (ByVal pwidth As Integer, ByVal
pheight As Integer) As Long
Private Declare Function getscreenwidth Lib
"setscn.dll" () As Long
Private Declare Function getscreenheight Lib
"setscn.dll" () As Long
Dim sh, sw As Long
---- 调用示例:点击Command1将屏幕分辩率设为640*480,点击Command2恢复原来设置。
Private Sub Command1_Click()
sw = getscreenwidth()
sh = getscreenheight()
setdisplaymode 640, 480
End Sub
Private Sub Command2_Click()
setdisplaymode sw, sh
End Sub
---- 2、PB中声明及调用:
---- PB中声明:
Public Function long setdisplaymode(long pwidth,
long pheight)Library " setscn.dll"
Public Function long getscreenwidth()Library
" setscn.dll"
Public Function long getscreenheight()Library
" setscn.dll"
---- 调用示例:点击cb_1将屏幕分辩率设为640*480,点击cb_2恢复原来设置。如下:
//clicked for cb_1 return long
//sw、sh是long型的全程变量
sw=getscreenwidth()
sh=getscreenheight()
setdisplaymode(640,480)
//clicked for cb_2 return long
setdisplaymode(sw,sh)
---- 3、Delphi中的声名及调用
---- 因为我们为setscn创建引入程序单元scnimport.pas,所以只要在uses子句后添加上scnimport,即可直接调用(源代码略)。