Determining video display information

The example in this section uses Windows API calls to determine a system's current video mode for the primary display monitor. If your application needs to display a certain amount of information on one screen, knowing the display size helps you scale the text accordingly. In addition, the code determines the number of monitors. If more than one monitor is installed, the procedure reports the virtual screen size.

'32-bit API declaration

Declare Function GetSystemMetrics Lib "user32" _

(ByVal nIndex As Long) As Long Public Const SM_CMONITORS = 8 0 Public Const SM_CXSCREEN = 0 Public Const SM_CYSCREEN = 1 Public Const SM_CXVIRTUALSCREEN = 7 8 Public Const SM_CYVIRTUALSCREEN = 7 9

Sub DisplayVideoInfo()

Dim numMonitors As Long

Dim vidWidth As Long, vidHeight As Long Dim virtWidth As Long, virtHeight As Long Dim Msg As String numMonitors = GetSystemMetrics(SM_CMONITORS) vidWidth = GetSystemMetrics(SM_CXSCREEN) vidHeight = GetSystemMetrics(SM_CYSCREEN)

virtWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN) virtHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN)

If numMonitors > 1 Then

Msg = numMonitors & " display monitors" & vbCrLf Msg = Msg & "Virtual screen: " & virtWidth & " x " Msg = Msg & virtHeight & vbCrLf & vbCrLf

Msg = Msg & "The video mode on the primary display is: " Msg = Msg & vidWidth & " x " & vidHeight

Else

Msg = Msg & "The video display mode: " Msg = Msg & vidWidth & " x " & vidHeight End If MsgBox Msg End Sub

Figure 11-21 shows the message box returned by this procedure when running on a dualmonitor system.

Figure 11-21: Using a Windows API call to determine the video display mode.

CD- This example is available on the companion CD-ROM. The filename is % video ROM mode.xlsm.

0 0

Post a comment