Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change screen resolution from Access? 5

Status
Not open for further replies.

geralf

Technical User
Apr 7, 2003
44
MX
Hi,

Is it possible to change the screen resolution from a button in Access?

Thanks in advance!
 
1st question is why? Users tend to get a bit pished if you start messing around with their desktop, it's like going to get some petrol from the garage and the pump guy respraying your car for you whilst you are there!

That said:

Copy this code into a module and change the relevant bits:
Option Explicit

'--------------------------------------------------------------
' Copyright ©1996-2002 VBnet, Randy Birch, All Rights Reserved.
' Terms of use '--------------------------------------------------------------

Public Declare Function ChangeDisplaySettings Lib "user32" _
Alias "ChangeDisplaySettingsA" _
(lpDevMode As Any, _
ByVal dwflags As Long) As Long

Public Const CCDEVICENAME As Long = 32
Public Const CCFORMNAME As Long = 32

Public Const DM_GRAYSCALE As Long = &H1
Public Const DM_INTERLACED As Long = &H2

Public Const DM_BITSPERPEL As Long = &H40000
Public Const DM_PELSWIDTH As Long = &H80000
Public Const DM_PELSHEIGHT As Long = &H100000
Public Const DM_DISPLAYFLAGS As Long = &H200000

Public Const CDS_UPDATEREGISTRY As Long = &H1
Public Const CDS_TEST As Long = &H2
Public Const CDS_FULLSCREEN As Long = &H4
Public Const CDS_GLOBAL As Long = &H8
Public Const CDS_SET_PRIMARY As Long = &H10
Public Const CDS_NORESET As Long = &H10000000
Public Const CDS_SETRECT As Long = &H20000000
Public Const CDS_RESET As Long = &H40000000
Public Const CDS_FORCE As Long = &H80000000

'Return values for ChangeDisplaySettings
'Public Const DISP_CHANGE_SUCCESSFUL = 0
'Public Const DISP_CHANGE_RESTART = 1
'Public Const DISP_CHANGE_FAILED = -1
'Public Const DISP_CHANGE_BADMODE = -2
'Public Const DISP_CHANGE_NOTUPDATED = -3
'Public Const DISP_CHANGE_BADFLAGS = -4
'Public Const DISP_CHANGE_BADPARAM = -5

Public 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



'--------------------------------------------------------------
' Copyright ©1996-2002 VBnet, Randy Birch, All Rights Reserved.
' Terms of use '--------------------------------------------------------------

Sub ChangeScreenModes()

Dim DM As DEVMODE


'change the current resolution, no prompting
'BE CAREFUL .. you could set your system to a
'setting which renders the display difficult to read.

With DM

.dmPelsWidth = 1024
.dmPelsHeight = 768
.dmBitsPerPel = 32
.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
.dmSize = LenB(DM)
End With

If ChangeDisplaySettings(DM, CDS_FORCE) <> 0 Then

MsgBox &quot;Error! Perhaps your hardware is not up to the task?&quot;

End If

End Sub


hth

Ben ----------------------------------------------
Ben O'Hara

&quot;Where are all the stupid people from...
...And how'd they get so dumb?&quot;
NoFX-The Decline
----------------------------------------------
 
Hi Ben O'Hara

Thanks for your fast reply.

That's what I've experienced from the users. I've developed a db at 1024 x 768. Some users PC's are set up with 800 x 600. The users which were running this resolution complained about the data beeing too small to read when it was changed to 1024 x 768. I don't agree with them that 1024 x 768 is too smal on a 17&quot; monitor. The scenario is more that they've 'always used 800 x 600' or perhaps they need reading glasses :). So to acommodate different users I would like to have a command button on a 'options form' which on click toggles between these two resolutions.

This code is over my head to understand, but if I want to use a command button to toggle screen resolution, then I also need to read the current resolution. Is this possible from your code above?

Thanks very much
 
Your wish....

The sub routine ToggleScreenSize() will switch between the two screen sizes.

If you need any help, let me know.

Ben

Option Explicit

'--------------------------------------------------------------
' Copyright ©1996-2002 VBnet, Randy Birch, All Rights Reserved.
' Terms of use '--------------------------------------------------------------

Public Declare Function ChangeDisplaySettings Lib &quot;user32&quot; _
Alias &quot;ChangeDisplaySettingsA&quot; _
(lpDevMode As Any, _
ByVal dwflags As Long) As Long

Declare Function GetDC Lib &quot;user32&quot; (ByVal hwnd As Long) As Long

Private Declare Function GetDeviceCaps Lib &quot;gdi32&quot; _
(ByVal hdc As Long, _
ByVal nIndex As Long) As Long

Public Const CCDEVICENAME As Long = 32
Public Const CCFORMNAME As Long = 32

Public Const DM_GRAYSCALE As Long = &H1
Public Const DM_INTERLACED As Long = &H2

Public Const DM_BITSPERPEL As Long = &H40000
Public Const DM_PELSWIDTH As Long = &H80000
Public Const DM_PELSHEIGHT As Long = &H100000
Public Const DM_DISPLAYFLAGS As Long = &H200000

Public Const CDS_UPDATEREGISTRY As Long = &H1
Public Const CDS_TEST As Long = &H2
Public Const CDS_FULLSCREEN As Long = &H4
Public Const CDS_GLOBAL As Long = &H8
Public Const CDS_SET_PRIMARY As Long = &H10
Public Const CDS_NORESET As Long = &H10000000
Public Const CDS_SETRECT As Long = &H20000000
Public Const CDS_RESET As Long = &H40000000
Public Const CDS_FORCE As Long = &H80000000

Public 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

Private Const HORZRES As Long = 8
Private Const VERTRES As Long = 10
Private Const BITSPIXEL As Long = 12
Private Const VREFRESH As Long = 116

Public currHRes As Long
Public currVRes As Long
Public currBPP As Long


'--------------------------------------------------------------
' Copyright ©1996-2002 VBnet, Randy Birch, All Rights Reserved.
' Terms of use '--------------------------------------------------------------

Sub ChangeScreenModes(scrWidth As Long, scrHeight As Long)

Dim DM As DEVMODE


'change the current resolution, no prompting
'BE CAREFUL .. you could set your system to a
'setting which renders the display difficult to read.

With DM

.dmPelsWidth = scrWidth
.dmPelsHeight = scrHeight
.dmBitsPerPel = 32
.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
.dmSize = LenB(DM)
End With

If ChangeDisplaySettings(DM, CDS_FORCE) <> 0 Then

MsgBox &quot;Error! Perhaps your hardware is not up to the task?&quot;

End If

End Sub



Private Function GetScreenSize()
Dim hdc As Long

hdc = GetDC(Application.hWndAccessApp)
currHRes = GetDeviceCaps(hdc, HORZRES)
currVRes = GetDeviceCaps(hdc, VERTRES)
currBPP = GetDeviceCaps(hdc, BITSPIXEL)
End Function

Sub ToggleScreenSize()
GetScreenSize
Select Case currHRes
Case 1024
ChangeScreenModes 800, 600
Case 800
ChangeScreenModes 1024, 768
Case Else
MsgBox &quot;Don't know what to do with you!&quot;
End Select
End Sub
----------------------------------------------
Ben O'Hara

&quot;Where are all the stupid people from...
...And how'd they get so dumb?&quot;
NoFX-The Decline
----------------------------------------------
 
Thanks very Much Ben!

Just like Aladdin....:) Awesome!

One question from your first post, you said '...and change the relevant bits'. What are you refering to in your code?

I'm soon finished with my session now, but I'll try it out later this evening. I'll post back.

Thanks very much for your assistance!

Gerhard
 
The bits that change the screen size & depth are:

.dmPelsWidth = 1024
.dmPelsHeight = 768
.dmBitsPerPel = 32


in the second example I have changed the module to accept variables in place of defined values.

hth

Ben ----------------------------------------------
Ben O'Hara

&quot;Where are all the stupid people from...
...And how'd they get so dumb?&quot;
NoFX-The Decline
----------------------------------------------
 
Hi Ben!

I've tried it out. Got one probem. When I click the command button to call the ToggleScreenSize, the screen changes resolution, but the VB editor opens and shows the module of the form where the button is placed. No errors though. I closed the editor and all other objects on the task bar than the db window and form itsself.

Any idea?

Gerhard
 
Hi Ben!

Disregard my last post. I had restarted the pc, and then it worked fine.

Thank you very much for the help again Ben!

best regards
Gerhard
 
oharab,

I am having the same problem at work with a database and a couple of users still using 800 X 600. I am new to access and not sure how to set it up please help (I have already tried with a toggle button but did not succeed.

Thanks in advance,

Kelly
 
Ben

Have tried your code and get to

DIM DM as DEVMODE

when it comes up with compile error: internal error


Using Access 2K

Any Ideas?


John R
 
Kelly,
To set it up, you need to copy all the code into a new module in your database.

Then on your form that controls the screensize put a normal button, you don't need a toggle button. On the onClick event of the button just add the code:
Call ToggleScreenSize()

Now when your users press the button the screensize will switch to 1024x768 if they are on 800x600 or vice versa.

If you have any more questions, just ask.

hth

Ben

----------------------------------------------
Ben O'Hara

&quot;Where are all the stupid people from...
...And how'd they get so dumb?&quot;
NoFX-The Decline
----------------------------------------------
 
John,
Have you copied all the code into a new module?
The DEVMODE type is defined near the beginning of the code.

hth

Ben

----------------------------------------------
Ben O'Hara

&quot;Where are all the stupid people from...
...And how'd they get so dumb?&quot;
NoFX-The Decline
----------------------------------------------
 
Yep, did that.

However, I hadn't closed the application down and restarted it - work's fine now, thanks.

Regards

John R
 
oharab,

I will give that a try first thing tuesday when I return to work and will let you know how it goes.

Thanks for replying so soon,

Kelly
 
oharab,

I have 2 problems but it is working somewhat.

1st problem:

When I click on the compile I get the following error;

Complie error: Sub or function not defined

(what is highlighted in the code is the following)

Private Function GetScreenSize()
Dim hdc As Long

hdc = GetDC(Application.hWndAccessApp)
currHRes = GetDeviceCaps(hdc, HORZRES) ***THE GETDEVICECAPS IS HIGHLIGHTED ****
currVRes = GetDeviceCaps(hdc, VERTRES)
currBPP = GetDeviceCaps(hdc, BITSPIXEL)
End Function


2nd problem:

This may be related to the 1st problem. When I click the button it goes from 800X600 to 1024x768 like it is supposed to, but leaves the task bar up a 1/3 from the bottom instead of staying at the bottom like it should.

By the way using win2000 w/access2000.

Thanks in advance,

Kelly
 
Kelly,
You need to have all of the code from &quot;Option Explicit&quot; to the end.
GetDeviceCaps is an api function declared at the top of the code:
Private Declare Function GetDeviceCaps Lib &quot;gdi32&quot; _
(ByVal hdc As Long, _
ByVal nIndex As Long) As Long


I'm not sure if running on win2000 is the problem. It works fine on my NT machine, but I don't have 2000 or XP to check. Make sure you have all the code & try again.

hth

B

----------------------------------------------
Ben O'Hara

&quot;Where are all the stupid people from...
...And how'd they get so dumb?&quot;
NoFX-The Decline
----------------------------------------------
 
oharab,

I checked the code and have it all from the second time you posted it. I will go back again and check out what I am doing wrong and get back to you.

Thanks,

Kelly
 
Thanks for the ToggleScreenSize() function. it undeniably 'works', but at the cost of resetting the screen refresh rate to 60Hz.

Obviously, this results in a heavy black border around everything. It's not a workable solution, since asking the user to change her/his refresh rate is even a bigger deal than having them switch resolutions.

Any ideas?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top