首先的窗口输出一些内容;
菜单单击函数代码;
void CgetmypicView::OnTestGetmypic()
{
// TODO: 在此添加命令处理程序代码
HWND hwnd = this->GetSafeHwnd();
HDC hDC = ::GetWindowDC(hwnd);//获取DC
RECT rect;
::GetClientRect(hwnd, &rect);//获取客户区大小
HDC hDCMem = ::CreateCompatibleDC(hDC);//创建兼容DC
HBITMAP hBitMap = ::CreateCompatibleBitmap(hDC, rect.right, rect.bottom);//创建兼容位图
HBITMAP hOldMap = (HBITMAP)::SelectObject(hDCMem, hBitMap);//将位图选入DC。并保存返回值
::BitBlt(hDCMem, 0, 0, rect.right, rect.bottom, hDC, 0, 0, SRCCOPY);//将图象拷贝到内存DC中
CImage image;
image.Attach(hBitMap);
image.Save(_T("e://myshige.jpg"));//假设文件后缀为.bmp,则保存为为bmp格式
image.Detach();
::SelectObject(hDCMem, hOldMap);//选入上次的返回值
//释放
::DeleteObject(hBitMap);
::DeleteDC(hDCMem);
::DeleteDC(hDC);
}
单击菜单之后在磁盘生成图片文件,打开如下;