Freigeben über


CPrintDialog::GetDeviceName

Retrieves the name of the currently selected printer device.

CString GetDeviceName( ) const;

Return Value

The name of the currently selected printer.

Remarks

Call this function after calling DoModal to retrieve the name of the currently selected printer, or after calling GetDefaults to retrieve the current device defaults of the default printer. Use a pointer to the CString object returned by GetDeviceName as the value of lpszDeviceName in a call to CDC::CreateDC.

Example

This code fragment shows the user's default printer name and the port it is connected to, along with the spooler name the printer uses. The code might show a message box that says, "Your default printer is HP LaserJet IIIP on \\server\share using winspool.", for example.

CPrintDialog dlg(FALSE);

if (!dlg.GetDefaults())
{
   AfxMessageBox(_T("You have no default printer!"));
}
else
{
   CString strDescription;

   strDescription.Format(_T("Your default printer is %s on %s using %s."),
      (LPCTSTR) dlg.GetDeviceName(),
      (LPCTSTR) dlg.GetPortName(),
      (LPCTSTR) dlg.GetDriverName());

   AfxMessageBox(strDescription);
}

Requirements

Header: afxdlgs.h

See Also

Concepts

CPrintDialog Class

CPrintDialog Members

Hierarchy Chart

CPrintDialog::GetDriverName

CPrintDialog::GetDevMode

CPrintDialog::GetPortName