主题:请教高手:怎样在程序中设置显示分辨率
qjbzjp
[专家分:8830] 发布于 2008-06-28 21:08:00
请教高手:
怎样在程序中设置显示分辨率,退出时又设置为原来的分辨率。谢谢!
回复列表 (共2个回复)
沙发
jianghongbo1 [专家分:410] 发布于 2008-06-29 10:32:00
screen.width
screen.height
twipsperpixelx
twipsperpixely
用这四个属性可以设置
分辨率为
screen.width\twipsperpixelx & "*" & screen.height\twipsperpixely
板凳
一江秋水 [专家分:9680] 发布于 2008-06-30 11:32:00
下面的代码供你参考
1.模块的代码:
Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Public Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
Public Const EWX_FORCE = 4
Public Const CCDEVICENAME = 32
Public Const CCFORMNAME = 32
Public Const DM_BITSPERPEL = &H40000
Public Const DM_PELSWIDTH = &H80000
Public Const DM_PELSHEIGHT = &H100000
Public Const CDS_UPDATEREGISTRY = &H1
Public Const CDS_TEST = &H4
Public Const DISP_CHANGE_SUCCESSFUL = 0
Public Const DISP_CHANGE_RESTART = 1
Type DEVMODE
dmDeviceName As String * CCDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
2、窗体的代码(把屏幕分辨率更改为640x480,保持原来的颜色数):
Private Sub Command1_Click()
Dim DevM As DEVMODE 'DevM收集信息
Dim erg As Long
erg& = EnumDisplaySettings(0&, 0&, DevM)
'不改变颜色数目是因为如果改变颜色数就要重新启动
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT 'Or DM_BITSPERPEL
DevM.dmPelsWidth = 1024 '屏幕宽度
DevM.dmPelsHeight = 748 '屏幕高度
'DevM.dmBitsPerPel = 32 (还可以为8,16,32甚至4)
'改变显示模式并检查是否可能
erg& = ChangeDisplaySettings(DevM, CDS_TEST) '检查是否成功
Select Case erg&
Case DISP_CHANGE_RESTART
If MsgBox("你现在必须重新启动系统,立即执行吗?", vbYesNo + vbSystemModal, "消息") = vbYes Then erg& = ExitWindowsEx(EWX_REBOOT, 0&)
Case DISP_CHANGE_SUCCESSFUL
erg& = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
MsgBox "一切正常!", vbOKOnly + vbSystemModal, "成功"
Case Else
MsgBox "显示模式不支持", vbOKOnly + vbSystemModal, "错误"
End Select
End Sub
我来回复