How do I minimize all desktop applications?

This is a discussion on How do I minimize all desktop applications? within the Windows Programming forums, part of the Platform Specific Boards category; I was trying to broadcast a system message to minimize all regular applications( i.e. active and visible ones only ), ...

  1. #1
    Registered User HelpfulPerson's Avatar
    Join Date
    Jun 2013
    Location
    Over the rainbow
    Posts
    288

    How do I minimize all desktop applications?

    I was trying to broadcast a system message to minimize all regular applications( i.e. active and visible ones only ), but apparently today is not my day for WinAPI coding. I have crashed my computer in my 3 attempts to debug it and test it. I will list each problem below.

    1) Drivers fully crashed except for a few, had to use command prompt to log off.
    2) Drivers partially crashed and I had to log off again through command prompt/ the start menu
    3) ( present ) All processes minimized, as intended, but the problem was that Windows took me too literally. Every process, regardless of status, responded to the message. It then crashed everything including my start menu and minimized every hidden application.

    Seeing as my track record isn't looking too nice so far, I came here to ask for help before I blow up my computer somehow trying to minimize applications. My desired result is to just minimize the applications that are visible and that the user is currently using to make my application the active window. Of course, this is kind of overkill, but I'm also doing it just to understand how to send messages. If you can help me achieve the desired effect, that would be spectacular.

    Code:
    /* Preprocessor directives */
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    
    #include <process.h>
    #include <windows.h>
    
    
    #include <fcntl.h>
    #include <io.h>
    #include <tlhelp32.h>
    #include <tchar.h>
    
    
    /* *********************************************************** */
    
    
    void win_error( char * message, DWORD error_code )
    {
        char error_buffer[BUFSIZ] = {0};
        sprintf( error_buffer, "%s : %d", message, ( int )error_code );
        MessageBox(NULL, error_buffer, "Error from System :", MB_ICONWARNING | MB_OK );
    
    
        exit( error_code );
    }
    
    
    /* *********************************************************** */
    
    
    int main( )
    {
        DWORD message_receivers = BSM_APPLICATIONS;
    
    
        if ( BroadcastSystemMessage( BSF_IGNORECURRENTTASK | BSF_POSTMESSAGE, &message_receivers, WM_SYSCOMMAND, SC_MINIMIZE, 0 ) <= 0 )
            win_error( "BroadcastSystemMessage : ", GetLastError( ) );
    
    
        return 0;
    }
    "Some people think they can outsmart me, maybe. Maybe. I've yet to meet one that can outsmart bullet" - Meet the Heavy, Team Fortress 2

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,198
    Look up EnumWindows for enumerating over all top level windows on the screen. EnumWindows() requires a callback function. In that callback, simple use SendMessage(handle, WM_SYSCOMMAND, SC_MINIMIZE, 0) [one of the arguments of the callback is a windows handle).

    There are plenty of other ways, but this one is arguably the simplest.
    Right 98% of the time, and don't care about the other 3%.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PrintWindow in .Net-applications in non-active desktop
    By rusvid in forum Windows Programming
    Replies: 0
    Last Post: 09-04-2012, 04:07 AM
  2. Get Installed applications list and applications activity
    By arunarora in forum C++ Programming
    Replies: 5
    Last Post: 05-25-2009, 09:41 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. desktop and distributed applications
    By moemen ahmed in forum C++ Programming
    Replies: 1
    Last Post: 06-29-2002, 04:56 PM
  5. Minimize itself?
    By MassKid in forum C Programming
    Replies: 4
    Last Post: 02-06-2002, 05:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21