ccm_paper
asked on
Finding the page width of default Printer
Hi all,
I need to find the width of the paper loaded in the user's default printer.
The printer may be a local one or a network printer. The width to be found
should be available even if user specifies paper of custom size.
Thanks in advance!
You need a printer DC from your default printer, and the use GetDeviceCaps:
int width = GetDeviceCaps(hPrtDC,PHYSI CALWIDTH) / GetDeviceCaps(hPrtDC,LOGPI XELSX) * 1000;
int height = GetDeviceCaps(hPrtDC,PHYSI CALHEIGHT) / GetDeviceCaps(hPrtDC,LOGPI XELSY) * 1000;
int width = GetDeviceCaps(hPrtDC,PHYSI
int height = GetDeviceCaps(hPrtDC,PHYSI
Here is a better code I have tested:
CPrintDialog dlg(FALSE);
dlg.GetDefaults();
HDC hPrtDC = dlg.m_pd.hDC;
// Page dimensions in inches
double width = (double)GetDeviceCaps(hPrt DC,PHYSICA LWIDTH) / GetDeviceCaps(hPrtDC,LOGPI XELSX);
double height = (double)GetDeviceCaps(hPrt DC,PHYSICA LHEIGHT) / GetDeviceCaps(hPrtDC,LOGPI XELSY);
CPrintDialog dlg(FALSE);
dlg.GetDefaults();
HDC hPrtDC = dlg.m_pd.hDC;
// Page dimensions in inches
double width = (double)GetDeviceCaps(hPrt
double height = (double)GetDeviceCaps(hPrt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PRINTDLG pd;
pd.lStructSize=(DWORD)size
BOOL bRet=AfxGetApp()->GetPrint
if(bRet)
{
// protect memory handle with ::GlobalLock and ::GlobalUnlock
DEVMODE FAR *pDevMode=(DEVMODE FAR *)::GlobalLock(m_hDevMode)
// test here pDevMode->dmPaperSize and pDevMode->dmPaperWidth
::GlobalUnlock(m_hDevMode)
}
See also MSDN topics DEVMODE, CWinApp::GetPrinterDeviceD