说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

调整分辩率和取当前分辩率 -VB资料

HTML文档下载 WORD文档下载 PDF文档下载
调整分辩率和取当前分辩率 -VB资料
怎样得到当前的屏幕分辨率?

在程序设计中我们经常要改变窗体的大小,而这也依赖于屏幕的分辨率,下面的例子将演示如何得到当前屏幕的分辨率:

ResWidth = Screen.Width \ Screen.TwipsPerPixelX

ResHeight = Screen.Height \ Screen.TwipsPerPixelY

ScreenRes = ResWidth & "x" & ResHeight

ResWidth和ResHeight分别表示屏幕的宽和高,比如这样的结果:

800x600


--------------------------------------------------------------------------------

如何改变屏幕的分辨率?

 

对于很多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
借助API Telegram能否成为第二个WhatsApp 机器学习也感性:90后软妹纸的编程之路 为安防与视频监控而生 西数紫盘首发 秘闻:鲍尔默离职,或与坚持收购诺基亚有关 【OSTC讲师专访】Thomas Yao:开源社区最缺有能力的领导者 如何开发一个CMP 关于DBExpress 修改视图的方法 [100分提问]大家帮我看一下,我这里的定义那里出错了 VB如何才能做出象QQ好友那样的界面? *.wav 的问题 各位高手...两个dataset..第二个dataset中的table比第一个中的多两个字段,,我想把第一个里面的table拷贝到第二个dataset上面的table[0]上 类设计中异常处理的考虑,请有经验的前辈说说看法 win98下运行边锋花屏的难题! 如何在WebRequest中模拟表单提交? (a-b)5次方除以(b-a)的3次方同底数幂的除 72*23+17*72-12*72*4简便运算怎么 17×23+82×23+23 简便计算 小学的! 急求简便计算(四年级下册)28*225-2*225 [-105又6分之5]乘12=?怎么算, 从31到39横竖者都等于105怎么算 105×105等于几 秒答 计算:(-b/a)^2除以(-a/b^2)的三次方 (A-B)的n次方除以A的n次方怎么计算 日三万兵集结冲绳 实弹演练夺岛英拟对外国购房者增税补赤字斯诺登愿赴德助查“监听门”(图)人类音乐史获推进:河南贾湖遗址再现8日媒:亚洲的战争与和平取决于中国如何一辆车到底是不是好车?还得看这4点参对于全球首届微商节的几种猜测!非农欠佳不敌薪资失业率改善,美指急升误违章扣6分罚钱无需担忧,用1招就能【过年遇说乡村事】之一:美丽乡村知多翼世界娱乐圈贵女灵异手札主宰两界大帝仙二十四桥旅游熙春台旅游五亭桥旅游小金山旅游徐园旅游
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘