1

我正在尝试创建一个程序来显示我的 Gtalk 的状态(在线/离线)。

替代文字

我可以找到 Status View 2 类,但如何找到其中的文本。

这是我的代码。

API 声明:

[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());

谢谢。

4

1 回答 1

2

我自己找到了解决方案。感谢阿巴扎巴姆

替代文字

如果你看图,有一个面板,其类名是“#32770”,Window Caption 是“Sign In Dialogue”

当用户离线时,此面板可见,而当用户联机时,此面板不可见。

所以主要的逻辑是检测面板的可见性。

您可以使用 Spy++ 来查找类名。

替代文字

API 声明:

[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.");
}

无论如何感谢您阅读我的问题。

于 2010-06-27T20:35:38.963 回答