Can you detect or change the pc resolution

Jon123

Registered User.
Local time
Today, 09:33
Joined
Aug 29, 2003
Messages
668
When starting the database is it possible to detect what the resolution is and change it or at least have a msgbox suggestion a high or lower res. I have forms that look much better at higher res.

jon
 
i have this code for checking the screen resolution at home, but i am not there now. i would suggest
googling this: ms access screen resolution VBA

i will post the code for ya when i get home if i remember.
 
here is what i promised Jon:
Code:
'*****************************************************************
' DECLARATIONS SECTION
'*****************************************************************

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 GetDesktopWindow Lib "User32" () As Long
Declare Function GetWindowRect Lib "User32" _
      (ByVal hWnd As Long, rectangle As RECT) As Long

Public Type DEVMODE
    dmDeviceName As String * 32
    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 * 32
    dmUnusedPadding As Integer
    dmBitsPerPixel As Integer
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
    dmICMMethod As Long
    dmICMIntent As Long
    dmMediaType As Long
    dmDitherType As Long
    dmReserved1 As Long
    dmReserved2 As Long
Rem    dmPanningWidth As Long 'remove the Rem if your OS is Windows 2000, if needed
Rem    dmPanningHeight As Long 'remove the Rem if your OS is Windows 2000, if needed
End Type

Public Declare Function EnumDisplaySettings Lib "user32.dll" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As String, ByVal iModeNum As Long, lpDevMode As DEVMODE) As Long
Public Const ENUM_CURRENT_SETTINGS = -1
Public Declare Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
Public Const CDS_UPDATEREGISTRY = &H1
Public Const CDS_TEST = &H2
Public Const DISP_CHANGE_SUCCESSFUL = 0
Public Const DISP_CHANGE_RESTART = 1

'*****************************************************************
' FUNCTION: GetScreenResolution()
'
' 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 GetScreenResolution() As String

   Dim R As RECT
   Dim hWnd As Long
   Dim RetVal As Long

   hWnd = GetDesktopWindow()
   RetVal = GetWindowRect(hWnd, R)
   GetScreenResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)

End Function

Public Function ChangeResolution(vWidth As Variant, vHeight As Variant)
On Error GoTo Err_ChangeResolution

    Dim dm As DEVMODE
    Dim RetVal As Long
    
    dm.dmSize = Len(dm)
    RetVal = EnumDisplaySettings(vbNullString, ENUM_CURRENT_SETTINGS, dm)

    dm.dmPelsWidth = vWidth  ' Width must be numeric (e.g. 1024 or 800 or 640)
    dm.dmPelsHeight = vHeight ' Height must be numeric (e.g. 768 or 600 or 480)

    RetVal = ChangeDisplaySettings(dm, CDS_TEST)
    If RetVal <> DISP_CHANGE_SUCCESSFUL Then
        Debug.Print "Unable to change to the requested resolution of " & vWidth & "x" & vHeight
    Else
        RetVal = ChangeDisplaySettings(dm, CDS_UPDATEREGISTRY)
        Select Case RetVal
        Case DISP_CHANGE_SUCCESSFUL
            Debug.Print "Resolution successfully changed to " & vWidth & "x" & vHeight
        Case DISP_CHANGE_RESTART
            Debug.Print "A reboot is necessary before the resolution changes will take effect."
        Case Else
            Debug.Print "Unable to change resolution!"
        End Select
    End If

Exit_ChangeResolution:
    Exit Function

Err_ChangeResolution:
    MsgBox Err.Number, Err.Description
    Resume Exit_ChangeResolution

End Function
 
If you simply want to detect the resolution and report on it then this shortened code will suffice

Code:
Declare Function GetDesktopWindow Lib "User32" () As Long
Declare Function GetWindowRect Lib "User32" (ByVal hWnd As Long, rectangle As RECT) As Long
Type RECT
   x1 As Long
   y1 As Long
   x2 As Long
   y2 As Long
End Type

'*****************************************************************
' FUNCTION: GetScreenResolution()
'
' 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
'     1280 x 800
'*****************************************************************
Function GetScreenResolution() As String

   Dim R As RECT
   Dim hWnd As Long
   Dim RetVal As Long

   hWnd = GetDesktopWindow()
   RetVal = GetWindowRect(hWnd, R)
   ResWidth = CInt((R.x2 - R.x1))
   ResHeight = CInt((R.y2 - R.y1))
   GetScreenResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)

End Function
 
Adam, I have your code. I have it is a module. How do I call the functions?
jon
 
Adam sorry I'm just a tad lost here. So I copied the code you set into a module. I called that module Resolutin. In the database I have a splash screen that opens in the on open event I'm trying to call the function
Call Public Function ChangeResolution(vWidth As Variant, vHeight As Variant)
but the code error on the word As and the code turns red.

jon
 
As adam said

Code:
Call ChangeResolution()

NOT

Code:
Call Public Function ChangeResolution(vWidth As Variant, vHeight As Variant)

David
 
so in the on open event of a form I have this line of code
Call ChangeResolution

The () at the end disappear when it saves. When the form opens or when I compile it I get an error message - Compile error argument not optional

is this error because of the way I'm calling it ?

jon
 
john,

just call the function NAME. just like what david has in his first code block above. if it still doesn't work for you, upload the database, and we'll take a look at what's wrong, OK?
 
When the form opens or when I compile it I get an error message - Compile error argument not optional

is this error because of the way I'm calling it ?

jon
no it's not jon. you're not entering any arguments (the args are in the () after the function name). if you don't understand this, upload it, and we'll help you out. sound like a plan?
 
yes I can upload but I will need to slim it down a bit.
 
ok here you go just open the Frm-Maincover in the on open I calling the function
 

Attachments

Jon,

This is how you show the user upon entering the database. I hid the AutoExec macro. I cannot get to the changing of the screen res right now, I'm off to work. Perhaps another day. Let me know if this is a good step. It should work fine for you. Now all you have to do is call the macro or the function when you open the form. I used the function on open of the DB, not the form.
 

Attachments

right click in the database window jon, and the options will be there for you. "navigation options" is what you want.
 
Sorry man I do not do macro's I like using VBA. But anyway I got the
Call GetScreenResolution()
and
Call ChangeResolution()

working it is really cool. So when the dbase starts the GetScreenResolution runs and displays a message that the resulation is being changed then it
Call ChangeResolution(1280, 768) and it changes the screen resulation. This is very cool. Now I need to fancy it up a bit. So I can check resulation and only change if its needed. Think I got that part. But what happens if the user's PC does not support say 1280 X 768 what do I do here in this case?
jon

again thanks for the support
sorry to be a pain still have tons to learn
 
the million dollar question can I put the user's resolution back to what it was when exiting the dbase?

jion
 

Users who are viewing this thread

Back
Top Bottom