|
-
Oct 13th, 2006, 05:13 AM
#1
Thread Starter
Lively Member
[RESOLVED] Screen Res
How do i change a computers screen res to be 1024x768 so my graphic will fit the screen?
if possible can i change it back to what it was before the program was opened when it is exited?
-
Oct 13th, 2006, 05:28 AM
#2
Re: Screen Res
 Originally Posted by dannyg
How do i change a computers screen res to be 1024x768 so my graphic will fit the screen?
if possible can i change it back to what it was before the program was opened when it is exited?
Welcome on the forums
Look at my sign resoulation free control
-
Oct 13th, 2006, 05:30 AM
#3
Re: Screen Res
AllAPI has this example:
http://www.allapi.net/apilist/Change...ettings.shtml#
Click the "Change Resolution" link under Examples.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Oct 13th, 2006, 05:53 AM
#4
PowerPoster
Re: Screen Res
Form
VB Code:
Option Explicit
Private Sub Form_Load()
ResizeDisplay True, 1024, 768
End Sub
Private Sub Form_Unload(Cancel As Integer)
ResizeDisplay (False)
End Sub
Module
VB Code:
Option Explicit
Const WM_DISPLAYCHANGE = &H7E
Const HWND_BROADCAST = &HFFFF&
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const CCDEVICENAME = 32
Const CCFORMNAME = 32
Const DM_BITSPERPEL = &H40000
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const CDS_UPDATEREGISTRY = &H1
Const CDS_TEST = &H4
Const DISP_CHANGE_SUCCESSFUL = 0
Const DISP_CHANGE_RESTART = 1
Const BITSPIXEL = 12
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
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
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, _
ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Any) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public OldX As Long
Public OldY As Long
Public nDC As Long
Private Sub ChangeResolution(x As Long, y As Long, Bits As Long)
Dim DevM As DEVMODE, ScInfo As Long, erg As Long, an As VbMsgBoxResult
erg = EnumDisplaySettings(0&, 0&, DevM)
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
DevM.dmPelsWidth = x
DevM.dmPelsHeight = y
DevM.dmBitsPerPel = Bits
erg = ChangeDisplaySettings(DevM, CDS_TEST)
Select Case erg&
Case DISP_CHANGE_RESTART
an = MsgBox("You need to restart your computer for new settings to take effect.", vbYesNo + vbSystemModal, "Info")
If an = vbYes Then
erg& = ExitWindowsEx(EWX_REBOOT, 0&)
End If
Case DISP_CHANGE_SUCCESSFUL
erg = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
ScInfo = y * 2 ^ 16 + x
SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, ByVal Bits, ByVal ScInfo
'MsgBox "Resolution has been changed...", vbOKOnly + vbExclamation, "Resolution Change"
Case Else
MsgBox "Display setting is not supported", vbOKOnly + vbCritical, "Error"
End Select
End Sub
Public Sub ResizeDisplay(ByVal ENABLED As Boolean, Optional ByVal x As Long, Optional ByVal y As Long)
If ENABLED And Not IsMissing(x) And Not IsMissing(y) Then
If x And y > 0 Then
OldX = Screen.Width / Screen.TwipsPerPixelX
OldY = Screen.Height / Screen.TwipsPerPixelY
nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
ChangeResolution x, y, GetDeviceCaps(nDC, BITSPIXEL)
End If
Else
If OldX And OldY > 0 Then
ChangeResolution OldX, OldY, GetDeviceCaps(nDC, BITSPIXEL)
DeleteDC nDC
End If
End If
End Sub
Last edited by rory; Oct 13th, 2006 at 06:05 AM.
-
Oct 13th, 2006, 05:54 AM
#5
Thread Starter
Lively Member
Re: Screen Res
It says display setting not supported when form closes :\
Last edited by dannyg; Oct 13th, 2006 at 06:01 AM.
-
Oct 13th, 2006, 06:06 AM
#6
PowerPoster
Re: Screen Res
yeah sorry .. edited above code.
-
Oct 13th, 2006, 06:07 AM
#7
Re: Screen Res
 Originally Posted by dannyg
It says display setting not supported when form closes :\
Check the code again
-
Oct 13th, 2006, 06:08 AM
#8
PowerPoster
Re: Screen Res
 Originally Posted by shakti5385
Check the code again 
works .. i had an extra condition in the main sub i didnt need ..
check now ..
-
Oct 13th, 2006, 06:12 AM
#9
Thread Starter
Lively Member
Re: Screen Res
got it working now thnx
-
Oct 13th, 2006, 06:13 AM
#10
PowerPoster
Re: [RESOLVED] Screen Res
no prob .. had the code laying around in an old form ..
just made the new sub and put it in a module for easier use. .
-
Oct 13th, 2006, 06:24 AM
#11
Re: [RESOLVED] Screen Res
 Originally Posted by rory
no prob .. had the code laying around in an old form ..
just made the new sub and put it in a module for easier use. .
good code by you boom
-
Mar 19th, 2007, 11:58 PM
#12
Lively Member
Re: [RESOLVED] Screen Res
Sorry to bump such and Old thread but its better then starting a new one.
I using this code.. it "works" fine BUT after I do this:
ResizeDisplay True, 1024, 768
it looks the right size but it sets my Screen.Width to 11520 and my Screen.Height to 11520.
These numbers shouldn't be the same, the width should be like 15360 or something.
Could you tell me what i'm doing wrong or why its doing this?
I copied the Code exactly.
Please Help
using VB6.0 on WinXP SP2.0
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
|