screen resolution

wild wolf
11-19-2001, 12:35 AM
is it possible to set the resolution of a system when a form loads for example the system resolution is 1024 by 768 and my game runs on 800 by 600, so i would like to set the resolution to 800 by 600 automatically once the form loads ?

Flyguy
11-19-2001, 02:02 AM
Yes, it is possible.

If you create your game to run in a "window" form it will be very anoying for users it the resolution is changed.

If you are making your game to run with DirectX just switch to Fullscreen and change to resolution.

So if you run in a window DON'T change the resolution, if its running in fullscreen do.
You could also make this an option to the user, whether to run it in a window or fullscreen.

wild wolf
11-19-2001, 02:22 AM
the game does run in full screen mode, iam not using DirectX, once teh form loads it will switch the resolution to 800 by 600 and once the form exits, it will switch back to the original, i have seen people do that but never got the chance to ask

Flyguy
11-19-2001, 02:36 AM
Have a look at www.planet-source-code.com (http://www.planet-source-code.com) I think you can find there some example code.

But I still think you should not change to resolution of the normal scren ... , just my opinion

wild wolf
11-19-2001, 03:00 AM
the reason why iam changing the resolution is because my game is set to 800 by 600 size and is set to full screen and so if the user runs it on 1024 by 768 then u will see some unwanted parts of the game, i tried the following code


if screen.height > 600 then
screen.height = 600
end if
if screen.width > 800 then
screen.width = 800
end if

but it gives me a compile error saying cannot modify as it is read only mode, i have already searched the url u gave me but without success

Flyguy
11-19-2001, 03:06 AM
Here some code I found, it assumes you have a List1 (listbox) and a Command1 (commandbutton)
<pre>
Option Explicit

' ChangRez sample by Matt Hart'
'
' How to change video resolution in Windows 95.
' The WinSDK API declarations for VB does NOT include
' this useful procedure, nor does it include some
' of the needed constants. I had to figure out the API
' declaration and go to the Platform SDK
' find most of the constants.

Const CCHDEVICENAME = 32
Const CCHFORMNAME = 32

Private Type DEVMODE
dmDeviceName As String * 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 * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type

Const DM_BITSPERPEL = &amp;H40000
Const DM_PELSWIDTH = &amp;H80000
Const DM_PELSHEIGHT = &amp;H100000
Const DM_DISPLAYFLAGS = &amp;H200000
Const DM_DISPLAYFREQUENCY = &amp;H400000

Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpInitData As DEVMODE, ByVal dwFlags As Long) As Long
Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (lpszDeviceName As Any, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long

Const BITSPIXEL = 12

' /* Flags for ChangeDisplaySettings */
Const CDS_UPDATEREGISTRY = &amp;H1
Const CDS_TEST = &amp;H2
Const CDS_FULLSCREEN = &amp;H4
Const CDS_GLOBAL = &amp;H8
Const CDS_SET_PRIMARY = &amp;H10
Const CDS_RESET = &amp;H40000000
Const CDS_SETRECT = &amp;H20000000
Const CDS_NORESET = &amp;H10000000

' /* Return values for ChangeDisplaySettings */
Const DISP_CHANGE_SUCCESSFUL = 0
Const DISP_CHANGE_RESTART = 1
Const DISP_CHANGE_FAILED = -1
Const DISP_CHANGE_BADMODE = -2
Const DISP_CHANGE_NOTUPDATED = -3
Const DISP_CHANGE_BADFLAGS = -4
Const DISP_CHANGE_BADPARAM = -5

Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4

Dim D() As DEVMODE, lNumModes As Long

Private Sub Command1_Click()
Dim l As Long, Flags As Long, x As Long
x = List1.ListIndex
D(x).dmFields = DM_BITSPERPEL Or DM_PELSWIDTH Or DM_PELSHEIGHT
Flags = CDS_UPDATEREGISTRY
l = ChangeDisplaySettings(D(x), Flags)
Select Case l
Case DISP_CHANGE_RESTART
l = MsgBox("This change will not take effect until you reboot the system. Reboot now?", vbYesNo)
If l = vbYes Then
Flags = 0
l = ExitWindowsEx(EWX_REBOOT, Flags)
End If
Case DISP_CHANGE_SUCCESSFUL
Case Else
MsgBox "Error changing resolution! Returned: " &amp; l
End Select
End Sub

Private Sub Form_Load()
Dim l As Long, lMaxModes As Long
Dim lBits As Long, lWidth As Long, lHeight As Long
lBits = GetDeviceCaps(hdc, BITSPIXEL)
lWidth = Screen.Width \ Screen.TwipsPerPixelX
lHeight = Screen.Height \ Screen.TwipsPerPixelY
lMaxModes = 8
ReDim D(0 To lMaxModes) As DEVMODE
lNumModes = 0
l = EnumDisplaySettings(ByVal 0, lNumModes, D(lNumModes))
Do While l
List1.AddItem D(lNumModes).dmPelsWidth &amp; "x" &amp; D(lNumModes).dmPelsHeight &amp; "x" &amp; D(lNumModes).dmBitsPerPel
If lBits = D(lNumModes).dmBitsPerPel And _
lWidth = D(lNumModes).dmPelsWidth And _
lHeight = D(lNumModes).dmPelsHeight Then
List1.ListIndex = List1.NewIndex
End If
lNumModes = lNumModes + 1
If lNumModes &gt; lMaxModes Then
lMaxModes = lMaxModes + 8
ReDim Preserve D(0 To lMaxModes) As DEVMODE
End If
l = EnumDisplaySettings(ByVal 0, lNumModes, D(lNumModes))
Loop
lNumModes = lNumModes - 1
End Sub
</pre>

wild wolf
11-22-2001, 07:20 PM
quite complicated buddy, din understand and dun have a slightest idea whats goin on, nvm, i am presenting my game today so i guess ill switch to the manual way, thanx anyway but i still would like to learn how it works, so maybe u could explain the code abit

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum