VB改变屏幕分辨率
我在网上搜到的代码,环境XPSP2,测试可以。但是当程序关闭时,分辨率又变回来了。我需要永久性的改变分辨率,而不是当程序运行时改变分辨率。代码如下:OptionExpli...
我在网上搜到的代码,环境XP SP2,测试可以。但是当程序关闭时,分辨率又变回来了。我需要永久性的改变分辨率,而不是当程序运行时改变分辨率。代码如下:
Option Explicit
Public Declare Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA" (ByRef lpDevMode As DEVMODE, ByVal dwFlags As Long) As Long
Public Declare Function EnumDisplaySettings Lib "user32.dll" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As String, ByVal iModeNum As Long, ByRef lpDevMode As DEVMODE) As Long
Const DM_PELSHEIGHT As Long = &H100000
Const DM_PEDTH As Long = &H80000
Const DM_BITSPERPEL As Long = &H40000
Const DM_DISPLAYFREQUENCY As Long = &H400000
Const CCHDEVICENAME As Long = 32
Const CCHFORMNAME As Long = 32
Const CDS_TEST = &H4
Private Type DEVMODE
dmDeviceName As String * CCHDEVICENAME
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 * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPedth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
'-------------------------------------------------------------------------------------------
' LngWidth //屏幕的宽(单位象素)
' LngHeight //屏幕的高(单位象素)
' IntColor //多少位颜色(e.g 16 or 32)
' LngFrequency //屏幕的刷新频率
'
'声明:
' 调用该函数时要确定所设置的值在系统所允许的设置范围内,比如系统的最大刷新频率位80,而你
' 用把LngFrequency设位85,这样将带来无法预测的后果。
'------------------------------------------------------------------------------------------Public Function SetDisplaymode(LngWidth As Long, LngHeight As Long, IntColor As Integer, LngFrequency As Long) As Long
Dim NewDevmode As DEVMODE
Dim lngP As Long
EnumDisplaySettings 0&, 0&, NewDevmode
With NewDevmode
.dmFields = DM_PELSHEIGHT Or DM_PEDTH Or DM_BITSPERPEL Or DM_DISPLAYFREQUENCY
.dmPedth = LngWidth
.dmPelsHeight = LngHeight
.dmBitsPerPel = IntColor
.dmDisplayFrequency = LngFrequency
End With
SetDisplaymode = ChangeDisplaySettings(NewDevmode, CDS_TEST)
End Function
看清楚问题,需要:关闭程序不恢复到原来的分辨率。 展开
Option Explicit
Public Declare Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA" (ByRef lpDevMode As DEVMODE, ByVal dwFlags As Long) As Long
Public Declare Function EnumDisplaySettings Lib "user32.dll" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As String, ByVal iModeNum As Long, ByRef lpDevMode As DEVMODE) As Long
Const DM_PELSHEIGHT As Long = &H100000
Const DM_PEDTH As Long = &H80000
Const DM_BITSPERPEL As Long = &H40000
Const DM_DISPLAYFREQUENCY As Long = &H400000
Const CCHDEVICENAME As Long = 32
Const CCHFORMNAME As Long = 32
Const CDS_TEST = &H4
Private Type DEVMODE
dmDeviceName As String * CCHDEVICENAME
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 * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPedth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
'-------------------------------------------------------------------------------------------
' LngWidth //屏幕的宽(单位象素)
' LngHeight //屏幕的高(单位象素)
' IntColor //多少位颜色(e.g 16 or 32)
' LngFrequency //屏幕的刷新频率
'
'声明:
' 调用该函数时要确定所设置的值在系统所允许的设置范围内,比如系统的最大刷新频率位80,而你
' 用把LngFrequency设位85,这样将带来无法预测的后果。
'------------------------------------------------------------------------------------------Public Function SetDisplaymode(LngWidth As Long, LngHeight As Long, IntColor As Integer, LngFrequency As Long) As Long
Dim NewDevmode As DEVMODE
Dim lngP As Long
EnumDisplaySettings 0&, 0&, NewDevmode
With NewDevmode
.dmFields = DM_PELSHEIGHT Or DM_PEDTH Or DM_BITSPERPEL Or DM_DISPLAYFREQUENCY
.dmPedth = LngWidth
.dmPelsHeight = LngHeight
.dmBitsPerPel = IntColor
.dmDisplayFrequency = LngFrequency
End With
SetDisplaymode = ChangeDisplaySettings(NewDevmode, CDS_TEST)
End Function
看清楚问题,需要:关闭程序不恢复到原来的分辨率。 展开
1个回答
展开全部
东莞大凡
2024-11-14 广告
2024-11-14 广告
标定板认准大凡光学科技,专业生产研发厂家,专业从事光学影像测量仪,光学投影测量仪.光学三维测量仪,光学二维测量仪,光学二维测量仪,光学三维测量仪,光学二维测量仪.的研发生产销售。东莞市大凡光学科技有限公司创立于 2018 年,公司总部坐落于...
点击进入详情页
本回答由东莞大凡提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询