動態改變螢幕設定 (轉)

gugu99發表於2008-07-18
動態改變螢幕設定 (轉)[@more@]

 

msnavigation--&gt

動態改變螢幕設定


  我們經常看到許多 Win95 的應用(尤其是遊戲)在執行它的時候改變螢幕的設定,執行完後恢復,在 中,我們可以用以下方法實現:

  文中的下劃線(_)為接上一行。
 
定義

'Vb man 2001
'URL:
'E-: coolde@21cn.com

Private Declare Function lstrcpy _
Lib "kernel32" Alias "lstrcpyA" _
(lpString1 As Any, lpString2 As Any) _
As Long
Const CCHDEVICENAME = 32
Const CCHFORMNAME = 32
Private Type DEVMODE
dmDeviceName As String * CCHDEVICENAME
dmSpecVersion As Integer
dmVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefault 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 Declare Function _
ChangeDisplaySettings Lib _
"User32" Alias "ChangeDisplaySettingsA" (_
ByVal lpDevMode As Long, _
ByVal dwflags As Long) As Long




'Vb man 2001
'URL: .net
': coolde@21cn.com

Public Function SetDisplayMode(Width As _
Integer,Height As Integer, Color As _
Integer) As Long
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const DM_BITSPERPEL = &H40000
Dim NewDevMode As DEVMODE
Dim pDevmode As Long
With NewDevMode
.dmSize = 122
If Color = -1 Then
.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
Else
.dmFields = DM_PELSWIDTH Or _
DM_PELSHEIGHT Or DM_BITSPERPEL
End If
.dmPelsWidth = Width
.dmPelsHeight = Height
 
If Color <> -1 Then
.dmBitsPerPel = Color
End If
End With
pDevmode = lstrcpy(NewDevMode, NewDevMode)
SetDisplayMode = ChangeDisplaySettings(pDevmode, 0)
End Function

例子:改變為 640x480x24位:

i = SetDisplayMode(640, 480, 24)

如果成功返回 0


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10748419/viewspace-1007452/,如需轉載,請註明出處,否則將追究法律責任。

相關文章