CPrintDialog::GetDefaults

擷取預設印表機的預設裝置,而不顯示對話方塊。

BOOL GetDefaults( );

傳回值

如果不是零,則函式成功,則為 0。

備註

擷取的值。 m_pd 結構中。

在某些情況下,對這個函式的呼叫將會呼叫 CPrintDialog建構函式 和 bPrintSetupOnly 設為 。在這些情況下,) 會自動配置印表機 DC 和 hDevNameshDevMode (位於 m_pd 資料成員的兩個控制代碼。

如果 CPrintDialog 的建構函式會以 bPrintSetupOnly 設為 ,這個函式不僅會傳回 hDevNameshDevMode (位於 m_pd.hDevNamesm_pd.hDevMode) 給呼叫端,,但也會在 m_pd.hDC的印表機 DC。當您完成使用物件時, CPrintDialog 為呼叫端的責任刪除印表機 DC 和呼叫在控制代碼的視窗 GlobalFree 函式。

範例

這個程式碼片段的預設印表機的裝置內容和報表使用者印表機的解析度 (以 Dots 的。(印表機功能的這個屬性通常稱為 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