The article will make use of the API " ShowWindow " from the user32 Dll and allow users to Minimise,Maximize and manuplate other windows from your DotNet Application
Introduction
The Following code will help you to minimize other Windows from your .NET Application.
To Demonstrate I have developed demo application 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
The Below Code in the Load Event Will Get the List of all Processes and Add it in the ComboBox
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,Maximize and other functions to Work We need to Define an API Method ShowWindow from user32.dll
<DllImport("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..
The Following Options can be used in the cmd parameter.
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 minimize 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
You can use the Other Options for other purpose.
For More Demonstration you can download the Full Project
Hope this Article Helped you.
Regards
Hefin Dsouza