Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How can i minimize all other application windows when my application run.
i want only my application window on the screen.all othes applications should be minimized.
Posted

Hi Raj try this!!!! A simple Way

Shell32.ShellClass objShel = new Shell32.ShellClass();
            ((Shell32.IShellDispatch4)objShel).ToggleDesktop();
 
Share this answer
 
v2
Comments
Tarun.K.S 2-May-11 7:03am    
Wrap your code with <pre> tags.
RAJI @Codeproject 2-May-11 7:20am    
I want this..thank you all for helping me!!
Member 10459063 17-Jul-14 1:29am    
Error: The type or namespace name 'Shell32' could not be found (are you missing a using directive or an assembly reference?)
Not a very good idea (why just sending your application on top is not enough?), but…

You need to be able to minimize a window by its HWND. To do this, use P/Invoke and Windows API SetWindowPlacement, see http://msdn.microsoft.com/en-us/library/ms633544(v=vs.85).aspx[^]. Let's assume you did it and wrapped it in a method MinimizeWindow(System.IntPtr hwnd).

Now, where to get all windows?

I would prefer using pure .NET library, not more P/Invoke:
C#
static void MinimizeAll() {
   System.Diagnostics.Process thisProcess =
      System.Diagnostics.Process.GetCurrentProcess();
   System.Diagnostics.Process[] processes =
      System.Diagnostics.Process.GetProcesses();
   foreach (System.Diagnostics.Process process in processes) {
      if (process == thisProcess) continue;
      System.IntPtr handle = process.MainWindowHandle;
      if (handle == System.IntPtr.Zero) continue;
      MinimizeWindow(handle);
   } //loop
} //MinimizeAll


That's it. Pretty simple, isn't it?

—SA
 
Share this answer
 
v3
Comments
Sandeep Mewara 2-May-11 6:54am    
5+ for it. Agreed yet would not use an application doing this.

:)
Sergey Alexandrovich Kryukov 2-May-11 7:32am    
Thank you, Sandeep.
Do you think I'll do it? Answering is one thing, doing it right is... :-)
--SA
Sandeep Mewara 2-May-11 9:17am    
Yep, I think you won't.
But for a change, you gave a solution for what you also find should not be done. :)
Sergey Alexandrovich Kryukov 2-May-11 13:51pm    
Exactly. I agree with you when it's some real-life project of my own, as to the OP's request -- why not having some fun? I honestly posted my "not a good idea" working, so...

By the way, I cannot remember, do I tell me about my "[Completely Useless Challenge]" initiative? I thought I told you. This is in my only CodeProject Question (see from my profile). You see, from time to time I do something useless...

--SA
Sandeep Mewara 3-May-11 0:49am    
Yes you told me. :)

I would not say that "useless" or your time spent on 'useless' something. :)
As a user, I would never like such thing. I would not like any application minimizing my other windows without my consent.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-May-11 6:51am    
I agree with you and criticize the idea in my answer. Voted 5 for yours.

However, I decided to present the solution as it can show generally helpful technique, please see. How do you like it?
--SA
Tarun.K.S 2-May-11 7:02am    
Agreed. 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900