有两个form1、form2,两个显示器,要修改屏幕的分辨率使form1在第一个显示器上显示,form2在另外一个显示器上显示

解决方案 »

  1.   

    多显示器其实就是不同的屏幕坐标,将窗体移动到合适的位置就可以了。
    Option ExplicitPublic 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 TypePublic Declare Function GetMonitorInfo Lib "user32.dll" Alias "GetMonitorInfoA" _
        (ByVal hMonitor As Long, ByRef lpmi As MONITORINFO) 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 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 LongSub Main()
        '先显示窗体
        Form1.Show
        Form2.Show
        '在枚举显示器来定位窗体
        EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf MonitorEnumProc, ByVal 0&
    End SubPublic 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
        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 = 1
    End Function
      

  2.   

    在form1里怎么给它来个判断有几个显示器
    如果有1个就不显示另一个窗口,如果有两显示器就显示另一个窗口
    怎么做?