2014-02-09 58 views
0

使用間諜++我一直在試圖控制與我自己的程序的外部程序表單按鈕之外.. enter image description here麻煩與按下按鈕的應用程序

圖爲我試圖模仿什麼控制,這裏是我的下面下面的代碼...

Dim hWnd As IntPtr = FindWindow(vbNullString, ListView4.SelectedItems(0).SubItems(3).Text) 
    If hWnd.Equals(IntPtr.Zero) Then 
     Return 
    End If 
    Dim hWndButton As IntPtr = _ 
    FindWindowEx(hWnd, IntPtr.Zero, "Button", "Load Settings") 
    If hWndButton.Equals(IntPtr.Zero) Then 
     Return 
    End If 

然而,當我運行的代碼沒有任何反應..一種可能性是,我抓住了窗口的名字是錯的,但如果不是這種情況是我的代碼是否正確?

+0

這代碼什麼也沒做,所以什麼也沒有發生...... –

+0

aww難怪..大聲笑..謝謝指出。我現在開始工作了。 –

+0

真遺憾我沒有發佈這個答案......這可能是我最有趣的答案。 –

回答

1

好,亞歷克斯指出,我並沒有真正啓動按鈕按下..現在,他指出這一點我能解決我的代碼..這是我現在使用:

Private Declare Auto Function FindWindow Lib "user32.dll" (_ 
ByVal lpClassName As String, _ 
ByVal lpWindowName As String _ 
) As IntPtr 

Private Declare Auto Function FindWindowEx Lib "user32.dll" (_ 
ByVal hwndParent As IntPtr, _ 
ByVal hwndChildAfter As IntPtr, _ 
ByVal lpszClass As String, _ 
ByVal lpszWindow As String _ 
) As IntPtr 

Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr 
Private Const BM_CLICK = &HF5 


    Dim hwndParent As Long = FindWindow(vbNullString, ListView4.SelectedItems(0).SubItems(3).Text) 
    Debug.Print("findwindow: " & hwndParent) 
    Dim hwndButton As Long = FindWindowEx(hwndParent, IntPtr.Zero, "Button", "Save as") 
    Debug.Print("OK: " & hwndButton) 
    hwndButton = SendMessage(hwndButton, BM_CLICK, 0, 0) 
    Debug.Print("Clicked: " & hwndButton)