CPrintDialog::GetDefaults

更新 : 2007 年 11 月

ダイアログ ボックスを表示せずに既定のプリンタの既定のデバイスを取得します。

BOOL GetDefaults( );

戻り値

正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。

解説

取得した値は m_pd 構造体に設定されます。

場合によっては、この関数を呼び出すと bPrintSetupOnly に FALSE を指定して CPrintDialogコンストラクタを呼び出します。この場合、プリンタ DC と hDevNames および hDevMode (m_pd データ メンバに置かれた 2 つのハンドル) が自動的に割り当てられます。

bPrintSetupOnly に FALSE を設定して CPrintDialog のコンストラクタを呼び出したときは、この関数は呼び出し側に hDevNameshDevMode (m_pd.hDevNamesm_pd.hDevMode に置かれています) を返すだけでなく、m_pd.hDC にプリンタ DC を返します。CPrintDialog オブジェクトを使い終わったときは、呼び出し元でプリンタ DC を削除し、このハンドルに対して Windows の GlobalFree 関数を呼び出す必要があります。

使用例

次のコードは、既定のプリンタのデバイス コンテキストを取得して、プリンタの解像度を 1 インチあたりのドット数でユーザーに対して示します。(プリンタ性能のこの値のことを 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
}

必要条件

ヘッダー : afxdlgs.h

参照

参照

CPrintDialog クラス

階層図

CPrintDialog::m_pd

CPrintDialog::GetDeviceName

CPrintDialog::GetDriverName

CPrintDialog::GetPortName

その他の技術情報

CPrintDialog のメンバ