Solved

change screen resolution in code

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now