|
|
|
If you are working with multiple monitors then this example will show you how to enumerate available monitors on your sytem and retrive properties of monitor.
Step-By-Step Example
- Create a standard exe project - Add one Module to project - Place one textbox on form1, set MultiLine=True - Add the following code in form1
Form1.frm |
- Add the following code in Module1
Module1.bas |
Click here to copy the following block | 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 Dim strMsg As String Dim strProp As String * 15
strProp = "Moitor handle: " strMsg = strMsg & strProp & " : " & CStr(hMonitor) & vbCrLf
MI.cbSize = Len(MI)
GetMonitorInfo hMonitor, MI
strProp = "Moitor Width" strMsg = strMsg & strProp & " : " & CStr(MI.rcMonitor.Right - MI.rcMonitor.Left) & vbCrLf strProp = "Moitor Height" strMsg = strMsg & strProp & " : " & CStr(MI.rcMonitor.Bottom - MI.rcMonitor.Top) & vbCrLf strProp = "Primary Monitor" strMsg = strMsg & strProp & " : " & CStr(CBool(MI.dwFlags = MONITORINFOF_PRIMARY)) & vbCrLf
If MonitorFromPoint(0, 0, MONITOR_DEFAULTTONEAREST) = hMonitor Then strMsg = strMsg & "#### Yes point (0, 0) lies within the bounds of this monitor ####" & vbCrLf End If
GetWindowRect Form1.hwnd, R If MonitorFromRect(R, MONITOR_DEFAULTTONEAREST) = hMonitor Then strMsg = strMsg & "#### Yes Form1 is on this monitor ####" & vbCrLf End If Form1.Text1 = Form1.Text1 & strMsg & String(65, "=") & vbCrLf
MonitorEnumProc = 1 End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|