You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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);
}
}