玩酷之家

 找回密码
 立即注册
查看: 62|回复: 0

VB 获取和修改屏幕分辨率与刷新频率?

[复制链接]
发表于 2021-1-8 16:53:09 | 显示全部楼层 |阅读模式
在窗体上画一个按钮和四个文本框,运行如下代码:启动时,显示相应数据。修改后,单击按钮改变设置。

  1. Option Explicit
  2. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
  3. Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags As Long) As Long
  4. Private Const CCDEVICENAME As Long = 32
  5. Private Const CCFORMNAME As Long = 32

  6. Private Const DM_BITSPERPEL As Long = &H40000
  7. Private Const DM_PELSWIDTH As Long = &H80000
  8. Private Const DM_PELSHEIGHT As Long = &H100000
  9. Private Const DM_DISPLAYFLAGS As Long = &H200000
  10. Private Const DM_DISPLAYFREQUENCY = &H400000

  11. Private Const CDS_FORCE As Long = &H80000000

  12. Private Const BITSPIXEL As Long = 12
  13. Private Const HORZRES As Long = 8
  14. Private Const VERTRES As Long = 10
  15. Private Const VREFRESH = 116

  16. Private Type DEVMODE
  17. dmDeviceName As String * CCDEVICENAME
  18. dmSpecVersion As Integer
  19. dmDriverVersion As Integer
  20. dmSize As Integer
  21. dmDriverExtra As Integer
  22. dmFields As Long
  23. dmOrientation As Integer
  24. dmPaperSize As Integer
  25. dmPaperLength As Integer
  26. dmPaperWidth As Integer
  27. dmScale As Integer
  28. dmCopies As Integer
  29. dmDefaultSource As Integer
  30. dmPrintQuality As Integer
  31. dmColor As Integer
  32. dmDuplex As Integer
  33. dmYResolution As Integer
  34. dmTTOption As Integer
  35. dmCollate As Integer
  36. dmFormName As String * CCFORMNAME
  37. dmUnusedPadding As Integer
  38. dmBitsPerPel As Integer
  39. dmPelsWidth As Long
  40. dmPelsHeight As Long
  41. dmDisplayFlags As Long
  42. dmDisplayFrequency As Long
  43. End Type

  44. Private Sub command1_Click()

  45. Dim DM As DEVMODE

  46. With DM
  47. .dmPelsWidth = CInt(Text1.Text)
  48. .dmPelsHeight = CInt(Text2.Text)
  49. .dmBitsPerPel = CInt(Text3.Text)
  50. .dmDisplayFrequency = CInt(Text4.Text)
  51. .dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL Or DM_DISPLAYFREQUENCY
  52. .dmSize = LenB(DM)
  53. End With

  54. If ChangeDisplaySettings(DM, CDS_FORCE) <> 0 Then

  55. MsgBox "错误!不支持此模式!"

  56. End If

  57. End Sub

  58. Private Sub Form_Load()
  59. Text1.Text = GetDeviceCaps(Me.hdc, HORZRES)
  60. Text2.Text = GetDeviceCaps(Me.hdc, VERTRES)
  61. Text3.Text = GetDeviceCaps(Me.hdc, BITSPIXEL)
  62. Text4.Text = GetDeviceCaps(Me.hdc, VREFRESH)
  63. End Sub
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|玩酷之家 ( 鄂ICP备14012049号 )

GMT+8, 2021-1-25 09:23 , Processed in 1.107602 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表