Click to See Complete Forum and Search --> : Monitor
TheBao
Jul 24th, 2001, 09:36 PM
Does any one has example for:
Public Declare Function GetMonitorInfo Lib "user32.dll" Alias "GetMonitorInfoA" (ByVal hMonitor As Long, ByRef lpmi As MONITORINFO) As Long
Thanks.
Matthew Gates
Jul 24th, 2001, 11:23 PM
GetMonitorInfo:
The GetMonitorInfo function lets you obtain information about a display monitor.
BOOL GetMonitorInfo(
HMONITOR hMonitor, // handle to display monitor
LPMONITORINFO lpmi // pointer to display monitor information
);
Parameters
hmonitor
Handle to the display monitor of interest.
lpmi
Pointer to a MONITORINFO structure or a MONITORINFOEX structure. The function stores information about the specified display monitor in this structure.
You must set the cbSize member of the structure to sizeof(MONITORINFO) or sizeof(MONITORINFOEX) before calling the GetMonitorInfo function. Doing so lets the function determine the type of structure you are passing to it.
The MONITORINFOEX structure is a superset of the MONITORINFO structure. It has one additional member: a string member, to contain a name for the display monitor. Most applications have no use for a display monitor name, and so can save some bytes by using a MONITORINFO structure.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
Windows NT: To get extended error information, callGetLastError. .
MonitorInfo Structure Type:
The MONITORINFO structure contains information about a display monitor.
The GetMonitorInfo function stores information in a MONITORINFO structure or a MONITORINFOEX structure.
The MONITORINFO structure is a subset of the MONITORINFOEX structure. The MONITORINFOEX structure adds a string member to contain a name for the display monitor.
typedef struct tagMONITORINFO {
DWORD cbSize;
RECT rcMonitor;
RECT rcWork;
DWORD dwFlags;
} MONITORINFO, *LPMONITORINFO;
Members
cbSize
The size of the structure, in bytes.
Set the cbSize member to sizeof(MONITORINFO) before calling the GetMonitorInfofunction. Doing so lets the function determine the type of structure you are passing to it.
rcMonitor
A RECT structure that specifies the display monitor rectangle, expressed in virtual screen coordinates. Note that if the monitor is not the primary display monitor, some of the rectangle's coordinates may be negative values.
rcWork
A RECT structure that specifies the work area rectangle of the display monitor, expressed in virtual screen coordinates. Note that if the monitor is not the primary display monitor, some of the rectangle's coordinates may be negative values.
dwFlags
A set of flags that represent attributes of the display monitor.
The following flag is defined. Value Meaning
MONITORINFOF_PRIMARY This is the primary display monitor.
Matthew Gates
Jul 24th, 2001, 11:25 PM
Example:
'In a form (Form1)
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@allapi.net
'set the graphics mode of this form to persistent
Me.AutoRedraw = True
'start the enumeration
EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf MonitorEnumProc, ByVal 0&
End Sub
'In a module
Public Const MONITORINFOF_PRIMARY = &H1
Public Const MONITOR_DEFAULTTONEAREST = &H2
Public Const MONITOR_DEFAULTTONULL = &H0
Public Const MONITOR_DEFAULTTOPRIMARY = &H1
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Type MONITORINFO
cbSize As Long
rcMonitor As RECT
rcWork As RECT
dwFlags As Long
End Type
Public Type POINT
x As Long
y As Long
End Type
Public Declare Function GetMonitorInfo Lib "user32.dll" Alias "GetMonitorInfoA" (ByVal hMonitor As Long, ByRef lpmi As MONITORINFO) As Long
Public Declare Function MonitorFromPoint Lib "user32.dll" (ByVal x As Long, ByVal y As Long, ByVal dwFlags As Long) As Long
Public Declare Function MonitorFromRect Lib "user32.dll" (ByRef lprc As RECT, ByVal dwFlags As Long) As Long
Public Declare Function MonitorFromWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal dwFlags As Long) As Long
Public Declare Function EnumDisplayMonitors Lib "user32.dll" (ByVal hdc As Long, ByRef lprcClip As Any, ByVal lpfnEnum As Long, ByVal dwData As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Function MonitorEnumProc(ByVal hMonitor As Long, ByVal hdcMonitor As Long, lprcMonitor As RECT, ByVal dwData As Long) As Long
Dim MI As MONITORINFO, R As RECT
Debug.Print "Moitor handle: " + CStr(hMonitor)
'initialize the MONITORINFO structure
MI.cbSize = Len(MI)
'Get the monitor information of the specified monitor
GetMonitorInfo hMonitor, MI
'write some information on teh debug window
Debug.Print "Monitor Width/Height: " + CStr(MI.rcMonitor.Right - MI.rcMonitor.Left) + "x" + CStr(MI.rcMonitor.Bottom - MI.rcMonitor.Top)
Debug.Print "Primary monitor: " + CStr(CBool(MI.dwFlags = MONITORINFOF_PRIMARY))
'check whether Form1 is located on this monitor
If MonitorFromWindow(Form1.hwnd, MONITOR_DEFAULTTONEAREST) = hMonitor Then
Debug.Print "Form1 is located on this monitor"
End If
'heck whether the point (0, 0) lies within the bounds of this monitor
If MonitorFromPoint(0, 0, MONITOR_DEFAULTTONEAREST) = hMonitor Then
Debug.Print "The point (0, 0) lies wihthin the range of this monitor..."
End If
'check whether Form1 is located on this monitor
GetWindowRect Form1.hwnd, R
If MonitorFromRect(R, MONITOR_DEFAULTTONEAREST) = hMonitor Then
Debug.Print "The rectangle of Form1 lies within this monitor"
End If
Debug.Print ""
'Continue enumeration
MonitorEnumProc = 1
End Function
TheBao
Jul 24th, 2001, 11:30 PM
I think, this code does not work on WinNT. EnumDisplayMonitors is available only in 98 or 2000. I am using NT :-(
Thanks.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.