如果电脑接了多个屏幕 vb6的窗体怎么才能知道自己在哪个屏幕? 又怎么知道当前屏幕的分辨率?
如果电脑接了多个屏幕 vb6的窗体怎么才能知道自己在哪个屏幕? 又怎么知道当前屏幕的分辨率?
现在的实际问题是,无论我的窗体在哪个屏幕中,调用Screen对象,都是取得的第一个屏幕的信息
[解决办法]
每个屏幕都有一个rect属性的,通过程序的坐标就能知道在哪个屏幕上
检测有几个屏幕以及每个屏幕的rect属性如下
Option ExplicitPublic Const MONITORINFOF_PRIMARY = &H1Public Const MONITOR_DEFAULTTONEAREST = &H2Public Const MONITOR_DEFAULTTONULL = &H0Public Const MONITOR_DEFAULTTOPRIMARY = &H1Public Type RECT Left As Long Top As Long Right As Long Bottom As LongEnd TypePublic Type MONITORINFO cbSize As Long rcMonitor As RECT rcWork As RECT dwFlags As LongEnd TypePublic Declare Function GetMonitorInfo Lib "user32.dll" Alias "GetMonitorInfoA" _ (ByVal hMonitor As Long, ByRef lpmi As MONITORINFO) As LongPublic Declare Function EnumDisplayMonitors Lib "user32.dll" (ByVal hdc As Long, _ ByRef lprcClip As Any, ByVal lpfnEnum As Long, ByVal dwData As Long) As LongPublic Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal X As _ Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal _ bRepaint As Long) As LongPublic Scr() As RECTPublic ScrSum As LongPublic 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 MI.cbSize = Len(MI) GetMonitorInfo hMonitor, MI R = MI.rcWork ScrSum = ScrSum + 1 ReDim Preserve Scr(ScrSum) Scr(ScrSum) = R 'If CBool(MI.dwFlags = MONITORINFOF_PRIMARY) Then '第一显示器 ' MoveWindow Form1.hwnd, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, 1& 'Else ' MoveWindow Form2.hwnd, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, 1& 'End If MonitorEnumProc = 1End FunctionPublic Sub CheckMonitor()ScrSum = 0EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf MonitorEnumProc, ByVal 0&End Sub