2011-10-29 31 views
1

我有一個顯示信息的程序(簡單文本,但不是在txt框中,看起來像.NET中的標籤),但禁用了選擇並禁用了鼠標左鍵和右鍵單擊。解決已禁用的選項

我想寫一個用作用戶的另一個程序(可以用C#表示,但也可以是其他語言),並將第一個程序顯示的信息記錄在txt文件中。

有沒有一種方法,我可以避開禁用選擇,左鍵和右鍵點擊?

回答

2

GetWindowText窗口API是你的朋友:

[DllImport("user32.dll", EntryPoint = "GetWindowText", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)] 
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount); 

你會得到其他程序的窗口,然後循環的手柄上的所有子窗口/使用EnumChildWindows控制,然後獲取文本呼籲GetWindowText對所有這些句柄。在某些情況下,你不會得到我預期的結果,或者可能是某些控件沒有處理暴露。

[DllImport("user32")] 
[return: MarshalAs(UnmanagedType.Bool)] 
public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i); 

關於如何使用EnumChildWindows詳細信息和答案在這裏看到:

Why is EnumChildWindows skipping children?

也看看這裏的一些想法和例子... Why does GetWindowText hang with a "closed" handle but not with a random one

相關問題