tags:

views:

93

answers:

1

Hi,

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.

+2  A: 

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.

Searock