.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> General >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Handling Other Windows From VB.NET(Minimize,Maximize etc)

Posted By:Hefin Dsouza       Posted Date: August 13, 2009    Points: 25    Category: General    URL: http://www.dotnetspark.com  
 

The Following code will help you to minimize other Windows from your .NET Application.
To Demonstrate I have developed a sample which will first get all the running process in the Combobox
Namespaces You Need to Import are

System.Diagnostics - For Processes
System.Runtime.InteropServices - For defining the API




For Each p As Process In Process.GetProcesses()
If (ComboBox1.Items.Contains(p.ProcessName) = False) Then
ComboBox1.Items.Add(p.ProcessName)
End If
Next



For the Minimize to Work We need to Define an API Method ShowWindow from user32.dll

_
Public Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal cmd As Integer) As Boolean
End Function

Once you have defined the API now its time to use it
Parameter Info
hwnd - The Window Handle on which the opperations will take place
cmd - An integer value which will hold the options wether to Minimise ,Maximise etc..

Hide = 0,
ShowNormal = 1,
ShowMinimized = 2,
ShowMaximized = 3,
Maximize = 3,
ShowNormalNoActivate = 4,
Show = 5,
Minimize = 6,
ShowMinNoActivate = 7,
ShowNoActivate = 8,
Restore = 9,
ShowDefault = 10,
ForceMinimized = 11*



Then I made a Button which will minimize all windows the code to Minimise all is

For Each p As Process In Process.GetProcesses()
ShowWindow(p.MainWindowHandle, 6)
Next

Then I made a button which will minimise Process selected from the combobox

Dim p() As Process = Process.GetProcessesByName(ComboBox1.SelectedItem)
For Each pr As Process In p
ShowWindow(pr.MainWindowHandle, 6) ' 6 used to Minimise
Next

Then I made a button which will maximise the Process selected from the combobox

Dim p() As Process = Process.GetProcessesByName(ComboBox1.SelectedItem)
For Each pr As Process In p
ShowWindow(pr.MainWindowHandle, 9) ' 9 used for Restoring
Next


Hope this Article Helped you.
Regards
Hefin Dsouza

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend