在窗体上画一个按钮和四个文本框,运行如下代码:启动时,显示相应数据。修改后,单击按钮改变设置。
- OptionExplicit
- PrivateDeclareFunctionGetDeviceCapsLib@H_301_30@"gdi32"(ByValhdcAsLong,ByValnIndexAsLong)AsLong
- PrivateDeclareFunctionChangeDisplaySettingsLib@H_301_30@"user32"Alias@H_301_30@"ChangeDisplaySettingsA"(lpDevModeAsAny,ByValdwflagsAsLong)AsLong
- PrivateConstCCDEVICENAMEAsLong=32
- PrivateConstCCFORMNAMEAsLong=32
- PrivateConstDM_BITSPERPELAsLong=&H40000
- PrivateConstDM_PELSWIDTHAsLong=&H80000
- PrivateConstDM_PELSHEIGHTAsLong=&H100000
- PrivateConstDM_DISPLAYFLAGSAsLong=&H200000
- PrivateConstDM_DISPLAYFREQUENCY=&H400000
- PrivateConstCDS_FORCEAsLong=&H80000000
- PrivateConstBITSPIXELAsLong=12
- PrivateConstHORZRESAsLong=8
- PrivateConstVERTRESAsLong=10
- PrivateConstVREFRESH=116
- PrivateTypeDEVMODE
- dmDeviceNameAsString*CCDEVICENAME
- dmSpecVersionAsInteger
- dmDriverVersionAsInteger
- dmSizeAsInteger
- dmDriverExtraAsInteger
- dmFieldsAsLong
- dmOrientationAsInteger
- dmPaperSizeAsInteger
- dmPaperLengthAsInteger
- dmPaperWidthAsInteger
- dmScaleAsInteger
- dmCopiesAsInteger
- dmDefaultSourceAsInteger
- dmPrintQualityAsInteger
- dmColorAsInteger
- dmDuplexAsInteger
- dmYResolutionAsInteger
- dmTTOptionAsInteger
- dmCollateAsInteger
- dmFormNameAsString*CCFORMNAME
- dmUnusedPaddingAsInteger
- dmBitsPerPelAsInteger
- dmPelsWidthAsLong
- dmPelsHeightAsLong
- dmDisplayFlagsAsLong
- dmDisplayFrequencyAsLong
- EndType
- PrivateSubcommand1_Click()
- DimDMAsDEVMODE
- WithDM
- .dmPelsWidth=CInt(Text1.Text)
- .dmPelsHeight=CInt(Text2.Text)
- .dmBitsPerPel=CInt(Text3.Text)
- .dmDisplayFrequency=CInt(Text4.Text)
- .dmFields=DM_PELSWIDTHOrDM_PELSHEIGHTOrDM_BITSPERPELOrDM_DISPLAYFREQUENCY
- .dmSize=LenB(DM)
- EndWith
- IfChangeDisplaySettings(DM,CDS_FORCE)<>0Then
- MsgBox@H_301_30@"错误!不支持此模式!"
- EndIf
- EndSub
- PrivateSubForm_Load()
- Text1.Text=GetDeviceCaps(Me.hdc,HORZRES)
- Text2.Text=GetDeviceCaps(Me.hdc,VERTRES)
- Text3.Text=GetDeviceCaps(Me.hdc,BITSPIXEL)
- Text4.Text=GetDeviceCaps(Me.hdc,VREFRESH)
- EndSub