CPrintDialog dlg(FALSE);

// Retrieve the current printer defaults from the Windows .ini file
// as necessary, or uses the last printer configuration set by the
// user in Print Setup.
CWinApp* app = AfxGetApp();
if (!app->GetPrinterDeviceDefaults(&dlg.m_pd))
    {
// Fails to create a printer device context for printing because
// no printer is being installed. Bring up dialog box to alert the
// users that they need to install a printer.  This step is optional.
if (app->DoPrintDialog(&dlg) != IDOK)
return FALSE;
    }
这段代码,获取系统缺省打印机,大多时候都很快,但是有时候耗时很久(10秒-50秒+不等),不知道什么原因啊???

解决方案 »

  1.   

    void CMyApp::SetLandscapeMode()
    {
       PRINTDLG pd;
       pd.lStructSize=(DWORD)sizeof(PRINTDLG);
       BOOL bRet=GetPrinterDeviceDefaults(&pd);
       if(bRet)
       {
          // protect memory handle with ::GlobalLock and ::GlobalUnlock
          DEVMODE FAR *pDevMode=(DEVMODE FAR *)::GlobalLock(m_hDevMode);
          // set orientation to landscape
          pDevMode->dmOrientation=DMORIENT_LANDSCAPE;
          ::GlobalUnlock(m_hDevMode);
       }
    }
     
      

  2.   

    Retrieves the current printer defaults from the Windows .INI file as necessary, or uses the last printer configuration set by the user in Print Setup.