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

Get active GUI of OS using .net 2.0

Author: Zunnair

This Article demonstrates the ability to overload several definitions to a Win32API call. Depending on which fields you fill in for windows caption and class name, one of four different definitions.

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. Show window: This demonstration allows the user to type in a window caption and/or class name, and bring the window to the foreground. The emphasis is on overloading multiple types of parameters to one WinAPI function to allow passing different types of variables to the function.

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


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

End If

        If hWnd = 0 Then

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



If Win32API.IsIconic(hWnd) Then

     Win32API.ShowWindow(hWnd, Win32API.SW_RESTORE)


     Win32API.ShowWindow(hWnd, Win32API.SW_SHOW)

   End If

   End If

 End Sub


Some Helpful Points


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 How we can Show Any Window or call any window like calculater etc. There are many other Concepts regarding Win32 API in I will Explain Others in Later Parts.




Add Article Comment:
Name :
Email Address :
Comments :
<< Getting Active Visual windows of OS using Windows32 API .Net 2.0

Disclaimer - Privacy
© 2002-2017