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.
Printable View
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.
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.
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
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
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.
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; }