Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

change screen resolution in code

Posted on 1998-07-02
5
Medium Priority
?
140 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 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

610 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