Results 1 to 4 of 4

Thread: Monitor

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2001
    Location
    Vietnam
    Posts
    613

    Monitor

    Does any one has example for:
    Code:
    Public Declare Function GetMonitorInfo Lib "user32.dll" Alias "GetMonitorInfoA" (ByVal hMonitor As Long, ByRef lpmi As MONITORINFO) As Long
    Thanks.

  2. #2
    Matthew Gates
    Guest
    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.

  3. #3
    Matthew Gates
    Guest
    Example:


    VB Code:
    1. 'In a form (Form1)
    2. Private Sub Form_Load()
    3.     'KPD-Team 2000
    4.     'URL: [url]http://www.allapi.net/[/url]
    5.     'E-Mail: [email][email protected][/email]
    6.     'set the graphics mode of this form to persistent
    7.     Me.AutoRedraw = True
    8.     'start the enumeration
    9.     EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf MonitorEnumProc, ByVal 0&
    10. End Sub
    11.  
    12. 'In a module
    13. Public Const MONITORINFOF_PRIMARY = &H1
    14. Public Const MONITOR_DEFAULTTONEAREST = &H2
    15. Public Const MONITOR_DEFAULTTONULL = &H0
    16. Public Const MONITOR_DEFAULTTOPRIMARY = &H1
    17. Public Type RECT
    18.     Left As Long
    19.     Top As Long
    20.     Right As Long
    21.     Bottom As Long
    22. End Type
    23. Public Type MONITORINFO
    24.     cbSize As Long
    25.     rcMonitor As RECT
    26.     rcWork As RECT
    27.     dwFlags As Long
    28. End Type
    29. Public Type POINT
    30.     x As Long
    31.     y As Long
    32. End Type
    33. Public Declare Function GetMonitorInfo Lib "user32.dll" Alias "GetMonitorInfoA" (ByVal hMonitor As Long, ByRef lpmi As MONITORINFO) As Long
    34. Public Declare Function MonitorFromPoint Lib "user32.dll" (ByVal x As Long, ByVal y As Long, ByVal dwFlags As Long) As Long
    35. Public Declare Function MonitorFromRect Lib "user32.dll" (ByRef lprc As RECT, ByVal dwFlags As Long) As Long
    36. Public Declare Function MonitorFromWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal dwFlags As Long) As Long
    37. 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
    38. Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    39. Public Function MonitorEnumProc(ByVal hMonitor As Long, ByVal hdcMonitor As Long, lprcMonitor As RECT, ByVal dwData As Long) As Long
    40.     Dim MI As MONITORINFO, R As RECT
    41.     Debug.Print "Moitor handle: " + CStr(hMonitor)
    42.     'initialize the MONITORINFO structure
    43.     MI.cbSize = Len(MI)
    44.     'Get the monitor information of the specified monitor
    45.     GetMonitorInfo hMonitor, MI
    46.     'write some information on teh debug window
    47.     Debug.Print "Monitor Width/Height: " + CStr(MI.rcMonitor.Right - MI.rcMonitor.Left) + "x" + CStr(MI.rcMonitor.Bottom - MI.rcMonitor.Top)
    48.     Debug.Print "Primary monitor: " + CStr(CBool(MI.dwFlags = MONITORINFOF_PRIMARY))
    49.     'check whether Form1 is located on this monitor
    50.     If MonitorFromWindow(Form1.hwnd, MONITOR_DEFAULTTONEAREST) = hMonitor Then
    51.         Debug.Print "Form1 is located on this monitor"
    52.     End If
    53.     'heck whether the point (0, 0) lies within the bounds of this monitor
    54.     If MonitorFromPoint(0, 0, MONITOR_DEFAULTTONEAREST) = hMonitor Then
    55.         Debug.Print "The point (0, 0) lies wihthin the range of this monitor..."
    56.     End If
    57.     'check whether Form1 is located on this monitor
    58.     GetWindowRect Form1.hwnd, R
    59.     If MonitorFromRect(R, MONITOR_DEFAULTTONEAREST) = hMonitor Then
    60.         Debug.Print "The rectangle of Form1 lies within this monitor"
    61.     End If
    62.     Debug.Print ""
    63.     'Continue enumeration
    64.     MonitorEnumProc = 1
    65. End Function

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2001
    Location
    Vietnam
    Posts
    613
    I think, this code does not work on WinNT. EnumDisplayMonitors is available only in 98 or 2000. I am using NT :-(

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width