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;
}