我用shell调用了一个.exe程序,想要获得该程序中一个叫做“snapshot”的按钮的句柄(该按钮没有快捷键),请问该如何实现。

解决方案 »

  1.   

    findwindow + findwindowexhttp://expert.csdn.net/Expert/topic/1330/1330345.xml?temp=.5036432
    http://expert.csdn.net/Expert/topic/1082/1082682.xml?temp=.6683161
      

  2.   

    先找窗体,Getwintext用标题判断
    然后遍历它的子窗体,知道找到那个符合的按钮为止
      

  3.   

    模块:
    Option ExplicitPublic Const GW_HWNDNEXT = 2Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
    Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Function InstanceToWnd(ByVal target_pid As Long) As Long
        Dim test_hwnd As Long
        Dim test_pid As Long
        Dim test_thread_id As Long    test_hwnd = FindWindow(ByVal 0&, ByVal 0&)    Do While test_hwnd <> 0
            If GetParent(test_hwnd) = 0 Then
                test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)            If test_pid = target_pid Then
                    InstanceToWnd = test_hwnd
                    Exit Do
                End If
            End If        test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
        Loop
    End Function
      

  4.   

    a=shell("XXX")
    b=InstanceToWnd(a)
    b为该窗体的句柄Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Longc=FindWindowEx(b,0,vbnullstring,“snapshot”)
    or
    c=FindWindowEx(b,0,“snapshot”,vbnullstring)
    这点我忘记了,你试试吧
      

  5.   

    请问kivic,InstanceToWnd()是个什么东东呀,好像不是个函数,运行时系统提示有函数没定义.
      

  6.   

    先用findwindow获取窗体句柄,再用findwindowex获取按钮句柄
      

  7.   

    我用findwindow无法获得窗口句柄,窗口标题栏为installwatch
    hwndinstall=findwindow(vbnullstring,"installwatch")
    运行结果是,hwndinstall=0,我觉得问题出在第二个参数上