Thread: Minimize all windows...

  1. #1
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69

    Talking Minimize all windows...

    How would I minimize all the open windows from within a C program? I want the desktop to have the focus. How do I do this? I have tried SetForegroundWindow(), SetFocus(), and SetActiveWindow() and I still can not make it work.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    You will need to use EnumWindows() to get a list of all open windows.
    Once you have the list you need to check IsWindowVisible() to find the ones that are showing.
    Then ShowWindow() will let you minimize them.
    Finally GetDesktopWindow() and SetFocus() will allow you to give the desktop focus.

  3. #3
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    How about an example? actually, I can figure out all the functions except EnumWindows(). Could you give me an example snippet of code that would use that function?
    Compiler: GCC

  4. #4
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Here's one. Don't worry, I've also little idea of what I was trying to accomplish with it. Still, shows you how it can be used. Or you could just use SendInput to send Win+D
    Last edited by adeyblue; 04-20-2011 at 05:16 PM.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Benji Wiebe View Post
    How about an example? actually, I can figure out all the functions except EnumWindows(). Could you give me an example snippet of code that would use that function?
    Compiler: GCC
    The documentation at MSDN is fairly complete...
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    Google is your friend.

    Basically the EnumWindows() function cycles through the Zorder giving window handles to it's callback procedure one at a time. The callback is written by you... That's where you determine if a window is visible and call the ShowEindow() function with SW_MINIMIZE to close itl down into the taskbar.
    Last edited by CommonTater; 04-20-2011 at 05:46 PM.

  6. #6
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    CommonTater, I already looked at MSDN. Couldn't make any sense out of it.
    Thanks a lot, adeyblue.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Benji Wiebe View Post
    CommonTater, I already looked at MSDN. Couldn't make any sense out of it.
    Thanks a lot, adeyblue.
    Here's a real simple example that just lists the window handles...

    Code:
    #include <windows.h>
    #include <stdio.h>
    
    
    BOOL CALLBACK EnumProc(HWND win, LPARAM lp)
      { printf("%X\t", (UINT_PTR) win);
        return TRUE; }
    
    
    int main (void)
      { 
    
      EnumWindows(&EnumProc,0);
    
        return 0; }
    Last edited by CommonTater; 04-20-2011 at 06:25 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. redraw after minimize
    By Prads in forum Windows Programming
    Replies: 6
    Last Post: 03-21-2010, 11:16 AM
  2. minimize executable size
    By heisel in forum C Programming
    Replies: 10
    Last Post: 09-10-2009, 09:00 AM
  3. How can I minimize the console?
    By manugarciac in forum C++ Programming
    Replies: 2
    Last Post: 05-06-2007, 09:37 PM
  4. minimize and maximize
    By Wick in forum Windows Programming
    Replies: 2
    Last Post: 08-20-2003, 10:37 PM
  5. Minimize itself?
    By MassKid in forum C Programming
    Replies: 4
    Last Post: 02-06-2002, 06:47 AM