Solved

change screen resolution in code

Posted on 1998-07-02
5
132 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
  • 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

776 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