Link to home
Start Free TrialLog in
Avatar of alwayscy
alwayscy

asked on

How to minimize all windows on TaskBar except my one?

EnumWindow and send WM_SYSCOMMAND message is not the right way.
Avatar of MichaelS
MichaelS

EnumWindows and than ShowWindow(hwnd, SW_MINIMIZE);
Avatar of alwayscy

ASKER

MichaelS,
I already try this in W2k,you will see a strange result!I have to restart my computer.
I think EnumWindows also enum many system process's windows.
I only want the windows in the taskbar.
Than when you get the handle of window you call something like IsWindowVisible() and if so than minimize it.
Shure you don't have to minimize systray window, may be you can do some exeptions.
Avatar of Zoppo
You even have to avoit to hide/minimize the desktop's window...
I was thinking to send WM_COMMAND message to explorer which it gets when you select "Minimize All Windows" in right mouse click menu on taskbar but was not able to catch it somehow with spy :( May be you can spend more time on it, than I think you just sent that message and restore your own window.
hi,
the correct way would be enumwindows,iswindowvisible etc but you can also cheat and use the shell to do it.
for me in delphi or c++ builder i would do like

var
oShell : OleVariant;
begin
oShell := CreateOleObject('Shell.Application');
oShell.MinimizeAll;

im sure you can do same in vb etc..
you might take a look at...

https://www.experts-exchange.com/jsp/qShow.jsp?qid=20120597

it's vb code ( really just api calls, though...so no problem to port over)...then send the appropriate messages to your application to restore.


Option Explicit

Private Const WM_COMMAND& = &H111
Private Const MIN_ALL& = 419
Private Const MIN_ALL_UNDO& = 416

Private Declare Function findwindow _
   Lib "user32" Alias "FindWindowA" ( _
       ByVal lpClassName$, _
       ByVal lpWindowName$ _
   ) As Long

Private Declare Function postmessage _
   Lib "user32" Alias "PostMessageA" ( _
       ByVal hWnd&, _
       ByVal wMsg&, _
       ByVal wParam&, _
       ByVal lParam& _
   ) As Long


Public Sub main()
Dim hWnd&

   hWnd& = findwindow("Shell_TrayWnd", vbNullString)
   postmessage hWnd&, WM_COMMAND&, MIN_ALL&, 0&
End Sub
As I understand it -you want to minimize all windows except yours to the taskbar - is that correct ??

If it is I have the coding solution - written in C - easily converted to C++ or MFC

I need 500 points plus an "A" grade

Agree ??

DarrinE
Also includes how to properly minimize and maximize the windows like using the windows key + m (minimize all)

DarrinE
>I need 500 points plus an "A" grade

And all other experts just had fun here :)
DarrinE, I think your habit to bargain for points
and grades before offering a solution (and without
any reference that you are able to find one) is really
cheeky and I hope that alwayscy won't do it ...
do you really think a function which does what he
needs is worth 500 points (=50$)?

If so, I think you're wrong at this site.

As MichaelS says...

EnumWindows(EnumWindowsProc,(LPARAM)hMyWnd);

...and...

BOOL CALLBACK EnumWindowsProc(HWND hWnd,LPARAM hMyWnd)
{
    if (IsWindowVisible(hWnd) && hWnd!=(HWND)hMyWnd)
        ShowWindow(hWnd,SW_MINIMIZE);
}

... is there any problem with this?
Heres an improved version...



BOOL CALLBACK EnumWindowsProc(HWND hWnd,LPARAM hMyWnd)
{
    DWORD style=GetWindowLong(hWnd,GWL_STYLE);

    if ((style&WS_VISIBLE) && (style&(WS_POPUP|WS_CHILD))==0)    
       ShowWindow(hWnd,SW_MINIMIZE);

    return TRUE;
}

//
{    
    ANIMATIONINFO ai;
    int oldVal;
   
    // Turn off window animation
    ai.cbSize=sizeof(ai);
    SystemParametersInfo(SPI_GETANIMATION,sizeof(ai),&ai,FALSE);    
    oldVal=ai.iMinAnimate;
    ai.iMinAnimate=0;
    SystemParametersInfo(SPI_SETANIMATION,sizeof(ai),&ai,FALSE);    
   
    // Minimize all except self
    EnumWindows(EnumWindowsProc,hMyWnd);
   
    // Restore window animation
    ai.iMinAnimate=oldVal;
    SystemParametersInfo(SPI_SETANIMATION,sizeof(ai),&ai,FALSE);
}
ASKER CERTIFIED SOLUTION
Avatar of robpitt
robpitt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry for posting twice - blasted buggy site!
First,thanks for everyone here!

Now I use spy catch the WIN+M message.
It's a WM_HOTKEY whith a 'WIN+M' in wparam and (x,y) of mouse in lparam.
I send it to 'Shell_TrayWnd'.It's just like someone press 'WIN+M'.

Thank you again!

But I can't divide points to many parts...
robpitt's version also do this.
using any these does not prevent "your window" from not being minimized - thats what I thought you wanted

as for bargaining .... its been done here before by some of the leading experts such as NickRepin, Madshie and others

I know what I have works - its used in a dozen of my commercial programs

MichaelS - ShowWindow(hwnd, SW_MINIMIZE) is the slowest way to minimize a series of windows

the following is the actual code to minimize all and restore all like the "win + m" hotkey - dont ever say you never get something for nothing (the example is in C)

#include <SHDOC401.H>

BOOL WINAPI MinimizeAll(void)
{
    IShellDispatch *pSD;

    CoInitialize(NULL);

    if (SUCCEEDED(CoCreateInstance(&CLSID_Shell,
                                   NULL,
                                   CLSCTX_SERVER,
                                   &IID_IShellDispatch,
                                   (LPVOID *)&pSD)))
    {
        pSD->lpVtbl->MinimizeAll(pSD);
        pSD->lpVtbl->Release(pSD);
    }

    CoUninitialize();

    return 0;
}




BOOL WINAPI UndoMinimizeALL(void)
{
    IShellDispatch *pSD;

    CoInitialize(NULL);

    if (SUCCEEDED(CoCreateInstance(&CLSID_Shell,
                                   NULL,
                                   CLSCTX_SERVER,
                                   &IID_IShellDispatch,
                                   (LPVOID *)&pSD)))
    {
        pSD->lpVtbl->UndoMinimizeALL(pSD);
        pSD->lpVtbl->Release(pSD);
    }

    CoUninitialize();

    return 0;
}



this is not what alwayscy  wanted - if he wants the code to do what he wants then he cant post a comment, perhaps he doesnt have the points but can offer more than 50 point I dont know

DarrinE
Of course the IShellDispatch method (or faking it with a Win+M keypress) only works if shell32.dll v4.71 (IE4) or later has been installed.

As for not minimising "your window" that was why I included hMyWnd in my code, I just forgot to add the test for it e.g. if (hWnd!=hMyWnd)


Rob
>Now I use spy catch the WIN+M message.
It's a WM_HOTKEY whith a 'WIN+M' in wparam and (x,y) of mouse in lparam.
I send it to 'Shell_TrayWnd'.It's just like someone press 'WIN+M'.

ummm...sounds familiar.