Solved

change screen resolution in code

Posted on 1998-07-02
5
136 Views
Last Modified: 2010-05-18
Is there any way to change the screen resolution from inside a VB program? I know how to tell what the resolution is, but I would then like to tell the user that my app has to have at least 800x600 and would the user like me to change it for them.
0
Comment
Question by:jGuild
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:jGuild
ID: 1464869
Edited text of question
0
 
LVL 1

Expert Comment

by:khaledc
ID: 1464870
You may have a look at Screen object in Vb help.
However, this only gives you basic control over the screen and not what you are after.
I am puzzeled also on how I can change my screen resolution. I may keep researching.
Anyone else is welcomed to answer your question.
0
 
LVL 4

Accepted Solution

by:
yowkee earned 100 total points
ID: 1464871
jGuild,

Here's a function to change screen resolution
-------
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
       Const CCDEVICENAME = 32
       Const CCFORMNAME = 32
       Const DM_PELSWIDTH = &H80000
       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
Sub ChangeRes(iWidth As Single, iHeight As Single)
    Dim a As Boolean
    Dim i&
    Dim DevM As DEVMODE
    
    i = 0
    Do
        a = EnumDisplaySettings(0&, i&, DevM)
        i = i + 1
    Loop Until (a = False)
    Dim b&
    DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
    DevM.dmPelsWidth = iWidth
    DevM.dmPelsHeight = iHeight
    b = ChangeDisplaySettings(DevM, 0)
End Sub
Private Sub Command1_Click()
    ChangeRes 800, 600
End Sub
--------

Regards.
0
 

Author Comment

by:jGuild
ID: 1464872
A couple of follow-ups:

A: Where did this info come from?. I looked all over for it

B: Do you have any info on the possible return values of
"ChangeDisplaySettingsA" ? What types of errors am I
likely to run into?

Thanks.

0
 
LVL 4

Expert Comment

by:yowkee
ID: 1464873
jGuild,

A. Sorry, I really forgot where I get the code. Normally if I knew the web page having the code, I'll just point you to there.

B. The return value of ChangeDisplaySettings including:

DISP_CHANGE_SUCCESSFUL      The settings change was successful.
DISP_CHANGE_RESTART      The computer must be restarted in order                          for the graphics mode to work.
DISP_CHANGE_BADFLAGS      An invalid set of flags was passed in.
DISP_CHANGE_FAILED      The display driver failed the specified                         graphics mode.
DISP_CHANGE_BADMODE      The graphics mode is not supported.
DISP_CHANGE_NOTUPDATED      Windows NT only: Unable to write settings                         to the registry.

And their value:
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

Regards.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question