- UID
- 167189
- 帖子
- 4416
- 积分
- 3078
- 阅读权限
- 50
- 注册时间
- 2012-12-6
- 最后登录
- 2015-6-20
- 在线时间
- 897 小时
|
//先读取BMP关联到memDC上
CDC memDC;
CClientDC dc(this);
int bmpWidth = 1024;
int bmpHeight = 768;
memDC.CreateCompatibleDC( &dc );
CBitmap* bitmap = new CBitmap();
HBITMAP hBitmap = NULL;
hBitmap = (HBITMAP)LoadImage(NULL, "1.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
bitmap->Attach(hBitmap);
CBitmap* pOldBitmap = (CBitmap*)memDC.SelectObject(bitmap);
//再创建一个用于打印的DC
CDC prtDC;
CPrintInfo printInfo;
HDC hDC = printInfo.m_pPD->m_pd.hDC;
if (hDC == NULL)
hDC = printInfo.m_pPD->CreatePrinterDC();
if(hDC !=NULL)
{
prtDC.Attach(hDC);
}
//然后你去看看StretchBlt这个函数,参数要怎么配,自己查下MSDN。
prtDC.StretchBlt(0, 0, last_bmpWidth * ratio_x, bmpHeight* ratio_y, &memDC,
paper_width * i / ratio_x, 0, last_bmpWidth, bmpHeight, SRCCOPY);
//最后
DOCINFO di;
memset(&di, 0, sizeof(DOCINFO));
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = szAppName;
szPortName = prtDlg.GetPortName();
di.lpszOutput = szPortName;
prtDC.m_bPrinting = TRUE;
if(prtDC.StartDoc(&di) == -1)
{
AfxMessageBox("Printing error occured. Unable to find printer.");
prtDC.DeleteDC();
}
prtDC.EndDoc();
prtDC.DeleteDC();
memDC.SelectObject(pOldBitmap);
delete bitmap;
memDC.DeleteDC(); |
|