top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Get active GUI of OS using .net 2.0?

0 votes
332 views
How to Get active GUI of OS using .net 2.0?
posted Feb 4, 2016 by Sathyasree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
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

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.

answer Feb 4, 2016 by Shivaranjini
Similar Questions
0 votes

How to get all values along with control Id using Jquery in ASP.NET?

+4 votes

How to Generic Method to Create and Execute Parameterized SQL Query in .NET 4.0 ?

+2 votes

How to use Zip operator in Linq with .NET 4.0?

+4 votes

How to Automate Web Browser using VB.NET?

...