Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Checking Active Windows of Operating System using VB.net

Author: Zunnair
Download Source Code : 744_Sample1.zip

This Article helps to check the active windows of Your Operating System. In many professional applications we need this kind of services. which very helpful and interesting.

Whenever we want to Access the windows authentication we have to use Win32 APIs .Because Microsoft Gives us his own way because Microsoft wants no disturbance in its Performance due to your access. 

Each of the Win32 API functions and constants have been wrapped up in the Win32API class for use in each demonstration.

Active windows: This fills a listbox with all active visual windows, by filtering the results of the callback function, EnumWindows using various Win32 API functions. In this example EnumWindows is defined using DllImport instead of Declare to contrast the difference between using the two methods.

 

Lets start Understanding by using Code it is recommended that with this explanation please run application First. And try to understand because helpful Comments are written there.

 

 

Private Sub btnRefreshActiveWindows_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefreshActiveWindows.Click

 

lbActiveWindows.Items.Clear()

Win32API.EnumWindowsDllImport(New Win32API.EnumWindowsCallback(

AddressOf _FillActiveWindowsList), 0)

End Sub

 

 

This subroutine clears the active windows list and fills it with all active windows.

 

EnumWindowDllImport works the same as in btn Refresh Active Processes Click however, it is defined using DllImport instead of Declare.

 

There are four overloads for the Win32API function FindWindow in the Win32API class, allowing either a String or an Integer to be passed to the class name and window name.  If either of the fields are blank, passing a 0 to the parameter marshalls NULL to the function call.

 

 

Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click

 

Dim hWnd As Integer

If txtWindowCaption.Text = "" And txtClassName.Text = "" Then

     hWnd = Win32API.FindWindowAny(0, 0)

ElseIf txtWindowCaption.Text = "" And txtClassName.Text <> "" Then

hWnd = Win32API.FindWindowNullWindowCaption(txtClassName.Text, 0)

ElseIf txtWindowCaption.Text <> "" And txtClassName.Text = "" Then

      hWnd = Win32API.FindWindowNullClassName(0, txtWindowCaption.Text)

Else

   hWnd = Win32API.FindWindow(txtClassName.Text, txtWindowCaption.Text)

End If

        If hWnd = 0 Then

MsgBox("Specified win not running.", MsgBoxStyle.Exclamation, Me.Text)

Else

     Win32API.SetForegroundWindow(hWnd)

If Win32API.IsIconic(hWnd) Then

     Win32API.ShowWindow(hWnd, Win32API.SW_RESTORE)

Else

     Win32API.ShowWindow(hWnd, Win32API.SW_SHOW)

   End If

   End If

 End Sub

 

 

1-FindWindowAny takes to Integer parameters and finds any available window.

 

2-FindWindowNullWindowCaption attempts to locate a window by class name alone.

 

3-FindWindowNullClassName attempts to locate a window by window name alone.

 

4-FindWindow searches for a window by class name and window name.

 

If the window isn't found FindWindow sets the windows handle to 0.  If the handle is 0 display an error message, otherwise bring window to foreground.

 

Win32API.SetForegroundWindow (hWnd) set the window as foreground.

If window is minimized, simply restore, otherwise show it.  Notice the

declaration of Win32API.IsIconic defines the return value as Boolean

allowing .NET to marshall the integer value to a Boolean.

 

in this Article I tried to explain Active Visual Windows Showing, there are many other Concepts regarding Win32 API in VB.net  

 

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Working with Client-Server Error Handling using VB.net

Disclaimer - Privacy
© 2002-2017 DevASP.net