Click to See Complete Forum and Search --> : how capture screen in Win2000


roboguru
January 10th, 2003, 04:43 AM
this code was working fine in Win98 but doesn't work in W2 .
please give hint
// Create device context
HDC hdc;
hdc=CreateDC("DISPLAY", NULL, NULL, NULL);
if(hdc==NULL) {
return ;
}

// Get dimensions
DWORD dwWidth, dwHeight, dwBPP, dwNumColors;

dwWidth = GetDeviceCaps(hdc, HORZRES);
dwHeight = GetDeviceCaps(hdc, VERTRES);
dwBPP = GetDeviceCaps(hdc, BITSPIXEL);
if(dwBPP<=8) {
dwNumColors = GetDeviceCaps(hdc, NUMCOLORS);
dwNumColors = 256;
} else {
dwNumColors = 0;
}



// Create compatible DC
HDC hdc2;
hdc2=CreateCompatibleDC(hdc);
if(hdc2==NULL) {
DeleteDC(hdc);

return ;
}

// Create bitmap
HBITMAP bitmap;
BITMAPINFO bmpinfo;
LPVOID pBits;

bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpinfo.bmiHeader.biWidth = dwWidth;
bmpinfo.bmiHeader.biHeight = dwHeight;
bmpinfo.bmiHeader.biPlanes = 1;
bmpinfo.bmiHeader.biBitCount = (WORD) dwBPP;
bmpinfo.bmiHeader.biCompression = BI_RGB;
bmpinfo.bmiHeader.biSizeImage = 0;
bmpinfo.bmiHeader.biXPelsPerMeter = 0;
bmpinfo.bmiHeader.biYPelsPerMeter = 0;
bmpinfo.bmiHeader.biClrUsed = dwNumColors;
bmpinfo.bmiHeader.biClrImportant = dwNumColors;

bitmap = CreateDIBSection(hdc, &bmpinfo,
DIB_PAL_COLORS, &pBits, NULL, 0);
if(bitmap==NULL) {
DeleteDC(hdc);
DeleteDC(hdc2);

return ;
}




m_ShowPic.SetBitmap(bitmap);



UpdateData(FALSE);



// Clean up

DeleteObject(bitmap);
DeleteDC(hdc2);
DeleteDC(hdc);

return ;