Whether you are online or offline. I don’t think this can be practically applied anywhere, but I thought it would be fun.
For this tutorial you need to have a basic understanding of FindWindowEx and IsWindowVisible API.
First you need to add InteropServices and Diagnostics namespaces.
Imports System.Diagnostics Imports System.Runtime.InteropServices
The InteropServices namespace provides a wide variety of members that support COM interop and platform invoke services.
The Diagnostics namespace provides access to local and remote processes.

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.
First you need to find the handle of panel “Sign In Dialogue”. For finding the handle you need to know the class of the child window.
You can use Spy++ to find the class name.

If you look in the figure “Google Talk – Google Xmpp Client GUI Window” is the parent window who has a child control “Main View” who in turn has a child control “#32770″.
You need to declare FindWindowEx Api to find the child handle and IsWindowVisible Api to find the visibility of the panel.
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr,ByVal childAfter As IntPtr,ByVal lclassName As String,ByVal windowTitle As String) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function IsWindowVisible(ByVal hWnd As IntPtr) As Boolean
End Function
Now here goes the main code.
If Process.GetProcessesByName("googletalk").Length = 0 Then
MessageBox.Show("Google Talk is not running.", "Alert")
Else
Dim hwnd As IntPtr
Dim boolCheck As Boolean
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")
boolCheck = IsWindowVisible(hwnd)
If boolCheck Then
MessageBox.Show("User is offline.", "Alert")
Else
MessageBox.Show("User is online.", "Alert")
End If
End If
Before finding the parent and child handle we need to check if Google Talk is running. We need to pass the process name as parameter to GetProcessesByName() method of Process class.
If Process.GetProcessesByName("googletalk").Length = 0 Then
MessageBox.Show("Google Talk is not running.", "Alert")
End If
If the process exists then we need to find the handle to the child control.
Dim hwnd As IntPtr 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")
Now once we have the handle of the child window, we need to pass that handle as argument to IsWindowVisible API which returns true if the child control is visible or returns false if the child control is not visible.
boolCheck = IsWindowVisible(hwnd)
If boolCheck=True then
MessageBox.Show("You are offline","Alert")
Else
MessageBox.Show("You are online","Alert")
End If
Download Source Code






MultiQuote


|