请问如果窗体没有焦点, 但处于激活状态, 能得到它的hwnd吗? (这个窗体可能不是最前面的窗体哦!)怎么得到? 请教啦~ 我一直搞不透.

解决方案 »

  1.   

    form1窗体:
    Option ExplicitPrivate Sub Command1_Click()
        Form2.Show
    End Subform2窗体
    Option ExplicitPrivate Sub Command1_Click()
        MsgBox Form2.hWnd
    End Sub
      

  2.   

    上面那个写错窗体了。form1窗体:
    Option ExplicitPrivate Sub Command1_Click()
        Form2.Show
    End Subform2窗体
    Option ExplicitPrivate Sub Command1_Click()
        MsgBox Form1.hWnd
    End Sub
      

  3.   

    我问错了, 不是本身和MID窗体阿, 是其它程序运行的窗体.
      

  4.   

    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Longdim lhwnd as long 
    lhwnd = findwindow(vbnullstring,"窗体的名称")
      

  5.   

    可以的.如果是VB本身的窗体,当然好办,但是,如果不是VB本身的窗体,必须引用API.
    下面这句API就是取前台窗口句柄的.
    Private Declare Function GetForegroundWindow Lib "user32" () As Long
      

  6.   

    可以的。
    module
    ============
    Option ExplicitDeclare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
    Declare Function IsWindowVisible Lib "user32" _
       (ByVal hwnd As Long) As LongDeclare Function IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As LongPublic Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
        Dim sSave As String, Ret As Long
        Ret = GetWindowTextLength(hwnd)
        sSave = Space(Ret)
        GetWindowText hwnd, sSave, Ret + 1    Form1.List1.AddItem sSave
        EnumWindowsProc = True
    End Function
    ========
    form1
    ========
    EnumWindows AddressOf EnumWindowsProc, ByVal 0&
      

  7.   

    上面的程序可以列出所有进程的hwnd.
      

  8.   

    对了,声明漏了一些,应该是下面这些
    Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Declare Function IsWindowVisible Lib "user32" _
       (ByVal hwnd As Long) As Long
    Declare Function GetParent Lib "user32" _
       (ByVal hwnd As Long) As LongDeclare Function IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As Long