Solved

change screen resolution in code

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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