473,657 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a way to change screen resolution in VBA

Is there a way to force a change in a user's screen resolution using
VBA code without having any input from the user?
Example: User John Backwards has his screen set to 800 x 600 pixels.
Backwards loads an Access app that needs at least 1024 x 768 pixels so
the app, on load, changes the screen resolution for him to 1024 x 768.

Nov 13 '05 #1
8 8494
Before I spark the ire of the community at large (is Larry online?) let
me revise my poorly prepared question (for which I have already
uncovered a solution)...
User John Backwards works in a mid-size company where he has been told
repeatedly that the minimum resolution for an enterprise level
application is 1024 x768. The application was developed for that spec
at a fairly large cost to the company and 1000+ users in many countries
over LAN/WAN/VPN connections use the application successfully. But poor
John Backwards calls tech support and puts in trouble tickets when, at
800 x 600 resolution, he can't see the bottom of certain forms or click
certain links.
Since poor John Backwards seems imune from termination, there seems to
be two solutions:
1.) force the screen to 1024 and maybe he (and a few of his cousins)
won't notice
2.) detect the 800 x 600 resolution and display a nasty message that
stays on his screen for maybe ten minutes explaining why he shouldn't
call tech support anymore when he can't perform certain actions.
There are probably other solutions but these two seem best for the
present mood.
lq

Nov 13 '05 #2
The code I found in this group to do this is below:
*************** *************** *************** *************** *****
' DECLARATIONS SECTION
'************** *************** *************** *************** ******
Option Compare Database
Option Explicit
Type RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type
' NOTE: The following declare statements are case sensitive.
Declare Function GetDesktopWindo w Lib "User32" () As Long
Declare Function GetWindowRect Lib "User32" _
(ByVal hWnd As Long, rectangle As RECT) As Long
'============== =============== =============== ==========
'This code shows how to change the screen resolution.
'Call the function like this:
' ChangeResolutio n 640, 480
'This would change the screen resolution to 640 pixels x 480 pixels.
Note
that
'you can only change the resolution to values supported by the display.

'Paste the following code into a module:'
Private Declare Function ChangeDisplaySe ttings Lib "User32" Alias _
"ChangeDisplayS ettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As
Long
Private Declare Function EnumDisplaySett ings Lib "User32" Alias _
"EnumDisplaySet tingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As
_
Long, lpDevMode As Any) As Boolean
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const CCFORMNAME = 32
Const CCDEVICENAME = 32
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
dmDisplayFreque ncy As Long
End Type
Public Function Change_Resoluti on(iWidth As Single, iHeight As Single)
Dim DevM As DEVMODE
Dim a As Boolean
Dim i As Long
Dim b As Long
i = 0
'Enumerate settings
Do
a = EnumDisplaySett ings(0&, i&, DevM)
i = i + 1
Loop Until (a = False)
'Change settings
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
DevM.dmPelsWidt h = iWidth
DevM.dmPelsHeig ht = iHeight
b = ChangeDisplaySe ttings(DevM, 0)
End Function
'************** *************** *************** *************** ******
' FUNCTION: GetScreenResolu tion()
'
' PURPOSE:
' To determine the current screen size or resolution.
'
' RETURN:
' The current screen resolution. Typically one of the following:
' 640 x 480
' 800 x 600
' 1024 x 768
'
'************** *************** *************** *************** ******
Function GetScreenResolu tion() As String
Dim R As RECT
Dim hWnd As Long
Dim RetVal As Long
hWnd = GetDesktopWindo w()
RetVal = GetWindowRect(h Wnd, R)
GetScreenResolu tion = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)
End Function

Nov 13 '05 #3
On 5 Aug 2005 19:12:05 -0700, "lauren quantrell"
<la************ *@hotmail.com> wrote:

Thanks for that clarification. I fortunately got to this message
before I finished responding to your OP :-)

I still like the "bitch about the 'best viewed with' resolution, and
offer two choices: Adjust_Resoluti on, and Exit.

Sometimes people like John can be helped with a larger monitor. I've
worked with an organization with one scary user (I would not want to
meet her in traffic) who was at 640*480 on a 21" monitor, which was
all she could work with with her vision. The organization accommodated
her as much as possible, which I think is a good thing. Forcing her to
go to 1024 would mean a VERY large monitor or she would have to quit
her job...

-Tom.
Before I spark the ire of the community at large (is Larry online?) let
me revise my poorly prepared question (for which I have already
uncovered a solution)...
User John Backwards works in a mid-size company where he has been told
repeatedly that the minimum resolution for an enterprise level
application is 1024 x768. The application was developed for that spec
at a fairly large cost to the company and 1000+ users in many countries
over LAN/WAN/VPN connections use the application successfully. But poor
John Backwards calls tech support and puts in trouble tickets when, at
800 x 600 resolution, he can't see the bottom of certain forms or click
certain links.
Since poor John Backwards seems imune from termination, there seems to
be two solutions:
1.) force the screen to 1024 and maybe he (and a few of his cousins)
won't notice
2.) detect the 800 x 600 resolution and display a nasty message that
stays on his screen for maybe ten minutes explaining why he shouldn't
call tech support anymore when he can't perform certain actions.
There are probably other solutions but these two seem best for the
present mood.
lq


Nov 13 '05 #4
Let me preface this by saying that I know this question has been
answered... OTOH, If you haven't been there yet, have a look around
Randy Birch's site.

http://vbnet.mvps.org/

tons of great VB stuff. even has links in his page to copy the code to
the clipboard for you (except it doesn't work with Firefox, and IE is a
virus waiting to kill your computer). The content, though, is
incredibly helpful (and searchable).

Nov 13 '05 #5
The one thing I did notice when using the Change_Resoluti on function is that
it also changed my refresh rate to 60Hz instead of the 85 I was at. I don't
know if there is a way to set this also, probably is.

--
Wayne Morgan
MS Access MVP
"lauren quantrell" <la************ *@hotmail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
The code I found in this group to do this is below:

Nov 13 '05 #6
Wayne Morgan wrote:
The one thing I did notice when using the Change_Resoluti on function is that
it also changed my refresh rate to 60Hz instead of the 85 I was at. I don't
know if there is a way to set this also, probably is.


This can be set in your video driver if it supports it, NVidia ones have
an override feature that can be used to set a decent rate at each
resolution or there's utilities like RefreshLock that do it.
Nov 13 '05 #7
I know how to do it in the video driver, I was just wondering if the VBA
code that sets the resolution could also set the refresh rate.

--
Wayne Morgan
MS Access MVP
"Trevor Best" <no****@nospam. invalid> wrote in message
news:42******** *************@n ews.zen.co.uk.. .
Wayne Morgan wrote:
The one thing I did notice when using the Change_Resoluti on function is
that it also changed my refresh rate to 60Hz instead of the 85 I was at.
I don't know if there is a way to set this also, probably is.


This can be set in your video driver if it supports it, NVidia ones have
an override feature that can be used to set a decent rate at each
resolution or there's utilities like RefreshLock that do it.

Nov 13 '05 #8
Wayne Morgan wrote:
I know how to do it in the video driver, I was just wondering if the VBA
code that sets the resolution could also set the refresh rate.


I tried before ('bout years ago when 43Hz interlaced was in use) and
couldn't do it, can't remember if it was a parameter on the change or
something that had to be done afterwards.
Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2731
by: Erik Bethke | last post by:
Hello All, I am trying to clean up some polish bugs with the Shanghai game I am working on and I am currently stuck on trying to get the right event for detecting when the user has changed the desktop resolution. I have tried trapping the following events: 1) SDL_ACTIVEEVENT 2) SDL_VIDEOEXPOSE
1
2857
by: Erik Bethke | last post by:
Hello All, I am trying to clean up some polish bugs with the Shanghai game I am working on and I am currently stuck on trying to get the right event for detecting when the user has changed the desktop resolution. I have tried trapping the following events: 1) SDL_ACTIVEEVENT 2) SDL_VIDEOEXPOSE 3) SDL_VIDEORESIZE
27
3313
by: skeeterbug | last post by:
please see http://www.geocities.com/operationsengineer1/test.htm for an idea of how i want my logo header div to be layed out. when i went to resize "Test" to 2em (from 1em), this is what happened... http://www.geocities.com/operationsengineer1/test1.htm
4
15506
by: pjac | last post by:
I need some help with some VB language that will change the screen resolution on a monitor when a MS-Access 2000 database is opened from 1024 x 768 to 800 x 600. Any help with this effort would be deeply appreciated. Thanks in advance....
1
2043
by: Bertrand1978 | last post by:
Hi All. I am using VC++/Visual Studio 6.0. I can get the current screen resolution with GetSystemMetrics(), but how do you change the screen resolution ? I guess I couldn't find a SetSystemMetrics() function or equivalent. Ideallly, I'd like to avoid messing up with DirectX or the display drivers directly. I suppose there must be an abstraction layer in VS that allows to do that. However, I'll take any suggestion at this point...
7
2178
by: Tim Rogers | last post by:
Hi folks, this is a resolution-detect script that I used on a site. As you can see it is designed to detect when the screen resolution falls below a certain level then load an alternative style sheet HOWEVER, is it possible to make a change to the code that will not only make it respond to windows with widths of less than 800 pixels but ALSO heights of less than 600 pixels. I'm a complete novice when it comes to .js so and help would...
7
7624
by: JaimeM26 | last post by:
I have been able to determine the resolution on the users machine, but i am looking for a way to force the resolution to 1024 X 768 if it is not that already in VB.NET. Can someone please help me with this. Also, is there a way to progromatically move the users taskbar back to the top or the bottom if it is located on either the left or right side of the screen? Thanks.
9
3897
by: Steve Wright | last post by:
Hi I'm developing a webpage that needs to include a different stylesheet depending on the screen resolution. I know that I could read the resolution in javascript and then do some sort of stylesheet switcher as part of the onload event but I would rather link in the correct stylesheet for the resolution in the first place.
1
3333
by: Tea Maker | last post by:
Hi, I have an application that is best viewed at 1024x768. I know that changing the screen resolution might cause some problems, but it's very important that I go on with this. So my plan is, to create a module in my application, that holds the current screen width and height (I already done this and it's working) . So now I want to change the screen resolution when I load the application, and later on , I will handle the onClose event...
0
8425
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.