当前位置: 首页>>代码示例>>C++>>正文


C++ CWinApp::GetPrinterDeviceDefaults方法代码示例

本文整理汇总了C++中CWinApp::GetPrinterDeviceDefaults方法的典型用法代码示例。如果您正苦于以下问题:C++ CWinApp::GetPrinterDeviceDefaults方法的具体用法?C++ CWinApp::GetPrinterDeviceDefaults怎么用?C++ CWinApp::GetPrinterDeviceDefaults使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CWinApp的用法示例。


在下文中一共展示了CWinApp::GetPrinterDeviceDefaults方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DoPreparePrinting

BOOL CView::DoPreparePrinting(CPrintInfo* pInfo)
{
	ASSERT(pInfo != NULL);
	ASSERT(pInfo->m_pPD != NULL);

	if (pInfo->m_pPD->m_pd.nMinPage > pInfo->m_pPD->m_pd.nMaxPage)
		pInfo->m_pPD->m_pd.nMaxPage = pInfo->m_pPD->m_pd.nMinPage;

	// don't prompt the user if we're doing print preview, printing directly,
	// or printing via IPrint and have been instructed not to ask

	CWinApp* pApp = AfxGetApp();
	if (pInfo->m_bPreview || pInfo->m_bDirect ||
		(pInfo->m_bDocObject && !(pInfo->m_dwFlags & PRINTFLAG_PROMPTUSER)))
	{
		if (pInfo->m_pPD->m_pd.hDC == NULL)
		{
			// if no printer set then, get default printer DC and create DC without calling
			//   print dialog.
			if (!pApp->GetPrinterDeviceDefaults(&pInfo->m_pPD->m_pd))
			{
				// bring up dialog to alert the user they need to install a printer.
				if (!pInfo->m_bDocObject || (pInfo->m_dwFlags & PRINTFLAG_MAYBOTHERUSER))
					if (pApp->DoPrintDialog(pInfo->m_pPD) != IDOK)
						return FALSE;
			}

			if (pInfo->m_pPD->m_pd.hDC == NULL)
			{
				// call CreatePrinterDC if DC was not created by above
				if (pInfo->m_pPD->CreatePrinterDC() == NULL)
					return FALSE;
			}
		}

		// set up From and To page range from Min and Max
		pInfo->m_pPD->m_pd.nFromPage = (WORD)pInfo->GetMinPage();
		pInfo->m_pPD->m_pd.nToPage = (WORD)pInfo->GetMaxPage();
	}
	else
	{
		// otherwise, bring up the print dialog and allow user to change things
		// preset From-To range same as Min-Max range
		pInfo->m_pPD->m_pd.nFromPage = (WORD)pInfo->GetMinPage();
		pInfo->m_pPD->m_pd.nToPage = (WORD)pInfo->GetMaxPage();

		if (pApp->DoPrintDialog(pInfo->m_pPD) != IDOK)
			return FALSE;       // do not print
	}

	ASSERT(pInfo->m_pPD != NULL);
	ASSERT(pInfo->m_pPD->m_pd.hDC != NULL);
	if (pInfo->m_pPD->m_pd.hDC == NULL)
		return FALSE;

	pInfo->m_nNumPreviewPages = pApp->m_nNumPreviewPages;
	VERIFY(pInfo->m_strPageDesc.LoadString(AFX_IDS_PREVIEWPAGEDESC));
	return TRUE;
}
开发者ID:pixelspark,项目名称:corespark,代码行数:59,代码来源:viewprnt.cpp

示例2: OnSelectPrinter

void CBCGPRibbonBackstagePagePrint::OnSelectPrinter() 
{
	CWinApp* pApp = AfxGetApp();
	if (pApp == NULL)
	{
		ASSERT(FALSE);
		return;
	}

	int nSelection = GetPrinterSelection ();
	if (nSelection < 0)
	{
		ASSERT(FALSE);
		return;
	}

	PRINTDLG* dlgPrint = GetPrintDlg();
	ASSERT(dlgPrint != NULL);

	LPDEVNAMES lpDevNames = NULL;
	if (dlgPrint->hDevNames != NULL)
	{
		lpDevNames = (LPDEVNAMES)::GlobalLock(dlgPrint->hDevNames);
		ASSERT(lpDevNames != NULL);
	}

	XPrinterInfo& info = m_Printers[nSelection];

 	if (lstrcmp((LPCTSTR)lpDevNames + lpDevNames->wDriverOffset, info.strDriverName) != 0 ||
 		lstrcmp((LPCTSTR)lpDevNames + lpDevNames->wDeviceOffset, info.strPrinterName) != 0 ||
 		lstrcmp((LPCTSTR)lpDevNames + lpDevNames->wOutputOffset, info.strPortName) != 0)
	{
		::GlobalUnlock(dlgPrint->hDevNames);

		// Compute size of DEVNAMES structure from PRINTER_INFO_2's data
		int drvNameLen = info.strDriverName.GetLength () + 1;  // driver name
		int ptrNameLen = info.strPrinterName.GetLength () + 1; // printer name
		int porNameLen = info.strPortName.GetLength () + 1;    // port name

		// Allocate a global handle big enough to hold DEVNAMES.
		HGLOBAL hDevNames = GlobalAlloc(GHND, sizeof(DEVNAMES) + (drvNameLen + ptrNameLen + porNameLen) * sizeof(TCHAR));
		DEVNAMES* pDevNames = (DEVNAMES*)GlobalLock(hDevNames);
		ASSERT(pDevNames != NULL);

		// Copy the DEVNAMES information from PRINTER_INFO_2
		// tcOffset = TCHAR Offset into structure
		int tcOffset = sizeof(DEVNAMES) / sizeof(TCHAR);
		ASSERT(sizeof(DEVNAMES) == tcOffset * sizeof(TCHAR));

		pDevNames->wDriverOffset = (WORD)tcOffset;
		memcpy((LPTSTR)pDevNames + tcOffset, (LPCTSTR)info.strDriverName, drvNameLen * sizeof(TCHAR));
		tcOffset += drvNameLen;

		pDevNames->wDeviceOffset = (WORD)tcOffset;
		memcpy((LPTSTR)pDevNames + tcOffset, (LPCTSTR)info.strPrinterName, ptrNameLen * sizeof(TCHAR));
		tcOffset += ptrNameLen;

		pDevNames->wOutputOffset = (WORD)tcOffset;
		memcpy((LPTSTR)pDevNames + tcOffset, (LPCTSTR)info.strPortName, porNameLen * sizeof(TCHAR));
		pDevNames->wDefault = 0;

		::GlobalUnlock(hDevNames);

		dlgPrint->hDevNames = hDevNames;

		pApp->SelectPrinter(dlgPrint->hDevNames, NULL, TRUE);
		pApp->DevModeChange((LPTSTR)(LPCTSTR)info.strPrinterName);
		pApp->GetPrinterDeviceDefaults (dlgPrint);

		short dmPaperSize = 0;
		if (dlgPrint->hDevMode != NULL)
		{
			LPDEVMODE lpDevMode = (LPDEVMODE)::GlobalLock (dlgPrint->hDevMode);
			dmPaperSize = lpDevMode->dmPaperSize;
			::GlobalUnlock (dlgPrint->hDevMode);
		}

		BOOL bNotify = m_wndPaper.GetCount () > 0;

		UpdatePrinterProperties(TRUE);
		UpdatePapers (dmPaperSize);
		UpdatePrinterProperties(FALSE, bNotify);
	}
}
开发者ID:cugxiangzhenwei,项目名称:WorkPlatForm,代码行数:84,代码来源:BCGPRibbonBackstagePagePrint.cpp


注:本文中的CWinApp::GetPrinterDeviceDefaults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。