怎么样获取默认打印机纸张的设置?
CPrintDialogdlg(FALSE);
if(!dlg.GetDefaults())
AfxMessageBox(_T("Youhavenodefaultprinter!"));
else
{
//attachtotheDCweweregiven
CDCdc;
dc.Attach(dlg.m_pd.hDC);
//askforthemeasurements
intnHorz=dc.GetDeviceCaps(LOGPIXELSX);
intnVert=dc.GetDeviceCaps(LOGPIXELSY);
//almostalwaysthesameinbothdirections,butsometimesnot!
/*CStringstr;
if(nHorz==nVert)
str.Format(_T("Yourprintersupports%dpixelsperinch"),nHorz);
else
str.Format(_T("Yourprintersupports%dpixelsperinch")
_T("horizontalresolution,and%dpixelsperinchvertical")
_T("resolution"),nHorz,nVert);
*/
//telltheuser
this->m_PageWidth=(float)dc.GetDeviceCaps(PHYSICALWIDTH)/nHorz;
this->m_PageHeight=(float)dc.GetDeviceCaps(PHYSICALHEIGHT)/nVert;
/*
AfxMessageBox(str);
str.Format(_T("实际可打印的区域width:%fheight:%f"),this->m_PageWidth,this->m_PageHeight);
AfxMessageBox(str);
*/
this->m_MarginLeft=(float)dc.GetDeviceCaps(PHYSICALOFFSETX)/nHorz;
this->m_MarginTop=(float)dc.GetDeviceCaps(PHYSICALOFFSETY)/nVert;
/*str.Format(_T("可打印区的水平/垂直偏移width:%fheight:%f"),this->m_MarginLeft,this->m_MarginTop);
AfxMessageBox(str);
*/
this->m_PageActWidth=(float)dc.GetDeviceCaps(HORZRES)/nHorz;
this->m_PageActHeight=(float)dc.GetDeviceCaps(VERTRES)/nVert;
/*str.Format(_T("纸张大小width:%fheight:%f"),this->m_PageActWidth,this->m_PageActHeight);
AfxMessageBox(str);
*/
this->m_MarginRight=this->m_PageWidth-this->m_MarginLeft-this->m_PageActWidth;
this->m_MarginBottom=this->m_PageHeight-this->m_MarginTop-this->m_PageActHeight;
/*
str.Format(_T("纸张右边距,下边距width:%fheight:%f"),this->m_MarginRight,this->m_MarginBottom);
AfxMessageBox(str);
*/
if(!dlg.GetDefaults())
AfxMessageBox(_T("Youhavenodefaultprinter!"));
else
{
//attachtotheDCweweregiven
CDCdc;
dc.Attach(dlg.m_pd.hDC);
//askforthemeasurements
intnHorz=dc.GetDeviceCaps(LOGPIXELSX);
intnVert=dc.GetDeviceCaps(LOGPIXELSY);
//almostalwaysthesameinbothdirections,butsometimesnot!
/*CStringstr;
if(nHorz==nVert)
str.Format(_T("Yourprintersupports%dpixelsperinch"),nHorz);
else
str.Format(_T("Yourprintersupports%dpixelsperinch")
_T("horizontalresolution,and%dpixelsperinchvertical")
_T("resolution"),nHorz,nVert);
*/
//telltheuser
this->m_PageWidth=(float)dc.GetDeviceCaps(PHYSICALWIDTH)/nHorz;
this->m_PageHeight=(float)dc.GetDeviceCaps(PHYSICALHEIGHT)/nVert;
/*
AfxMessageBox(str);
str.Format(_T("实际可打印的区域width:%fheight:%f"),this->m_PageWidth,this->m_PageHeight);
AfxMessageBox(str);
*/
this->m_MarginLeft=(float)dc.GetDeviceCaps(PHYSICALOFFSETX)/nHorz;
this->m_MarginTop=(float)dc.GetDeviceCaps(PHYSICALOFFSETY)/nVert;
/*str.Format(_T("可打印区的水平/垂直偏移width:%fheight:%f"),this->m_MarginLeft,this->m_MarginTop);
AfxMessageBox(str);
*/
this->m_PageActWidth=(float)dc.GetDeviceCaps(HORZRES)/nHorz;
this->m_PageActHeight=(float)dc.GetDeviceCaps(VERTRES)/nVert;
/*str.Format(_T("纸张大小width:%fheight:%f"),this->m_PageActWidth,this->m_PageActHeight);
AfxMessageBox(str);
*/
this->m_MarginRight=this->m_PageWidth-this->m_MarginLeft-this->m_PageActWidth;
this->m_MarginBottom=this->m_PageHeight-this->m_MarginTop-this->m_PageActHeight;
/*
str.Format(_T("纸张右边距,下边距width:%fheight:%f"),this->m_MarginRight,this->m_MarginBottom);
AfxMessageBox(str);
*/
本文地址:http://www.45fan.com/dnjc/69164.html