can you change the screen resolution of the computer in runtime in vb6 :confused:
Printable View
can you change the screen resolution of the computer in runtime in vb6 :confused:
VB Code:
Private Const WM_DISPLAYCHANGE = &H7E Private Const HWND_BROADCAST = &HFFFF& Private Const EWX_LOGOFF = 0 Private Const EWX_SHUTDOWN = 1 Private Const EWX_REBOOT = 2 Private Const EWX_FORCE = 4 Private Const CCDEVICENAME = 32 Private Const CCFORMNAME = 32 Private Const DM_BITSPERPEL = &H40000 Private Const DM_PELSWIDTH = &H80000 Private Const DM_PELSHEIGHT = &H100000 Private Const CDS_UPDATEREGISTRY = &H1 Private Const CDS_TEST = &H4 Private Const DISP_CHANGE_SUCCESSFUL = 0 Private Const DISP_CHANGE_RESTART = 1 Private 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 Private OldX As Long Private OldY As Long Private nDC As Long Private Sub ChangeRes(X As Long, Y As Long, Bits As Long) Dim DevM As DEVMODE, ScInfo As Long, erg As Long, an As VbMsgBoxResult 'Get the info into DevM erg = EnumDisplaySettings(0&, 0&, DevM) 'This is what we're going to change DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL DevM.dmPelsWidth = X 'ScreenWidth DevM.dmPelsHeight = Y 'ScreenHeight DevM.dmBitsPerPel = Bits '(can be 8, 16, 24, 32 or even 4) 'Now change the display and check if possible erg = ChangeDisplaySettings(DevM, CDS_TEST) 'Check if succesfull Select Case erg& Case DISP_CHANGE_RESTART an = MsgBox("You've to reboot", 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 'Notify all the windows of the screen resolution change SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, ByVal Bits, ByVal ScInfo MsgBox "Everything's ok", vbOKOnly + vbSystemModal, "It worked!" Case Else MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error" End Select End Sub Private Sub Command1_Click() 'KPD-Team 1999 'URL: [url]http://www.allapi.net/[/url] 'E-Mail: [email][email protected][/email] Dim nDC As Long 'retrieve the screen's resolution OldX = Screen.Width / Screen.TwipsPerPixelX OldY = Screen.Height / Screen.TwipsPerPixelY 'Create a device context, compatible with the screen nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&) 'Change the screen's resolution ChangeRes 640, 480, GetDeviceCaps(nDC, BITSPIXEL) End Sub
Hack, you make it WAY too easy =P.
Z.
Thanks that worked great
is that the simplest way to do it thought??
that looks prety complex and thier are some things in the code like:
Public Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
If an = vbYes Then
erg& =ExitWindowsEx(EWX_REBOOT, 0&)
End If
thoes code snipits seem to be used to shut down the computer are they nesisary i dont know any computer that need to be shut down to change the res mabye real old ones do though
and also how do i get it to make the code i type in the post form message look like code
With a Microsoft product, you can even change your mind unless you reboot.
In terms of formatting your posts, see the link in my signature.
Using those functions are the easiest.Quote:
Originally posted by dogfish227
Thanks that worked great
is that the simplest way to do it thought??
that looks prety complex and thier are some things in the code like:
Public Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
If an = vbYes Then
erg& =ExitWindowsEx(EWX_REBOOT, 0&)
End If
Yes, you could always remove the shutdown code, and the comments if you really want to shorten your code. You can also remove the constants that are not in use.
ok thanks for the help with the res
but i still dont know how to make the code on the form look like code
i tried useing the "[code ]" tag but that is for code in genal it dosent change the colors:
the page never atualy says how to make it look like vb codeCode:label1.caption = "Test"
i tried "[vb], [visiual basic], [visiualbasic],"
none of those worked what is the name of the tag
[vbcode][/Highlight] :)
VB Code:
Dim Worked as boolean Worked = true 'it worked
Can anyone tell me what this line of code actually does?
I found the code reset my refresh rate to 60Hz even with:VB Code:
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
included in the code.VB Code:
DevM.dmDisplayFrequency = 75
I commented out the top line and now it works without a problem, I've not removed something important have I?
ta.
- Mike.
You fill in the dmFields property to let Windows know what other properties you are going to be using.Quote:
Originally posted by MikeAJK
Can anyone tell me what this line of code actually does?
VB Code:
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL