我正在尝试创建一个程序,它会告诉我Gtalk的状态(在线/离线)。
我可以找到Status View 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);
调用Api的代码:
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());
感谢。
答案 0 :(得分:2)
我找到了解决方案。感谢abazabam。
如果你看一下这个图,有一个小组的名字是“#32770”,而且窗口标题是“登录对话”
当用户离线时,此面板可见,当用户上线时,该面板不可见。
因此,主要逻辑是检测面板的可见性。
您可以使用Spy ++查找班级名称。
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.");
}
无论如何感谢您阅读我的问题。