WEB开发网
开发学院软件开发VB 动态改变屏幕设置 阅读

动态改变屏幕设置

 2006-02-27 21:13:26 来源:WEB开发网   
核心提示:我们经常看到许多Win95的应用程序(尤其是游戏)在运行它的时候改变屏幕的设置,运行完后恢复,动态改变屏幕设置,在VB中,我们可以用以下方法实现:'-定义PRivateDeclareFunctionlstrcpy_Lib"kernel32"Alias"lstrcpyA"_
我们经常看到许多Win95的应用程序(尤其是游戏)在运行它的时候改变屏幕的设置,运行完后恢复,在VB中,我们可以用以下方法实现:
'-定义
PRivateDeclareFunctionlstrcpy_
Lib"kernel32"Alias"lstrcpyA"_
(lpString1AsAny,lpString2AsAny)_
AsLong
ConstCCHDEVICENAME=32
ConstCCHFORMNAME=32
PrivateTypeDEVMODE
dmDeviceNameAsString*CCHDEVICENAME
dmSpecVersionAsInteger
dmDriverVersionAsInteger
dmSizeAsInteger
dmDriverExtraAsInteger
dmFieldsAsLong
dmOrientationAsInteger
dmPaperSizeAsInteger
dmPaperLengthAsInteger
dmPaperWidthAsInteger
dmScaleAsInteger
dmCopiesAsInteger
dmDefaultSourceAsInteger
dmPrintQualityAsInteger
dmColorAsInteger
dmDuplexAsInteger
dmYResolutionAsInteger
dmTTOptionAsInteger
dmCollateAsInteger
dmFormNameAsString*CCHFORMNAME
dmUnusedPaddingAsInteger
dmBitsPerPelAsInteger
dmPelsWidthAsLong
dmPelsHeightAsLong
dmDisplayFlagsAsLong
dmDisplayFrequencyAsLong
EndType
PrivateDeclareFunction_
ChangeDisplaySettingsLib_
"User32"Alias"ChangeDisplaySettingsA"(_
ByVallpDevModeAsLong,_
ByValdwflagsAsLong)AsLong
'-函数

PublicFunctionSetDisplayMode(WidthAs_
Integer,HeightAsInteger,ColorAs_
Integer)AsLong
ConstDM_PELSWIDTH=&H80000
ConstDM_PELSHEIGHT=&H100000
ConstDM_BITSPERPEL=&H40000
DimNewDevModeAsDEVMODE
DimpDevmodeAsLong
WithNewDevMode
.dmSize=122
IfColor=-1Then
.dmFields=DM_PELSWIDTHOrDM_PELSHEIGHT
Else
.dmFields=DM_PELSWIDTHOr_
DM_PELSHEIGHTOrDM_BITSPERPEL
EndIf
.dmPelsWidth=Width
.dmPelsHeight=Height

IfColor<>-1Then
.dmBitsPerPel=Color
EndIf
EndWith
pDevmode=lstrcpy(NewDevMode,NewDevMode)
SetDisplayMode=ChangeDisplaySettings(pDevmode,0)
EndFunction
例子调用:改变为640x480x24位:
i=SetDisplayMode(640,480,24)
如果成功返回0

->

Tags:动态 改变 屏幕

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接