Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 30023 |  Welcome, Guest!   Register  Login
Home > Articles > Windows Forms > Minimizing Other Windows From DotNet Application

Minimizing Other Windows From DotNet Application

Article posted by Initiotech on 9/20/2009 | Views: 4406 | Category: Windows Forms | Level: Intermediate red flag


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

Download


 Download source code for Minimizing Other Windows From 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

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

About Hefin Dsouza

Experience:8 year(s)
Home page:http://hefin.in
Member since:Wednesday, September 16, 2009
Level:Starter
Status: [Member]
Biography:My Name is Hefin Dsouza.
I am a faculty at Computer Education Institute.I am also an Freelance Software Developer and Software Trainner.I am working with DotNet Technologies from the past 8 years.I am an Microsoft Certified Windows Application Developer for .NET 3.5.
And also a Blogger at http://blog.hefin.in
>> Write Response - Respond to this post and get points
Related Posts

The Article explains the usage of FileSystemWatcher class in winforms for logging Deleting,Renaming,Modifications of files.

In this article explains you how to create Stopwatch Application using C#.

This article shows to you , how to creating a Text-to-Speech application using VB.Net with Visual Studio 2008.

In This article you will know how to start a mobile application on windows.

In Windows application development, we have few built-in extender components like ErrorProvider, Tooltip, etc. Extender component will add few more properties to built-in controls to enhance the functionality. In this article we will discuss about creating a custom extender component for Windows controls.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/28/2012 11:58:40 AM