Retrieve Display Resolution Information

The following API function retrieves the computer's display size:

Declare Function DisplaySize Lib "user32" Alias _

"GetSystemMetrics" (ByVal nIndex As Long) As Long

Public Const SM_CXSCREEN = 0 Public Const SM_CYSCREEN = 1

Function VideoRes() As String Dim vidWidth Dim vidHeight vidWidth = DisplaySize(SM_CXSCREEN) vidHeight = DisplaySize(SM_CYSCREEN)

Select Case (vidWidth * vidHeight) Case 307200

VideoRes = "640 x 480" Case 480000

VideoRes = "800 x 600" Case 786432

VideoRes = "1024 x 768" Case Else

VideoRes = "Something else" End Select

End Function

Sub CheckDisplayRes() Dim Videolnfo As String

Dim Msg1 As String, Msg2 As String, Msg3 As String Videolnfo = VideoRes

Msg1 = "Current resolution is set at " & Videolnfo & Chr(10)

Msg2 = "Optimal resolution for this application is 1024 x 768" & Chr(10)

Msg3 = "Please adjust resolution"

Select Case Videolnfo

MsgBox Msg1 & Msg2 & Msg3 Case Is = "800 x 600"

MsgBox Msg1 & Msg2 Case Is = "1024 x 768"

MsgBox Msg1 Case Else

MsgBox Msg2 & Msg3 End Select

End Sub

In Figure 22.4, the CheckDisplayRes macro warns the client that the display setting is not optimal for the application.

Figure 22.4

Check the display resolution and prompt the user to change the resolution to get the most out of your application.

Figure 22.4

Check the display resolution and prompt the user to change the resolution to get the most out of your application.

0 0

Post a comment