Thread: screen capture in c

  1. #1
    c_new_32
    Guest

    Question screen capture in c

    ok people i am a neewby to c but i do know how to program in it im saying im not an expert but i can use it

    any way i want to make a screen captureing program can someone provide me with some source that will copy the screen to the clip board for the user to paste in ms paint

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    Search Google for your answer. There's probably a winapi function which will capture the screen. Look for the keywords: winapi screen capture

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    This function captures any window on screen and saves it to the clipboard:

    Code:
    #define RectWidth(lprc)  ((lprc)->right-(lprc)->left)
    #define RectHeight(lprc) ((lprc)->bottom-(lprc)->top)
    
    void CaptureWindow(HWND hwnd){
     HDC hdc,hdcMem;
     HBITMAP hbm,oldbm;
     RECT rc,rcCrop;
     hdc=GetWindowDC(hwnd);
     hdcMem=CreateCompatibleDC(hdc);
     SelectBitmap(hdcMem,oldbm);
     GetWindowRect(hwnd,&rc);
     SetRect(&rcCrop,0,0,RectWidth(&rc),RectHeight(&rc));
     hbm=CreateCompatibleBitmap(hdc,RectWidth(&rcCrop),
      RectHeight(&rcCrop));
     oldbm=SelectObject(hdcMem,hbm);
     BitBlt(hdcMem,0,0,RectWidth(&rcCrop),
      RectHeight(&rcCrop),hdc,0,0,SRCCOPY);
     OpenClipboard(hwnd);
     EmptyClipboard();
     SetClipboardData(CF_BITMAP,hbm);
     CloseClipboard();
     ReleaseDC(hwnd,hdc);
     DeleteDC(hdcMem);
     DeleteObject(oldbm);
    }
    To capture the screen, call:

    CaptureWindow(GetDesktopWindow());

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    98
    i have another question on this. can the print screen button on the keyboard be used somehow to achieve this?i mean can the button be emulated somehow in a program?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  2. What is the code to capture the screen?
    By laar in forum C++ Programming
    Replies: 2
    Last Post: 12-15-2005, 07:53 PM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  5. Screen capture problem....my code!(PLEASE READ!)
    By SyntaxBubble in forum Windows Programming
    Replies: 0
    Last Post: 05-02-2002, 05:07 PM