Thread: Window Image Capture

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    26

    Window Image Capture

    Do you know how i can capture the image of each running window in the desktop?!
    I want to do something similar to Windows powertoy that show me the thumbnail of each active window.
    look at the attachment for an example

  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Ok this doesn't really screen capture anything. It just iterates through the active programs. What you are looking for is called EnumWindows. Here is the description:
    EnumWindows
    The EnumWindows function enumerates all top-level windows on the screen by passing the handle to each window, in turn, to an application-defined callback function. EnumWindows continues until the last top-level window is enumerated or the callback function returns FALSE.

    BOOL EnumWindows(
    WNDENUMPROC lpEnumFunc, // callback function
    LPARAM lParam // application-defined value
    );
    Parameters
    lpEnumFunc
    [in] Pointer to an application-defined callback function. For more information, see EnumWindowsProc.
    lParam
    [in] Specifies an application-defined value to be passed to the callback function.
    Return Values
    If the function succeeds, the return value is nonzero.

    If the function fails, the return value is zero. To get extended error information, call GetLastError.

    If EnumWindowsProc returns zero, the return value is also zero.
    And here is the description of the user defined enum proc:
    EnumWindowsProc
    The EnumWindowsProc function is an application-defined callback function used with the EnumWindows or EnumDesktopWindows function. It receives top-level window handles. The WNDENUMPROC type defines a pointer to this callback function. EnumWindowsProc is a placeholder for the application-defined function name.

    BOOL CALLBACK EnumWindowsProc(
    HWND hwnd, // handle to parent window
    LPARAM lParam // application-defined value
    );
    Parameters
    hwnd
    [in] Handle to a top-level window.
    lParam
    [in] Specifies the application-defined value given in EnumWindows or EnumDesktopWindows.
    Return Values
    To continue enumeration, the callback function must return TRUE; to stop enumeration, it must return FALSE.

    Remarks
    An application must register this callback function by passing its address to EnumWindows or EnumDesktopWindows
    And finally here is a simple sample code to show you how it all comes together:
    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    BOOL CALLBACK EnumProc(HWND hwnd,LPARAM lParam);
    
    int nNoWnd = 0;
    
    int main(void)
    
    {
        cout << "Enumerating..." << endl;
        EnumWindows((WNDENUMPROC) EnumProc,NULL);
        
        cout << "Total of " << nNoWnd << " windows" << endl;
     
        return 0;
    }
    
    
    BOOL CALLBACK EnumProc(HWND hwnd,LPARAM lParam)
    {
        char buff[MAX_PATH+1];
    
        if(GetWindowText(hwnd,buff,MAX_PATH+1) <= 0)
            cout << "\"No Title\"" << endl;
    
        else
            cout << buff << endl;
    
        nNoWnd++;
        
        
        return TRUE;
    }
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM