windows XP中插入SVCHOST进程抓屏问题
HDC hdc,hdc2;
hdc=CreateDC("DISPLAY", NULL, NULL, NULL);
//hdc=GetDC(NULL);
OutputString("Error CodecreateDC:%d",GetLastError());//返回错误代码0,正确执行
// Create compatible DC
hdc2=CreateCompatibleDC(hdc);
OutputString("Error createcompatiableDC:%d",GetLastError());//返回错误代码6,表示句柄无效。
// 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;
}
//OutputString("dwWidth:%d",dwWidth);
//OutputString("dwHeight:%d",dwHeight);
//OutputString("dwBPP:%d",dwBPP);
//OutputString("dwNumcolors:%d",dwNumColors);
// 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);
OutputString("Error Codecreatedibsection:%d",GetLastError());//返回错误代码8,表示存储空间不足,无法处理批命令。
HGDIOBJ gdiobj;
gdiobj = SelectObject(hdc2, (HGDIOBJ)bitmap);
OutputString("Error CodeSelectObject:%d",GetLastError());//返回错误代码6,句柄无效。
if (!BitBlt(hdc2, 0,0, dwWidth, dwHeight, hdc, 0,0, SRCCOPY))
{
OutputString("Error Code%d",GetLastError());//执行了,返回错误代码6,句柄无效。
}
上面的这段程序我是作为SVCHOST进程的服务来执行的,如果在windows XP系统中运行,则上面的BitBlt函数返回0,导致我无法获取屏幕,如果在windows 2000下运行,那么上面的BitBlt函数返回非零,抓屏正确执行。windows 2000和windows XP下的所有上面的返回的错误代码都是一样的!
谢谢回复!