查找 GoogleTalk 的状态

发布于 2024-09-06 19:10:22 字数 1037 浏览 2 评论 0原文

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

alt text

我可以找到 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());

谢谢。

I am trying to create a program which will show me the status of my Gtalk (online/offline).

alt text

I can find the Status View 2 class, but how can I find the text within it.

Here's my code.

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

Code that calls 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());

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫雨熙 2024-09-13 19:10:22

我自己找到了解决方案。感谢 abazabam

alt text

如果你看图,有一个面板,其类名为“ #32770”,窗口标题是“登录对话框”。

当用户离线时,该面板可见,而当用户上线时,该面板不可见。

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

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

alt text

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

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

I found a solution my self. Thanks to abazabam.

alt text

If you look at the figure, there is a panel whose class name is "#32770" and Window Caption is "Sign In Dialogue"

When the user is offline then this panel is visible, and when the user goes online the panel is not visible.

So the main logic is to detect the visibility of the panel.

You can use Spy++ to find the class name.

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

Code :

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

Anyways thanks for reading my problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文