首页上一页 1 下一页尾页 3 条记录 1/1页
VC++范例宝典光碟的实例源代码运行根本不能实践打印图片
发表在C语言图书答疑
2010-08-16
是否精华
是
否
版块置顶:
是
否
void CPrintImageDlg::OnButtonprint()
{
CDC memDC;
CDC* imagedc = m_image.GetDC();
memDC.CreateCompatibleDC(imagedc);
CRect m_rect;
//获取图像的大小
m_image.GetClientRect(m_rect);
CBitmap bitmap;
if(!bitmap.LoadBitmap(IDB_BITMAP1))
{
return;
}
imagedc->SelectObject(bitmap);//将位图加入imageDC中
memDC.BitBlt(0,0,m_rect.Width(),m_rect.Height(),imagedc,0,0,SRCCOPY);
int formx,formy;
formx = imagedc->GetDeviceCaps(LOGPIXELSX);
formy = imagedc->GetDeviceCaps(LOGPIXELSY);
CPrintDialog m_printdlg (FALSE);
if (m_printdlg.DoModal()==IDOK)
{
CDC dc;
dc.Attach(m_printdlg.GetPrinterDC());
//获取打印机与屏幕的分辨率比率
int printerx,printery;
printerx = dc.GetDeviceCaps(LOGPIXELSX);
printery = dc.GetDeviceCaps(LOGPIXELSY);
double ratex,ratey;
ratex = (double)printerx/formx;
ratey = (double)printery/formy;
//打印图像
dc.StartDoc("printsss");
dc.StretchBlt(30,40,(int)(m_rect.Width()*ratex),(int)(m_rect.Height()*ratey),&memDC,0,0,m_rect.Width(),m_rect.Height(),SRCCOPY);
dc.EndDoc();
}
}
你好这是书中第10章310例,VC打印图片的代码,你们的光碟上的例子根本就运行不了.
我试了好多遍了.
能说说吗?
我的QQ:291366195
sike008@163.com
{
CDC memDC;
CDC* imagedc = m_image.GetDC();
memDC.CreateCompatibleDC(imagedc);
CRect m_rect;
//获取图像的大小
m_image.GetClientRect(m_rect);
CBitmap bitmap;
if(!bitmap.LoadBitmap(IDB_BITMAP1))
{
return;
}
imagedc->SelectObject(bitmap);//将位图加入imageDC中
memDC.BitBlt(0,0,m_rect.Width(),m_rect.Height(),imagedc,0,0,SRCCOPY);
int formx,formy;
formx = imagedc->GetDeviceCaps(LOGPIXELSX);
formy = imagedc->GetDeviceCaps(LOGPIXELSY);
CPrintDialog m_printdlg (FALSE);
if (m_printdlg.DoModal()==IDOK)
{
CDC dc;
dc.Attach(m_printdlg.GetPrinterDC());
//获取打印机与屏幕的分辨率比率
int printerx,printery;
printerx = dc.GetDeviceCaps(LOGPIXELSX);
printery = dc.GetDeviceCaps(LOGPIXELSY);
double ratex,ratey;
ratex = (double)printerx/formx;
ratey = (double)printery/formy;
//打印图像
dc.StartDoc("printsss");
dc.StretchBlt(30,40,(int)(m_rect.Width()*ratex),(int)(m_rect.Height()*ratey),&memDC,0,0,m_rect.Width(),m_rect.Height(),SRCCOPY);
dc.EndDoc();
}
}
你好这是书中第10章310例,VC打印图片的代码,你们的光碟上的例子根本就运行不了.
我试了好多遍了.
能说说吗?
我的QQ:291366195
sike008@163.com