#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    8
    Rep Power
    0

    Lightbulb how to capture the screen


    how can i capture the screen image in C or C++
    regards
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    Something like this perhaps
    Code:
    void CaptureImage(void)
    {
        HDC hDC;
     
        // First get the Device Context of the desktop
        hDC = GetDC(NULL);
    
        // Now get the screen size
        SIZE size;
        size.cx = GetSystemMetrics(SM_CXSCREEN);
        size.cy = GetSystemMetrics(SM_CYSCREEN);
    
        // Now do a BitBlt
        HDC hMemDC = CreateCompatibleDC(hDC);
        HBITMAP hBitmap = CreateCompatibleBitmap(hDC, size.cx, size.cy);
        if (hBitmap) {
             HBITMAP hOldBmp = (HBITMAP) SelectObject(hMemDC, hBitmap);
            BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, SRCCOPY);
            SelectObject(hMemDC, hOldBmp);
            DeleteDC(hMemDC);        
            // hBitmap is now a handle to the screen capture. 
            // Do what you want with it here, before deleting it below.
            DeleteObject(hBitmap);
        }
        ReleaseDC(NULL, hDC);
    }
    The last part was off the top of my head and I haven't really tested it, but it should be pretty close to The Right Thing. Hope this helps :)
    Last edited by Scorpions4ever; June 26th, 2003 at 01:30 AM.

IMN logo majestic logo threadwatch logo seochat tools logo