2010-06-22 50 views
1

我正在嘗試創建一個程序來顯示我的Gtalk(在線/離線)狀態。GoogleTalk的查找狀態

alt text

我能找到狀態視圖2類,但我怎麼能找到其中的文本。

這是我的代碼。

API decleration:調用阿比

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] 
private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle); 

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

代碼:

IntPtr hwnd = IntPtr.Zero; 

hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Google Talk - Google Xmpp Client GUI Window", "Google Talk"); 

hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Main View", "@main"); 

hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Status View 2", "Status Box"); 

hwnd = FindWindowEx(hwnd, IntPtr.Zero, "RichEdit20W", "String.Empty"); 

MessageBox.Show(hwnd.ToString()); 

感謝。

回答

2

我找到了一個我自己的解決方案。感謝abazabam

alt text

如果你看一下這個數字,有一個面板類名爲「#32770」和窗口標題是「登錄對話」

當用戶離線那麼這個面板可見,並且當用戶上線時,該面板不可見。

所以主要邏輯是檢測面板的可見性。

您可以使用Spy ++來查找類名稱。

alt text

API decleration:

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] 
private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle); 

[DllImport("user32.dll", CharSet = CharSet.Auto)] 
public static extern bool IsWindowVisible(IntPtr hWnd); 

代碼:

IntPtr hwnd = IntPtr.Zero; 

bool check; 

hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Google Talk - Google Xmpp Client GUI Window", "Google Talk"); 

hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Main View", "@main"); 

hwnd = FindWindowEx(hwnd, IntPtr.Zero, "#32770", "Sign In Dialogue"); 

check = IsWindowVisible(hwnd); 

if (check == true) 
{ 
    MessageBox.Show("User is offline."); 
} 
else 
{ 
    MessageBox.Show("User is online."); 
} 

反正感謝您閱讀我的問題。