QQRead:http://www.qqread.com/vb/c257393.html
Changing the screen resolution
A big problem for many vb-programmers is how to change the screen resolution, also because in the Api-viewer the variable for EnumDisplaySettings and ChangeDisplaySettings is missing!
1. Code for the basic-module
Declare Function EnumDisplaySettings Lib "user32" _
Alias "EnumDisplaySettingsA" _
(ByVal lpszDeviceName As Long, _
ByVal iModeNum As Long, _
lpDevMode As Any) As BooleanDeclare 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 LongPublic 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 = 1Type 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 TypeExample
Changes the resolution to 640x480 with the current colordepth.
Dim DevM As DEVMODE
注释:Get the info into DevM
erg& = EnumDisplaySettings(0&, 0&, DevM)
注释:We don注释:t change the colordepth, because a
注释:rebot will be necessary
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT 注释:Or DM_BITSPERPEL
DevM.dmPelsWidth = 640 注释:ScreenWidth
DevM.dmPelsHeight = 480 注释:ScreenHeight
注释:DevM.dmBitsPerPel = 32 (could be 8, 16, 32 or even 4)
注释:Now change the display and check if possibleerg& = ChangeDisplaySettings(DevM, CDS_TEST)
注释:Check if succesfullSelect Case erg&
Case DISP_CHANGE_RESTART
an = MsgBox("You注释:ve to reboot", vbYesNo + vbSystemModal, "Info")
If an = vbYes Then
erg& = ExitWindowsEx(EWX_REBOOT, 0&)
End If
Case DISP_CHANGE_SUCCESSFUL
erg& = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
MsgBox "Everything注释:s ok", vbOKOnly + vbSystemModal, "It worked!"
Case Else
MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
End SelectEnd Sub进入讨论组讨论。
Changing the screen resolution
A big problem for many vb-programmers is how to change the screen resolution, also because in the Api-viewer the variable for EnumDisplaySettings and ChangeDisplaySettings is missing!
1. Code for the basic-module
Declare Function EnumDisplaySettings Lib "user32" _
Alias "EnumDisplaySettingsA" _
(ByVal lpszDeviceName As Long, _
ByVal iModeNum As Long, _
lpDevMode As Any) As BooleanDeclare 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 LongPublic 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 = 1Type 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 TypeExample
Changes the resolution to 640x480 with the current colordepth.
Dim DevM As DEVMODE
注释:Get the info into DevM
erg& = EnumDisplaySettings(0&, 0&, DevM)
注释:We don注释:t change the colordepth, because a
注释:rebot will be necessary
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT 注释:Or DM_BITSPERPEL
DevM.dmPelsWidth = 640 注释:ScreenWidth
DevM.dmPelsHeight = 480 注释:ScreenHeight
注释:DevM.dmBitsPerPel = 32 (could be 8, 16, 32 or even 4)
注释:Now change the display and check if possibleerg& = ChangeDisplaySettings(DevM, CDS_TEST)
注释:Check if succesfullSelect Case erg&
Case DISP_CHANGE_RESTART
an = MsgBox("You注释:ve to reboot", vbYesNo + vbSystemModal, "Info")
If an = vbYes Then
erg& = ExitWindowsEx(EWX_REBOOT, 0&)
End If
Case DISP_CHANGE_SUCCESSFUL
erg& = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
MsgBox "Everything注释:s ok", vbOKOnly + vbSystemModal, "It worked!"
Case Else
MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
End SelectEnd Sub进入讨论组讨论。
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- VB+Access设计图书管理系统 (104238次浏览)
- VB设计有语音报时和报警功能的闹钟 (13528次浏览)
- 用VB打造“超酷”个性化菜单 (667次浏览)
- VB基础学习:编码规范 (654次浏览)
- 对注册表进行编程的“捷径” (646次浏览)
- 在IIS中建立WEB站点的例子! (603次浏览)
- 用VB6.0设计简易赛车游戏 (414次浏览)
- 导入注册表设置 (308次浏览)
- 用Visual Basic.NET编写扑克牌游戏 (189次浏览)
- VB急速密码生成---RndString (188次浏览)



