|
|
#include "StdAfx.h"
|
|
|
#include "PrintView.h"
|
|
|
#include "GlobalFunction.h"
|
|
|
#include "FileMgr.h"
|
|
|
|
|
|
|
|
|
CPrintViewMgr::CPrintViewMgr(void)
|
|
|
{
|
|
|
}
|
|
|
CPrintViewMgr::~CPrintViewMgr(void)
|
|
|
{
|
|
|
}
|
|
|
CString CPrintViewMgr::GetPrintViewFullFilePath()
|
|
|
{
|
|
|
CString FullFilePath;
|
|
|
CString FileName = "\\View.bmp";
|
|
|
//获取完整路径
|
|
|
CFileMgr FileMgr;
|
|
|
FileMgr.GetFullFilePath(FullFilePath,FileName);
|
|
|
return FullFilePath;
|
|
|
}
|
|
|
//打印view 的内容到一个bmp 图片
|
|
|
void CPrintViewMgr::PrintViewToBmp(HDC hDC,RECT rect)
|
|
|
{
|
|
|
CString FullFilePath = GetPrintViewFullFilePath();
|
|
|
PrintViewToBmpExt(FullFilePath,hDC,rect);
|
|
|
}
|
|
|
void CPrintViewMgr::PrintViewToBmpExt(CString Path,HDC hDC,RECT 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的图象复制到内存DC中
|
|
|
|
|
|
CImage image;
|
|
|
image.Attach(hBitMap);
|
|
|
image.Save(Path);//如果文件后缀为.bmp,则保存为为bmp格式
|
|
|
image.Detach();
|
|
|
|
|
|
::SelectObject(hDCMem, hOldMap);//选入上次的返回值
|
|
|
|
|
|
//释放
|
|
|
::DeleteObject(hBitMap);
|
|
|
::DeleteDC(hDCMem);
|
|
|
//::DeleteDC(hDC);
|
|
|
}
|
|
|
//保存为bmp 文件
|
|
|
void CPrintViewMgr::SaveToBmpFile(HDC hDC,RECT rect)
|
|
|
{
|
|
|
TCHAR szFilters[]=("BMP 文件(*.bmp)|*.bmp");
|
|
|
CFileDialog dlg(FALSE,("bmp"),("BmpFile"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters);
|
|
|
if(dlg.DoModal()==IDOK)
|
|
|
{
|
|
|
PrintViewToBmpExt(dlg.GetPathName(),hDC,rect);
|
|
|
}
|
|
|
} |