我需要开发一个ActiveX控件,功能是所见即所得的打印网页中的内容,而且是直接使用系统默认的打印机进行打印,不弹打印机选择对话框,请问如何实现?
我主要使用到了VC++的CView、CDC、CPrintDialog、DOCINFO、CPrintInfo等类,目前直接打印功能实现了,不过打印不出任何内容,请高手指点.贴出实现该功能的主要代码如下:void CISOFTSTONECtrl::DirectPrint()
{
// TODO: Add your dispatch handler code here
/*CDC dc; int nCurPage=1;
CPrintDialog pdlg(FALSE,PD_NOPAGENUMS|PD_NOSELECTION,this);
BOOL bFindPrinter=pdlg.GetDefaults();
if(!bFindPrinter)
return ;
dc.Attach(pdlg.GetPrinterDC());*/ CVIEWPIC viewpic;
CDC dc;
CPrintDialog printDlg(FALSE,PD_NOPAGENUMS|PD_NOSELECTION,this);
//利用CPrintDialog 生成打印机设备环境
BOOL bFindPrinter=printDlg.GetDefaults();
if(!bFindPrinter)
return ; dc.Attach(printDlg.GetPrinterDC()); // Attach a printer DC 让HANDLE连接到dc上
dc.m_bPrinting = TRUE; CString strTitle; // Get the application title ?
strTitle.LoadString(AFX_IDS_APP_TITLE); DOCINFO di; // Initialise print document details DOCINFO中有相关的打印信息
::ZeroMemory (&di, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = strTitle;//设置标题 // Get the printing extents and store in the m_rectDraw field of a
// CPrintInfo object
CPrintInfo Info;//
Info.m_rectDraw.SetRect(0,0,dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES));//设置范围
viewpic.OnPrint(&dc,&Info);
BOOL bPrintingOK = dc.StartDoc(&di); // Begin a new print job 开始打印
dc.StartPage(); dc.EndPage();
dc.EndDoc(); if (bPrintingOK)
dc.EndDoc(); // end a print job
else
dc.AbortDoc(); // abort job. dc.Detach(); // detach the printer DC
}
我主要使用到了VC++的CView、CDC、CPrintDialog、DOCINFO、CPrintInfo等类,目前直接打印功能实现了,不过打印不出任何内容,请高手指点.贴出实现该功能的主要代码如下:void CISOFTSTONECtrl::DirectPrint()
{
// TODO: Add your dispatch handler code here
/*CDC dc; int nCurPage=1;
CPrintDialog pdlg(FALSE,PD_NOPAGENUMS|PD_NOSELECTION,this);
BOOL bFindPrinter=pdlg.GetDefaults();
if(!bFindPrinter)
return ;
dc.Attach(pdlg.GetPrinterDC());*/ CVIEWPIC viewpic;
CDC dc;
CPrintDialog printDlg(FALSE,PD_NOPAGENUMS|PD_NOSELECTION,this);
//利用CPrintDialog 生成打印机设备环境
BOOL bFindPrinter=printDlg.GetDefaults();
if(!bFindPrinter)
return ; dc.Attach(printDlg.GetPrinterDC()); // Attach a printer DC 让HANDLE连接到dc上
dc.m_bPrinting = TRUE; CString strTitle; // Get the application title ?
strTitle.LoadString(AFX_IDS_APP_TITLE); DOCINFO di; // Initialise print document details DOCINFO中有相关的打印信息
::ZeroMemory (&di, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = strTitle;//设置标题 // Get the printing extents and store in the m_rectDraw field of a
// CPrintInfo object
CPrintInfo Info;//
Info.m_rectDraw.SetRect(0,0,dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES));//设置范围
viewpic.OnPrint(&dc,&Info);
BOOL bPrintingOK = dc.StartDoc(&di); // Begin a new print job 开始打印
dc.StartPage(); dc.EndPage();
dc.EndDoc(); if (bPrintingOK)
dc.EndDoc(); // end a print job
else
dc.AbortDoc(); // abort job. dc.Detach(); // detach the printer DC
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货