我們經常看到許多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
->