我写了个抓屏的程序,代码在windows application模式下可以抓屏,后来我把这个程序改成了系统服务程序,结果抓出的图全是黑的.不知道问题出在哪儿?奇怪的是这个服务程序在DEBUG时候也可以抓,但是其release版本运行成服务后就不行
解决方案 »
- 求思路~VC6.0下对话框背景图片带滚动条 绘图
- 怎样制作小体积的安装包?
- VS2008中MFC对话框背景色设置时候的问题
- 【请教】对话框上显示内存位图问题
- 启动softice时:弹出错误对话框sofeice start failure ,提示如下错误: Errror code 31 连接到系统上的设备没有发挥作用。
- 大虾们帮小弟看一下关于子菜单的消息响应问题!!!(在线等啊)
- 不知道是大问题还是小问题
- 调用 含有类申明的 dll 出现错误,
- 一个小问题(CListCtrl)
- 一个组件如何接收由ASP程序传来的二进制类型的数据???
- 我想在一个VC作的DIALOG程序在运行时带入参数,怎么办?
- 完成端口连接限制问题(参与就有分!!!!!!!!!!!!!!!!!!!!!!)
if capture media,try DirectDraw.
to liufeng24(流枫) : 在release下,绘图句柄没有值 ?
to kingzai(stevenzhu) :在啥地方设置?
代码如下:
bool save_screen(BYTE *&pScreen, DWORD &nLength)
{
int nScreenX = GetSystemMetrics(SM_CXSCREEN);
int nScreenY = GetSystemMetrics(SM_CYSCREEN);
HDC hDC = GetDC(GetDesktopWindow());
HDC hMemDC = CreateCompatibleDC(hDC);
HBITMAP hBitmap = CreateCompatibleBitmap(hDC, nScreenX, nScreenY);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
// 保存整个屏幕内容 保存在bitmap中了
BitBlt(hMemDC, 0, 0, nScreenX, nScreenY, hDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOldBitmap);
DIBSection.SetBitmap((HBITMAP)hBitmap);
ReleaseDC(GetDesktopWindow(), hDC);
BITMAPFILEHEADER hdr;
LPBITMAPINFOHEADER lpbi = DIBSection.GetBitmapInfoHeader();
DWORD dwBitmapInfoSize = sizeof(BITMAPINFO) + DIBSection.m_iColorTableSize*sizeof(RGBQUAD);
DWORD dwFileHeaderSize = dwBitmapInfoSize + sizeof(hdr);
hdr.bfType = DS_BITMAP_FILEMARKER;
hdr.bfSize = dwFileHeaderSize + lpbi->biSizeImage;
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;
hdr.bfOffBits = dwFileHeaderSize; nLength = sizeof(hdr)+dwBitmapInfoSize+lpbi->biSizeImage ;
pScreen = new BYTE [nLength];
if ( pScreen )
{
memcpy( pScreen, &hdr, sizeof(hdr));
memcpy( pScreen+sizeof(hdr), lpbi, dwBitmapInfoSize);
memcpy( pScreen+sizeof(hdr)+dwBitmapInfoSize, DIBSection.GetDIBits(), lpbi->biSizeImage);
}
return TRUE;
}
CDC dc;
dc.CreateDC("DISPLAY",NULL,NULL,NULL);
CBitmap bm; BITMAP btm;
char* lpData; int Width=20;
int Height=25;
bm.CreateCompatibleBitmap(&dc,Width,Height); CDC tdc;
tdc.CreateCompatibleDC(&dc);
CBitmap *pOld=tdc.SelectObject(&bm);
tdc.BitBlt(0,0,Width,Height,&dc,cur.x,cur.y,SRCCOPY);
tdc.SelectObject(pOld);
bm.GetBitmap(&btm);
int size=btm.bmWidthBytes*btm.bmHeight;
if(btm.bmWidthBytes/btm.bmWidth == 1)
return FALSE; lpData=new char[size];
/////////////////////////////////////////////
BITMAPINFOHEADER bih;
bih.biBitCount=btm.bmBitsPixel;
bih.biClrImportant=0;
bih.biClrUsed=0;
bih.biCompression=0;
bih.biHeight=btm.bmHeight;
bih.biPlanes=1;
bih.biSize=sizeof(BITMAPINFOHEADER);
bih.biSizeImage=size;
bih.biWidth=btm.bmWidth;
bih.biXPelsPerMeter=0;
bih.biYPelsPerMeter=0;
///////////////////////////////////
GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS); //在这里分析LPDATA中的数据 delete lpData;