Article ID: 117565
Article Last Modified on 11/21/2006
/* Compile options needed: none
*/
BOOL CMyView::GetPageSize(CSize &nRetVal)
{
PRINTDLG FAR * pPrintDlg = new PRINTDLG;
BOOL bRet = FALSE;
// Get the current printer's settings.
if(AfxGetApp()->GetPrinterDeviceDefaults(pPrintDlg))
{
// Get pointers to the two setting structures.
DEVNAMES FAR *lpDevNames =
(DEVNAMES FAR *)::GlobalLock(pPrintDlg->hDevNames);
DEVMODE FAR *lpDevMode =
(DEVMODE FAR *)::GlobalLock(pPrintDlg->hDevMode);
// Get the specific driver information.
CString szDriver((LPTSTR)lpDevNames +
lpDevNames->wDriverOffset);
CString szDevice((LPTSTR)lpDevNames +
lpDevNames->wDeviceOffset);
CString szOutput((LPTSTR)lpDevNames +
lpDevNames->wOutputOffset);
// Create a CDC object according to the current settings.
CDC pDC;
pDC.CreateDC(szDriver, szDevice, szOutput, lpDevMode);
// Query this CDC object for the width and height of the current
// page.
nRetVal.cx = pDC.GetDeviceCaps(HORZSIZE);
nRetVal.cy = pDC.GetDeviceCaps(VERTSIZE);
// Get rid of the CDC object.
pDC.DeleteDC();
// Unlock the pointers to the setting structures.
::GlobalUnlock(pPrintDlg->hDevNames);
::GlobalUnlock(pPrintDlg->hDevMode);
bRet = TRUE;
}
delete pPrintDlg;
return bRet;
}
Additional query words: kbNoUpdate
Keywords: kbhowto kbprint kbcmndlgprint KB117565