Thread: My little program

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    932

    My little program

    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);
    }
    Last edited by Ducky; 05-02-2009 at 12:26 PM.
    Using Windows 10 with Code Blocks and MingW.

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    IsAltTabWindow is wrong.
    See Explorer source code....

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    What is "Explorer source code" ?
    Using Windows 10 with Code Blocks and MingW.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM