|
-
Sep 19th, 2004, 08:33 AM
#1
Thread Starter
New Member
Question about Resolution
Um.... I'm kind of new here to Visual Basic, and I was wondering, how do you change the resolution in Visual Basic?
Say, if i wanted to change the resolution to 640*480, how would I do that? Do I need some kind of DirectX function?
Please help, thanks
-
Sep 19th, 2004, 10:01 AM
#2
-
Sep 22nd, 2004, 07:32 PM
#3
Thread Starter
New Member
Post an example?
Can you post an example, please? Sorry, I'm quite new to VB, so I'm not really sure how that code works.
So If you have the time, could you post a small example showing how to change the resolution, please?
-
Sep 22nd, 2004, 07:47 PM
#4
Fanatic Member
You're going to have to put a command button on form.
VB Code:
Option Explicit
Private Const CCDEVICENAME = 32
Private Const CCFORMNAME = 32
Private Const DISP_CHANGE_SUCCESSFUL = 0
Private Const DISP_CHANGE_RESTART = 1
Private Const DISP_CHANGE_FAILED = -1
Private Const DISP_CHANGE_BADMODE = -2
Private Const DISP_CHANGE_NOTUPDATED = -3
Private Const DISP_CHANGE_BADFLAGS = -4
Private Const DISP_CHANGE_BADPARAM = -5
Private Const CDS_UPDATEREGISTRY = &H1
Private Const CDS_TEST = &H2
Private Const DM_BITSPERPEL = &H40000
Private Const DM_PELSWIDTH = &H80000
Private Const DM_PELSHEIGHT = &H100000
Private 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
Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags As Long) As Long
Function ChangeScreenSettings(lWidth As Integer, lHeight As Integer, lColors As Integer)
Dim tDevMode As DEVMODE, lTemp As Long, lIndex As Long
' Declare variables
lIndex = 0
Do
'Instilise Do loop
lTemp = EnumDisplaySettings(0&, lIndex, tDevMode)
' Call the APi function
If lTemp = 0 Then Exit Do
' If there is no more data or an erro occurs
' then return 0 and exit do
lIndex = lIndex + 1
' Increase the index to be enumerated
With tDevMode
If .dmPelsWidth = lWidth And .dmPelsHeight = lHeight And .dmBitsPerPel = lColors Then
lTemp = ChangeDisplaySettings(tDevMode, CDS_UPDATEREGISTRY)
Exit Do
End If
End With
' Set the new data
' Change the display type. This depends on the paramter used
' It can either be:
' 0 - Dynamic change if possible
' CDS_UPDATEREGISTRY - Dynamically change if possible
' and if not possibel then update registry for change
' on the next boot-up
' CDS_TEST - Test the new settings
Loop
End Function
Private Sub Command1_Click()
ChangeScreenSettings 800, 600, 16
End Sub
"X-mas is 24.Desember you English morons.." - NoteMe
-
Sep 22nd, 2004, 07:51 PM
#5
Here is the code, made clearer and commented "better":
VB Code:
'add into a module
Option Explicit
Private Const CCDEVICENAME = 32
Private Const CCFORMNAME = 32
Private Const DISP_CHANGE_SUCCESSFUL = 0
Private Const DISP_CHANGE_RESTART = 1
Private Const DISP_CHANGE_FAILED = -1
Private Const DISP_CHANGE_BADMODE = -2
Private Const DISP_CHANGE_NOTUPDATED = -3
Private Const DISP_CHANGE_BADFLAGS = -4
Private Const DISP_CHANGE_BADPARAM = -5
Private Const CDS_UPDATEREGISTRY = &H1
Private Const CDS_TEST = &H2
Private Const DM_BITSPERPEL = &H40000
Private Const DM_PELSWIDTH = &H80000
Private Const DM_PELSHEIGHT = &H100000
Private 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
Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags As Long) As Long
'this function returns true if it was able to change the resolution
'usage: ChangeScreenSettings 800, 600, 32
'will set resolution to 800 x 600 at 32-bit colors
Public Function ChangeScreenSettings(lWidth As Integer, lHeight As Integer, lColors As Integer) As Boolean
Dim tDevMode As DEVMODE, lTemp As Long, lIndex As Long
'start from the first setting
lIndex = 0
'loop until a matching resolution setting is found
Do
'call API: get settings to tDevMode
lTemp = EnumDisplaySettings(0&, lIndex, tDevMode)
'no more data, exit loop
If lTemp = 0 Then Exit Do
'increase index
lIndex = lIndex + 1
With tDevMode
'check if width, height and amount of colors match
If .dmPelsWidth = lWidth And .dmPelsHeight = lHeight And .dmBitsPerPel = lColors Then
'change the resolution to the demanded one as we found a matching setting
lTemp = ChangeDisplaySettings(tDevMode, CDS_UPDATEREGISTRY)
'we were able to set the demanded resolution!
ChangeScreenSettings = True
Exit Do
End If
End With
Loop
End Function
Then you can make a command button to a form and add following code:
VB Code:
Private Sub Command1_Click()
If Not ChangeScreenSettings(800, 600, 32) Then
MsgBox "Failed to change resolution"
End If
End Sub
Hope this helps
-
Sep 23rd, 2004, 06:29 PM
#6
Thread Starter
New Member
OMG
Wow... You are my life saver! Thank you sooooooo much!
That's so cool!
Thanks.
-
Sep 25th, 2004, 12:06 PM
#7
Thread Starter
New Member
umm...
One, more question...
Sorry to bother you, but how do you change it back to the default resolution that the person had before?
-
Sep 25th, 2004, 12:10 PM
#8
Hmm... in the loop, look for the current resolution setting also. So first you loop looking for current resolution and the resolution to change to, and then loop is done (both settings found) then change the resolution and return the old resolution index number as the function return value.
Complex?
-
Sep 28th, 2004, 03:48 PM
#9
Thread Starter
New Member
Sorry....
I'm a very "Weak" programmer in Visual Basic, so can you give me an example of how to do that, that would really help me out.
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|