Ive created (transformed) this little program to close every window with one click when i finished to work,surf etc...
I put a check for "C:\\Documents" to avoid that it close itself before closing other
programs.
It works great only for a little time it gives a black screen for a few seconds when closing the windows. It didnt do it before.
I hope i havent done something wrong.
Thanks for any input on it.
Code:
#include <windows.h>
#define ARRAYSIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
BOOL IsAltTabWindow(HWND hwnd)
{
LONG_PTR exStyles = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
// Start at the root owner
HWND hwndWalk = hwnd;
// appwindows treated as no owner, so don't try and find one
if(!(exStyles & WS_EX_APPWINDOW))
{
hwndWalk = GetAncestor(hwnd, GA_ROOTOWNER);
}
// See if we are the last active visible popup
HWND hwndTry = hwndWalk;
while ((hwndTry = GetLastActivePopup(hwndWalk)) != hwndTry) {
if (IsWindowVisible(hwndTry)) break;
hwndWalk = hwndTry;
}
// tool windows are treated as not visible so they'll never appear in the list
// fail them here
return (hwndWalk == hwnd) && !(exStyles & WS_EX_TOOLWINDOW);
}
BOOL CALLBACK Enum(HWND hwnd, LPARAM lParam)
{
if(IsAltTabWindow(hwnd) && IsWindowVisible(hwnd))
{
CHAR Buff[260];
GetWindowText(hwnd, Buff, ARRAYSIZE(Buff));
if(strncmp(Buff,"C:\\Documents",6) != 0) PostMessage( hwnd, WM_CLOSE, 0, 0 );
}
return TRUE;
}
int __cdecl main()
{
EnumWindows(&Enum, 0);
}