For Windows platforms, the number of display Resolution and color is important, especially for multimedia applications and games. But in many cases, users do not fit the current screen to set the software needed for the operation. Software usual practice is to prompt the user to set the screen to the software requirements of the Resolution and the number of colors, and then restart the software. This will undoubtedly increase the burden on ordinary users and difficult operation, reducing the software-friendliness and ease of use.
---- Ideally: the beginning of the software, to dynamically change screen settings to meet the requirements of the software is running. After running the software, then automatically changes the screen to set the value back to the original settings. All these processes are completed in unknowingly. This approach can be called by the VB API (application program interface) functions do. Achieved as follows:
---- 1, open a standard EXE project.
---- Second, in the "Project" under the menu bar, select "Add Module", add a module for the project.
---- And add the following code in the module:
'--------------- The following code to get the screen to set parameters --------------
Declare Function GetDeviceCaps Lib
"Gdi32" (ByVal hdc As Long,
ByVal nIndex As Long) As Long
'API function taking the specified device information
Public Const HORZRES = 8
'Three screens constants
Public Const VHORZRES = 10
Public Const BITSPIXEL = 12
'--------------- Through the character data type conversion COPY --------------
Private Declare Function lstrcpy Lib "kernel32"
Alias "lstrcpyA" (lpString1 As Any, lpString2 As Any) As Long
'------------------ The following structure for the screen initialization -----------------
Const CCHDEVICENAME = 32
Const CCHFORMNAME = 32
Private Type DEVMODE
dmDeviceName As String backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6 -tar.gz xml2dict-read-only 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 backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6 -tar.gz xml2dict-read-only CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
'------------------ Settings screen core API -----------------
Private Declare Function ChangeDisplaySettings
Lib "User32" Alias "ChangeDisplaySettingsA"
(ByVal lpDevMode As Long, ByVal dwflags As Long) As Long
'------------------ Settings screen function -----------------
Public Function SetDispMode (Width As Integer,
Height As Integer, Color As Integer) As Long
(SetDispMode constructed their own set of functions to change the screen,
Its three parameters Width, Height, and Color are the horizontal screen resolution
Vertical resolution, color bits, so its value can be 24,16,0. 0 is the original color settings. )
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 = 0 Then
'If Color = 0 only change the screen resolution, without changing color.
. DmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
Else
'If the Color range from 0 to change the screen resolution and color.
. DmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
End If
. DmPelsWidth = Width
. DmPelsHeight = Height
If Color <> 0 Then
. DmBitsPerPel = Color
End If
End With
pDevmode = lstrcpy (NewDevMode, NewDevMode)
'Get a pointer to the structure of the Long NewDevMode type of pointer.
ChangeDisplaySettings pDevmode, 0
End Function
---- 3, in the project form, add two buttons Command1 and Command2, the Caption property were "800x600x16" and "restore the original settings."
---- The code is:
'Window "General | Statement" area
Option Explicit
Dim H, V, Color As Long
'Reputation variable, the initial screen to save the settings
Private Sub Form_Load ()
'--------------- The following code to get the initial screen equipment --------------
H = GetDeviceCaps (Form1.hdc, HORZRES)
V = GetDeviceCaps (Form1.hdc, VHORZRES)
Color = GetDeviceCaps (Form1.hdc, BITSPIXEL)
End Sub
Private Sub Command1_Click ()
'Call function to change the screen settings SetDispMode
SetDispMode 800, 600, 16
End Sub
Private Sub Command2_Click ()
'To restore the original settings screen
SetDispMode Cint (H), Cint (V), Cint (Color)
End Sub
---- 4, will compile the implementation.
---- After the execution of this program, if you click Command1, then your computer screen display mode will be set to "800x600x16" display mode; If you click Command2, then your computer screen display mode will be set to the original display mode. This procedure slightly modified, can be placed on the desktop or taskbar, quick changes directly to the screen settings.
Recommended links:
Infomation Dictionaries EducationBritain invented the robot can be SWALLOWED pills belly detection of cancerVOB to MPGRuntime Error 1714 Fix It NowJobs: Find A Good Quality Of The Work Of Eight MajorRouting Protocol RIP Routing Basics Introduction to note (2)VOB To WMVFreeBSD Serial (64): NetBIOS name resolutionHot Search Or Lookup ToolsTeach You A Maliciously Modify The Registry WoesDreamweaverMX Build Guestbook (4)IDS classification (1)Wizard XML Or CSS ToolsUT Starcom orders by the Indian IPTV operatorReport Calculators And ConvertersMTS To MOV