检查并自动调整屏幕分辨率为800x600

Option Explicit
Public oldwidth As Integer, oldheight As Integer, oldcolor As Integer, oldfreq As Long
Private Declare Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA" (ByRef lpDevMode As DEVMODE, ByVal dwFlags As Long) As Long
Private Declare Function EnumDisplaySettings Lib "user32.dll" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As String, ByVal iModeNum As Long, ByRef lpDevMode As DEVMODE) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Const ENUM_CURRENT_SETTINGS = 1
Private Const BITSPIXEL = 12

Const DM_PELSHEIGHT As Long = &H100000
Const DM_PELSWIDTH 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
Const GDC_FREQ = 116

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
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Sub Form_Activate()
   oldwidth = GetDisplayWidth
   oldheight = GetDisplayHeight
   getcolor
   getfreq
   Call initscreen
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
   If KeyAscii = 27 Then
      Unload Me
   End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
   restscreen
End Sub
Public Sub initscreen()
    Dim nwidth As Long, nheight As Long, ncolor As Integer, nfreq As Long
    nwidth = 800: nheight = 600: ncolor = 16: nfreq = 60
    Call SetDisplaymode(nwidth, nheight, ncolor, nfreq)
End Sub
Public Sub restscreen()
   Dim nwidth As Long, nheight As Long, ncolor As Integer, nfreq As Long
   nwidth = oldwidth: nheight = oldheight: ncolor = oldcolor: nfreq = oldfreq
   Call SetDisplaymode(nwidth, nheight, ncolor, nfreq)
End Sub
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_PELSWIDTH Or DM_BITSPERPEL Or DM_DISPLAYFREQUENCY
      .dmPelsWidth = LngWidth
      .dmPelsHeight = LngHeight
      .dmBitsPerPel = IntColor
      .dmDisplayFrequency = LngFrequency
   End With
   SetDisplaymode = ChangeDisplaySettings(newDevmode, CDS_TEST)
End Function
Public Function GetDisplayWidth() As Integer
   On Error Resume Next
   GetDisplayWidth = Screen.Width / Screen.TwipsPerPixelX
End Function
Public Function GetDisplayHeight() As Integer
   On Error Resume Next
   GetDisplayHeight = Screen.Height / Screen.TwipsPerPixelY
End Function
Public Function getfreq() As Integer
   On Error Resume Next
   oldfreq = GetDeviceCaps(Me.hdc, GDC_FREQ)
End Function
Public Sub getcolor()
   On Error Resume Next
   oldcolor = Format$(GetDeviceCaps(hdc, BITSPIXEL))
End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值