我的显示是1024*768我想做个程序把显示变成800*600,谁知怎么样做啊!说一下啊O
如何改变屏幕的分辨率?
对于很多VB程序员来说怎样改变屏幕的分辨率一直是一个难题,而且在API-Viewer里竟然没有EnumDisplaySettings和ChangeDisplaySettings!!遵从以下的步骤,你就可以改变屏幕的分辨率。将以下代码加入模块文件:
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(保持原来的颜色数)。
Dim DevM As DEVMODE
'DevM收集信息
erg& = EnumDisplaySettings(0&, 0&, DevM)
'不改变颜色数目是因为如果改变颜色数就要重新启动
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT 'Or DM_BITSPERPEL
DevM.dmPelsWidth = 640 '屏幕宽度
DevM.dmPelsHeight = 480 '屏幕高度
'DevM.dmBitsPerPel = 32 (还可以为 8, 16, 32甚至4)
'改变显示模式并检查是否可能
erg& = ChangeDisplaySettings(DevM, CDS_TEST)'检查是否成功 Select Case erg&
Case DISP_CHANGE_RESTART
an = MsgBox("你现在必须重新启动系统,执行吗?", vbYesNo + vbSystemModal, "消息")
If an = vbYes Then erg& = ExitWindowsEx(EWX_REBOOT, 0&)
End If
Case DISP_CHANGE_SUCCESSFUL
erg& = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
MsgBox "一切正常!", vbOKOnly + vbSystemModal, "成功"
Case Else
MsgBox "显示模式不支持", vbOKOnly + vbSystemModal, "错误"End Select
End Sub
知了