在没有Doc/View的情况下打印 [英] print without Doc/View

查看:88
本文介绍了在没有Doc/View的情况下打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好时光!

我打印窗口,但不打印此窗口菜单.我在哪里犯错?

good time !

I print window, but not print menu this window. Where i do mistake?

void CTestApp::OnFilePrint()
{
        CPrintDialog cp(FALSE);
	if (cp.DoModal)==IDOK)
        {  
	  CPrintInfo Info;
	  CDC PrintDC;					
	  PrintDC.Attach(cp.GetPrinterDC());	
	  DOCINFO infStru;				
	  ::ZeroMemory (&infStru, sizeof (DOCINFO)); 
						
	 infStru.cbSize = sizeof (DOCINFO);			
	 infStru.lpszOutput=NULL;

	 if (PrintDC.StartDoc(&infStru )==-1)	
		AfxMessageBox(_T("Error StartDoc"),NULL,NULL);

	 PrintDC.StartPage();		
	 PrintDC.SetMapMode(MM_ANISOTROPIC);
	 CClientDC dcScreen(NULL);
	
	 int ixd = dcScreen.GetDeviceCaps(LOGPIXELSX);
	 int iyd = dcScreen.GetDeviceCaps(LOGPIXELSY); 

	 // get the printer''s pixel resolution 
	 int ixp = PrintDC.GetDeviceCaps(LOGPIXELSX); 
	 int iyp = PrintDC.GetDeviceCaps(LOGPIXELSY); 
     
         PrintDC.SetMapMode(MM_ANISOTROPIC); 
	 PrintDC.SetWindowExt(ixd, -iyd); 
	 PrintDC.SetViewportExt(ixp, -iyp);
		
	 m_pMainWnd->Print(&PrintDC, PRF_OWNED | PRF_CLIENT | PRF_NONCLIENT | PRF_CHILDREN);
		
	 AfxMessageBox(_T("printing"),NULL,NULL);
		
	 if (PrintDC.EndPage()<0)
		AfxMessageBox(_T("Error EndPage"),NULL,NULL);
	 if (PrintDC.EndDoc()==0)
		AfxMessageBox(_T("Error EndDoc"),NULL,NULL);		
	 PrintDC.Detach();
	}
}

推荐答案

好时光!
帮助我解决决策问题.
我创建的项目没有支持架构的Doc/View.
当我正在打印窗口时,不打印菜单此窗口(IDR_MAINFRAME).我在哪里犯错?

BOOL CTestApp :: InitInstance()
{
.
.
pFrame =新的CMainFrame;
如果(!pFrame)
返回FALSE;
m_pMainWnd = pFrame;
pFrame-> LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,NULL,NULL);
pFrame-> ShowWindow(SW_SHOW);
pFrame-> UpdateWindow();
.
.
}

无效的CTestApp :: OnFilePrint()
{
CPrintDialog cp(FALSE);
如果(cp.DoModal)== IDOK)
{
CPrintInfo信息;
CDC PrintDC;
PrintDC.Attach(cp.GetPrinterDC());
DOCINFO infStru;
:: ZeroMemory(& infStru,sizeof(DOCINFO));

infStru.cbSize = sizeof(DOCINFO);
infStru.lpszOutput = NULL;

如果(PrintDC.StartDoc(& infStru)==-1)
AfxMessageBox(_T("Error StartDoc"),NULL,NULL);

PrintDC.StartPage();
PrintDC.SetMapMode(MM_ANISOTROPIC);
CClientDC dcScreen(NULL);

int ixd = dcScreen.GetDeviceCaps(LOGPIXELSX);
int iyd = dcScreen.GetDeviceCaps(LOGPIXELSY);

//获取打印机的像素分辨率
int ixp = PrintDC.GetDeviceCaps(LOGPIXELSX);
int iyp = PrintDC.GetDeviceCaps(LOGPIXELSY);

PrintDC.SetMapMode(MM_ANISOTROPIC);
PrintDC.SetWindowExt(ixd,-iyd);
PrintDC.SetViewportExt(ixp,-iyp);

m_pMainWnd-> Print(& PrintDC,PRF_OWNED | PRF_CLIENT | PRF_NONCLIENT | PRF_CHILDREN);

AfxMessageBox(_T("printing"),NULL,NULL);

如果(PrintDC.EndPage()< 0)
AfxMessageBox(_T("Error EndPage"),NULL,NULL);
如果(PrintDC.EndDoc()== 0)
AfxMessageBox(_T("Error EndDoc"),NULL,NULL);
PrintDC.Detach();
}
}
Good time !
help me with decision problem.
i create project without support architecture Doc/View.
When i am printing window, not printing menu this window (IDR_MAINFRAME). Where i do mistake?

BOOL CTestApp::InitInstance()
{
.
.
pFrame = new CMainFrame;
if (!pFrame)
return FALSE;
m_pMainWnd = pFrame;
pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL);
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
.
.
}

void CTestApp::OnFilePrint()
{
CPrintDialog cp(FALSE);
if (cp.DoModal)==IDOK)
{
CPrintInfo Info;
CDC PrintDC;
PrintDC.Attach(cp.GetPrinterDC());
DOCINFO infStru;
::ZeroMemory (&infStru, sizeof (DOCINFO));

infStru.cbSize = sizeof (DOCINFO);
infStru.lpszOutput=NULL;

if (PrintDC.StartDoc(&infStru )==-1)
AfxMessageBox(_T("Error StartDoc"),NULL,NULL);

PrintDC.StartPage();
PrintDC.SetMapMode(MM_ANISOTROPIC);
CClientDC dcScreen(NULL);

int ixd = dcScreen.GetDeviceCaps(LOGPIXELSX);
int iyd = dcScreen.GetDeviceCaps(LOGPIXELSY);

// get the printer''s pixel resolution
int ixp = PrintDC.GetDeviceCaps(LOGPIXELSX);
int iyp = PrintDC.GetDeviceCaps(LOGPIXELSY);

PrintDC.SetMapMode(MM_ANISOTROPIC);
PrintDC.SetWindowExt(ixd, -iyd);
PrintDC.SetViewportExt(ixp, -iyp);

m_pMainWnd->Print(&PrintDC, PRF_OWNED | PRF_CLIENT | PRF_NONCLIENT | PRF_CHILDREN);

AfxMessageBox(_T("printing"),NULL,NULL);

if (PrintDC.EndPage()<0)
AfxMessageBox(_T("Error EndPage"),NULL,NULL);
if (PrintDC.EndDoc()==0)
AfxMessageBox(_T("Error EndDoc"),NULL,NULL);
PrintDC.Detach();
}
}


这篇关于在没有Doc/View的情况下打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆