CPrintDialog::GetDefaults

检索默认打印机的设备默认值,而不显示对话框。

BOOL GetDefaults( );

返回值

非零,如果函数运行成功;否则为0。

备注

检索的值。m_pd 结构将。

有时,对此函数的调用将调用 CPrintDialog构造函数 和 bPrintSetupOnly 设置为 FALSE。在这些情况下,)自动分配打印机DC和 hDevNameshDevMode (位于 m_pd 数据成员的两个控点。

如果 CPrintDialog 的构造函数调用与 bPrintSetupOnly 设置为 FALSE,此功能不仅将返回 hDevNameshDevMode (位于 m_pd.hDevNamesm_pd.hDevMode)调用方,但是,还返回在 m_pd.hDC的打印机dc:date。完成对 CPrintDialog 对象,则被调用方负责删除打印机DC并对处理的Windows GlobalFree 功能。

示例

此代码片段具有默认打印机的设备上下文和报表用户打印机的分辨率在点/英寸的。(打印机的功能的此属性通常称为DPI。)

CPrintDialog dlg(FALSE);

if (!dlg.GetDefaults())
{
   AfxMessageBox(_T("You have no default printer!"));
}
else
{
   // attach to the DC we were given
   CDC dc;
   dc.Attach(dlg.m_pd.hDC);

   // ask for the measurements
   int nHorz = dc.GetDeviceCaps(LOGPIXELSX);
   int nVert = dc.GetDeviceCaps(LOGPIXELSY);

   // almost always the same in both directions, but sometimes not!
   CString str;
   if (nHorz == nVert)
   {
      str.Format(_T("Your printer supports %d pixels per inch"), nHorz);
   }
   else
   {
      str.Format(_T("Your printer supports %d pixels per inch ")
         _T("horizontal resolution, and %d pixels per inch vertical ")
         _T("resolution"), nHorz, nVert);
   }

   // tell the user
   AfxMessageBox(str);

   // Note: no need to call Detach() because we want the CDC destructor
   // to call FreeDC() on the DC we borrowed from the common dialog
}

要求

Header: afxdlgs.h

请参见

参考

CPrintDialog选件类

层次结构图

CPrintDialog::m_pd

CPrintDialog::GetDeviceName

CPrintDialog::GetDriverName

CPrintDialog::GetPortName