2017-09-03 39 views
2

我有一個第三方應用程序,我沒有創建自己。我需要創建一個應用程序,它可以偵聽按鈕點擊並從該應用程序中的表中讀取數據。我相信第三方應用程序是用C#編寫的,但我不確定。有沒有辦法知道何時按下UI按鈕並從應用程序收集數據?我不介意解決方案必須寫入哪種編程語言,只要它滿足上述任務即可。從其他Windows應用程序捕獲事件

+0

你能訪問其他應用程序源代碼嗎? – z3nth10n

+0

不,它是從互聯網下載的,我試圖創建一種界面,更清晰地顯示該應用程序中的數據,並在第三方按下按鈕時執行操作。 – JPadley

回答

1

您可以使用少量DLL(如user32.dll)從其他應用程序獲取數據。 查找父句柄窗口:

[DllImport("user32.dll", SetLastError = true)] 
static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 

public static IntPtr FindWindow(string windowName) 
{ 
    var hWnd = FindWindow(windowName, null); 
    return hWnd; 
} 

之後,找到一個子窗口

[DllImport("user32.dll", SetLastError = true)] 
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle); 

private IntPtr FindSomeElement(IntPtr parent) 
{ 
    IntPtr childHandle; 

childHandle = FindWindowEx(
    parent,  
    IntPtr.Zero,  
    "WindowsForms10.EDIT.app21", 
    IntPtr.Zero); 
return childHandle;} 

的把手,從它那裏得到的文本:

private static string GetText(IntPtr childHandle) 
{ 
    const uint WM_GETTEXTLENGTH = 0x000E; 
    const uint WM_GETTEXT = 0x000D; 

    var length = (int)SendMessage(handle, WM_GETTEXTLENGTH, IntPtr.Zero, null); 
    var sb = new StringBuilder(length + 1); 
    SendMessage(handle, WM_GETTEXT, (IntPtr)sb.Capacity, sb); 
    return sb.ToString(); 
} 

//我沒有測試這個代碼,只是給出了一個想法。 有關更多信息,請訪問www.pinvoke.net/default.aspx/。你可以找到很多關於user32.dll的信息

+0

也SPY ++會幫助你獲得元素類名稱或主窗口類名稱。 –

+0

這是用什麼語言寫的? – JPadley

+0

@JPadley,它的c# –

相關問題