你好,您在点击打印的时候,没有出现“打印”对话框,此时主对话框中的条形码已显示了,打印机有动作,出纸了,条码出不来,打印机已确认是正常的,代码如下:
//构造打印对话框
CPrintDialog m_print(false,PD_ALLPAGES | PD_USEDEVMODECOPIES |PD_RETURNDEFAULT| PD_NOPAGENUMS | PD_HIDEPRINTTOFILE | PD_NOSELECTION,this);
m_barcode.SetBackColor(RGB(255,255,255));
if (m_print.DoModal()==IDOK)
{
CDC dc1 ;
dc1.Attach(m_print.GetPrinterDC()); //将dc1关联到打印机句柄
CDC dc;
dc.Attach(m_barcode.GetDC()->m_hDC); //将dc关联到条形码句柄
CString str;
CRect rect;
m_barcode.GetClientRect(rect); //获取条形码的客户区域
rect.DeflateRect(1,1,1,1);
int screenx,screeny;
int printx,printy;
double ratex,ratey;
//确定打印机与屏幕的像素比率
screenx = dc.GetDeviceCaps(LOGPIXELSX);
screeny = dc.GetDeviceCaps(LOGPIXELSY);
printx = dc1.GetDeviceCaps(LOGPIXELSX);
printy = dc1.GetDeviceCaps(LOGPIXELSY);
ratex = (double)(printx)/screenx;
ratey = (double)(printy)/screeny;
dc1.SetBkMode(TRANSPARENT);
//开始打印
dc1.StartDoc("FirstDoc");
dc1.StretchBlt(1,1,(int)(rect.Width()*ratex),(int)(rect.Height()*ratey),&dc,1,1,rect.Width(),rect.Height(),SRCCOPY);
dc1.EndDoc();
}