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
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
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
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" 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?
Public Declare Function ChangeDisplaySettings Lib "user32" _
Alias "ChangeDisplaySettingsA" _
(lpDevMode As Any, _
ByVal dwflags As Long) As Long
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" _
(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
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 "Error! Perhaps your hardware is not up to the task?"
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 "Don't know what to do with you!"
End Select
End Sub
----------------------------------------------
Ben O'Hara
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.
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.
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
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.
Kelly,
You need to have all of the code from "Option Explicit" to the end.
GetDeviceCaps is an api function declared at the top of the code:
Private Declare Function GetDeviceCaps Lib "gdi32" _
(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
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.