假如我用程序启动了一个word ,如何获得它的hWnd-窗口句柄

解决方案 »

  1.   

    findwindow(vbnullstring,窗口标题名),成功返回句柄,失败返回0
      

  2.   

    就是我获得了(word)他的hwnd后,我要改变它的大字,要求如下:
    有两个word 一起,它平开始是水平平铺,但现在去要改变它们的大小,即当一个拉小时,另一个就变大,就像是中间有一个分割条的形式,这样能实现吗
      

  3.   

    theword = findwindow ( "OpusApp", vbnullstring )用timer可以做到,中间那个分割条好像不好做
      

  4.   

    我的意思并不是要分割条啊只是他们能联动的改变大小就可以啦
    既把一个拉小时另一个拉大始终两个word窗口能占满整个屏幕就行啦。
      

  5.   

    获得句柄后可以用timer 定时返回两个窗口的尺寸,使两个窗口的尺寸和等于指定的数值.
    关注...
      

  6.   

    针对两个记事本Option Explicit
    Dim b As Boolean
    Private Sub Form_Load()
        Timer1.Enabled = True
        Timer1.Interval = 100
        n0 = 0
        n1 = 0
    End SubPrivate Sub Timer1_Timer()
        If Not b Then
            b = True
        Else
            If n0 <> 0 And n1 <> 0 Then
                Dim r As RECT
                GetWindowRect n0, r
                SetWindowPos n1, 0, 0, r.Bottom, Screen.Width / 15, Screen.Height / 15 - r.Bottom, 0
            Else
                n0 = 0
                n1 = 0
                EnumWindows AddressOf myenum, ByVal 0&
            End If
        End If
    End Sub-----------------------------------------------Option Explicit
    Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) 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 Long
    Public Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End TypePublic n0 As Long
    Public n1 As Long
    Public Function myenum(ByVal hwnd As Long, ByVal lParam As Long) As Long
        Dim ss As String * 255
        GetClassName hwnd, ss, 255
        If remove0(ss) = "Notepad" And n0 = 0 Then
            n0 = hwnd
        End If
        If remove0(ss) = "Notepad" And n1 = 0 And n0 <> 0 And hwnd <> n0 Then
            n1 = hwnd
        End If
        myenum = 1
    End Function
    Public Function remove0(ByVal src As String) As String
        Dim i As Integer
        Dim s As String
        For i = 1 To Len(src)
            If Mid(src, i, 1) <> Chr(0) Then
                s = s & Mid(src, i, 1)
            Else
                Exit For
            End If
        Next i
        remove0 = s
    End Function