3个回答
展开全部
代码 大概就是这样 有几个关键函数仔细一下,要是要完整代码呢留言
CDC memDC;
CBitmap memBitmap,*pOldBitmap;
CWindowDC dc(GetDesktopWindow());
memDC.CreateCompatibleDC(&dc);
int nWidth,nHeight;
/* nWidth=GetSystemMetrics(SM_CXSCREEN);
nHeight=GetSystemMetrics(SM_CYSCREEN);*/
CRect rect;
GetDesktopWindow()->GetWindowRect(rect);
ClientToScreen(&rect);
nWidth=rect.Width();
nHeight=rect.Height();
memBitmap.CreateCompatibleBitmap(&dc,nWidth,nHeight);
pOldBitmap=memDC.SelectObject(&memBitmap);
// memDC.StretchBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,rect.Width(),rect.Height(),SRCCOPY);
memDC.BitBlt(0,0,nWidth,nHeight,&dc,0,0,SRCCOPY);
BITMAPFILEHEADER BMFhead;
BITMAPINFOHEADER BMIhead;
BMFhead.bfReserved1=0;
BMFhead.bfReserved2=0;
BMFhead.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
BMFhead.bfSize=BMFhead.bfOffBits+nWidth*nHeight*4;
BMFhead.bfType=0x4d42;
BMIhead.biBitCount=32;
BMIhead.biClrImportant=0;
BMIhead.biClrUsed=0;
BMIhead.biSizeImage=0;
BMIhead.biXPelsPerMeter=0;
BMIhead.biYPelsPerMeter=0;
BMIhead.biCompression=BI_RGB;
BMIhead.biHeight=nHeight;
BMIhead.biPlanes=1;
BMIhead.biSize=sizeof(BITMAPINFOHEADER);
BMIhead.biWidth=nWidth;
DWORD dwSize=nWidth*nHeight*4;
BYTE *pData=new BYTE[dwSize];
GetDIBits(memDC.m_hDC,(HBITMAP)memBitmap.m_hObject,0,nHeight,pData,(LPBITMAPINFO)&BMIhead,DIB_RGB_COLORS);
CFile file;
file.Open("test.bmp",CFile::modeCreate | CFile::modeWrite);
file.Write(&BMFhead,sizeof(BITMAPFILEHEADER));
file.Write(&BMIhead,sizeof(BITMAPINFOHEADER));
file.Write(pData,dwSize);
file.Close();
memDC.SelectObject(pOldBitmap);
MessageBox("绘图完毕");
GetParent()->ShowWindow(SW_SHOW);
CDC memDC;
CBitmap memBitmap,*pOldBitmap;
CWindowDC dc(GetDesktopWindow());
memDC.CreateCompatibleDC(&dc);
int nWidth,nHeight;
/* nWidth=GetSystemMetrics(SM_CXSCREEN);
nHeight=GetSystemMetrics(SM_CYSCREEN);*/
CRect rect;
GetDesktopWindow()->GetWindowRect(rect);
ClientToScreen(&rect);
nWidth=rect.Width();
nHeight=rect.Height();
memBitmap.CreateCompatibleBitmap(&dc,nWidth,nHeight);
pOldBitmap=memDC.SelectObject(&memBitmap);
// memDC.StretchBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,rect.Width(),rect.Height(),SRCCOPY);
memDC.BitBlt(0,0,nWidth,nHeight,&dc,0,0,SRCCOPY);
BITMAPFILEHEADER BMFhead;
BITMAPINFOHEADER BMIhead;
BMFhead.bfReserved1=0;
BMFhead.bfReserved2=0;
BMFhead.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
BMFhead.bfSize=BMFhead.bfOffBits+nWidth*nHeight*4;
BMFhead.bfType=0x4d42;
BMIhead.biBitCount=32;
BMIhead.biClrImportant=0;
BMIhead.biClrUsed=0;
BMIhead.biSizeImage=0;
BMIhead.biXPelsPerMeter=0;
BMIhead.biYPelsPerMeter=0;
BMIhead.biCompression=BI_RGB;
BMIhead.biHeight=nHeight;
BMIhead.biPlanes=1;
BMIhead.biSize=sizeof(BITMAPINFOHEADER);
BMIhead.biWidth=nWidth;
DWORD dwSize=nWidth*nHeight*4;
BYTE *pData=new BYTE[dwSize];
GetDIBits(memDC.m_hDC,(HBITMAP)memBitmap.m_hObject,0,nHeight,pData,(LPBITMAPINFO)&BMIhead,DIB_RGB_COLORS);
CFile file;
file.Open("test.bmp",CFile::modeCreate | CFile::modeWrite);
file.Write(&BMFhead,sizeof(BITMAPFILEHEADER));
file.Write(&BMIhead,sizeof(BITMAPINFOHEADER));
file.Write(pData,dwSize);
file.Close();
memDC.SelectObject(pOldBitmap);
MessageBox("绘图完毕");
GetParent()->ShowWindow(SW_SHOW);
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
给你代码,发哪里
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
http://blog.csdn.net/zwmei/article/details/7440579
此文做了比较详细的解释,可以参考
此文做了比较详细的解释,可以参考
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询