Dectect screen resolution

D

David

I'm trying to dectect the computer screen resolution and if it's below
1024x768 advise user and close access.

I have seen sample code like below, but i need help putting it together.


Here is something I found that looks like what i want, but dont know how to
use it
(Q) How do I find out what the current screen resolution is or what the
screen size is?

(A) You can use the GetSystemMetrics API to return these and many other
items. Use the posted function as an example to return the values you need.

'***************** Code Start **********************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetSys Lib "user32" _
Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1
Private Const SM_CXVSCROLL = 2
Private Const SM_CYHSCROLL = 3
Private Const SM_CYCAPTION = 4
Private Const SM_CXBORDER = 5
Private Const SM_CYBORDER = 6
Private Const SM_CXDLGFRAME = 7
Private Const SM_CYDLGFRAME = 8
Private Const SM_CYVTHUMB = 9
Private Const SM_CXHTHUMB = 10
Private Const SM_CXICON = 11
Private Const SM_CYICON = 12
Private Const SM_CXCURSOR = 13
Private Const SM_CYCURSOR = 14
Private Const SM_CYMENU = 15
Private Const SM_CXFULLSCREEN = 16
Private Const SM_CYFULLSCREEN = 17
Private Const SM_CYKANJIWINDOW = 18
Private Const SM_MOUSEPRESENT = 19
Private Const SM_CYVSCROLL = 20
Private Const SM_CXHSCROLL = 21
Private Const SM_DEBUG = 22
Private Const SM_SWAPBUTTON = 23
Private Const SM_RESERVED1 = 24
Private Const SM_RESERVED2 = 25
Private Const SM_RESERVED3 = 26
Private Const SM_RESERVED4 = 27
Private Const SM_CXMIN = 28
Private Const SM_CYMIN = 29
Private Const SM_CXSIZE = 30
Private Const SM_CYSIZE = 31
Private Const SM_CXFRAME = 32
Private Const SM_CYFRAME = 33
Private Const SM_CXMINTRACK = 34
Private Const SM_CYMINTRACK = 35
Private Const SM_CXDOUBLECLK = 36
Private Const SM_CYDOUBLECLK = 37
Private Const SM_CXICONSPACING = 38
Private Const SM_CYICONSPACING = 39
Private Const SM_MENUDROPALIGNMENT = 40
Private Const SM_PENWINDOWS = 41
Private Const SM_DBCSENABLED = 42
Private Const SM_CMOUSEBUTTONS = 43
Private Const SM_CMETRICS = 44

Function fGetSysStuff(strWhat As String) As String
Dim strRet As String
Select Case LCase(strWhat)
Case "resolution": strRet = apiGetSys(SM_CXSCREEN) & "x" _
& apiGetSys(SM_CYSCREEN)
Case "windowsize": strRet = apiGetSys(SM_CXFULLSCREEN) & "x" _
& apiGetSys(SM_CYFULLSCREEN)
End Select
fGetSysStuff = strRet
End Function
'***************** Code End **********************

Thank you
david
 
J

Jeff Conrad

in message:
I'm trying to detect the computer screen resolution and if it's below
1024x768 advise user and close access.

I have seen sample code like below, but i need help putting it together.


Here is something I found that looks like what I want, but don't know how to
use it
(Q) How do I find out what the current screen resolution is or what the
screen size is?

(A) You can use the GetSystemMetrics API to return these and many other
items. Use the posted function as an example to return the values you need.

<<code snipped>>

Hi David,

Here's a way that seems to work.

1. Copy and paste all that code into a new standard module and call the
module basDetectResolution.

2. Create another new standard module and copy/paste the following
code into it:

Public Function BadResolution() As Boolean
On Error GoTo ErrorPoint

Dim strResolution As String

strResolution = fGetSysStuff("resolution")

If Left(strResolution, 3) = "800" Then
BadResolution = True
End If

If Left(strResolution, 3) = "640" Then
BadResolution = True
End If

If BadResolution = True Then
MsgBox "Your current resolution is below " _
& "1024x768." & vbNewLine & "The program " _
& "will now terminate.", vbExclamation, _
"Unsupported Resolution Detected."
DoCmd.Quit
End If

ExitPoint:
Exit Function

ErrorPoint:
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Function

3. Compile the code.

4. Save and close this module. Name the module basCheckResolution

5. Create a new macro. In the Action column select RunCode.
In the Function Name area near the bottom of the half of the screen enter:
BadResolution()

6. Save and close this macro. Name this macro AutoExec. Very important
to name it that so this macro will run whenever the database is opened.

7. Close the database and then open it to test. For a resolution of 640Xwhatever
or 800xwhatever the message will be displayed and the database closed. Change
the message to your liking.

I must ask though if this is really necessary. There is code available that will
allow you to resize forms to different screen resolutions.

Hope that helps,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top