Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
3.57/5 (3 votes)
See more:
How can I set the CopyFromScreen picture of desktop to Image (or Bitmap) object?



Thanks
Posted
Updated 12-Dec-10 2:52am
v2

The print screen button?
 
Share this answer
 
HDC								hdc = GetDC(0);
HDC								mdc = CreateCompatibleDC(hdc);
HBITMAP						hbmpscreen;
BITMAPINFO				bmi;
HGDIOBJ						obmp;

bmi.bmiHeader.biSize          = sizeof(BITMAPINFO);
bmi.bmiHeader.biWidth         = GetSystemMetrics(SM_CXSCREEN);
bmi.bmiHeader.biHeight        = GetSystemMetrics(SM_CYSCREEN);
bmi.bmiHeader.biPlanes        = 1; 
bmi.bmiHeader.biBitCount      = 24;
bmi.bmiHeader.biCompression   = 0; 
bmi.bmiHeader.biSizeImage     = (((bmi.bmiHeader.biWidth*bmi.bmiHeader.biBitCount/8)+3)&~3)*bmi.bmiHeader.biWidth;
bmi.bmiHeader.biXPelsPerMeter = 300;
bmi.bmiHeader.biYPelsPerMeter = 300;
bmi.bmiHeader.biClrUsed       = 0;
bmi.bmiHeader.biClrImportant  = 0;

hbmpscreen = CreateDIBitmap(mdc,&hbmpscreen,0,0,&bmi.bmiHeader,DIB_RGB_COLORS);
obmp = SelectObject(mdc,hbmpscreen);
BitBlt(mdc,0,0,bmi.bmiHeader.biWidth,bmi.bmiHeader.biHeight,hdc,0,0,SRCCOPY);

SelectObject(mdc,obmp);
DeleteDC(mdc);
ReleaseDC(hdc);
 
Share this answer
 
v4
Comments
fjdiewornncalwe 12-Dec-10 10:25am    
Please note the development language the OP is using before posting an answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900