Click here to Skip to main content
15,885,981 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
How to switch to desktop programaticaly?
EDIT: Without minimizing opened windows, just like you left_click on it.
Posted
Updated 15-Mar-11 3:42am
v2
Comments
Henry Minute 15-Mar-11 10:19am    
Why would you want to do this? It sounds suspicious.
Perhaps, if you edit your question to explain exactly what it is you are trying to do and why, you may get more answers.
Toli Cuturicu 15-Mar-11 11:34am    
I second Henry Minute.
Why??
Sergey Alexandrovich Kryukov 15-Mar-11 11:58am    
I guess this is what "Show desktop" does and I know the answer. Please see.
I never done this programmaticall but I don't think this is a big problem.
--SA
Sergey Alexandrovich Kryukov 15-Mar-11 12:02pm    
And I found C# sample.
--SA

1 solution

You can do something very similar.
You can run the following file from Shell:

[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
Command=ToggleDesktop


The extension of such file is "SCF", for example, the name would be "Show Desktop.SCF". Just create a file and click it.

When you run such file, you can get pretty much what you want.

I'm sure you can do it programmatically. First, try to make and run this file and see if this is what you want.
If found the following C# sample:
http://blogs.msdn.com/b/robgruen/archive/2004/02/24/79294.aspx[^].

—SA
 
Share this answer
 
v4
Comments
Sergey Alexandrovich Kryukov 15-Mar-11 15:17pm    
The one who voted 2: did you read the Answer and the reference? :-)
--SA
[no name] 15-Mar-11 15:19pm    
For sending hot-keys to explorer. ((Shell32.IShellDispatch4)objShel).RefreshMenu() - exactly what was need before SendKeys(), and avoid minimizing active windows. And of course need to use Thread.Sleep(at least 200) before SendKeys();
Thanks!
Sergey Alexandrovich Kryukov 15-Mar-11 16:47pm    
I don't think sleeping is robust. What if it is 201? :-)
I would think there is much better solution. Also, SendKeys is pretty bad, not always works. What does work is (via P/Invoke) Windows API SendInput. Could you clarify a situation a bit. What is the input, in which application? Surely, source code not accessible to you, right? What a key press should do? Why "RefreshMenu" and not "ShowDesktop".

It's just if you hope to get more help...

Thank for accepting my Answer...
--SA
KUMAR619 1-Aug-15 11:13am    
@SA I have a question for you regarding focussing.
I need to make my exe(applicaiton lose its focus).
When I calick on link another application pops up.
As soon as I click my old exe which is visible by its edges its not focussing.

I come to know that the taskbar icon is still highlighting the old exe even if the new exe is on top. How to make the old exe lose its focus.

Thanks in advance
Sergey Alexandrovich Kryukov 1-Aug-15 13:31pm    
"Focusing" is the state of a control, not an application; this is actually always a keyboard focus, which is only one per the whole desktop. You need to describe your scenario in detail and ask a separate question.
—SA

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