Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. unable to to set paper size in printer properties

unable to to set paper size in printer properties

Scheduled Pinned Locked Moved C / C++ / MFC
c++mfcprinter
1 Posts 1 Posters 10 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    narsi.rao16
    wrote last edited by
    #1

    void CMFCApplication2Dlg::TestFinal()
    {
    CPrintDialogEx dlg;

    CString strPrinterName = _T("Microsoft Print to PDF");
    const WORD nPaperA4 = DMPAPER_A4;
    
    // Preserve old default printer
    TCHAR szOldDefault[256] = { 0 };
    DWORD dwSize = _countof(szOldDefault);
    if (!::GetDefaultPrinter(szOldDefault, &dwSize)) szOldDefault[0] = '\0';
    CString strOldDefault = szOldDefault;
    
    // Set target printer temporarily
    ::SetDefaultPrinter(strPrinterName);
    
    // Get DEVMODE / DEVNAMES
    CPrintDialog tempDlg(FALSE);
    if (!tempDlg.GetDefaults()) goto RestoreDefault;
    
    dlg.m_pdex.hDevMode = tempDlg.m_pd.hDevMode;
    dlg.m_pdex.hDevNames = tempDlg.m_pd.hDevNames;
    tempDlg.m_pd.hDevMode = NULL;
    tempDlg.m_pd.hDevNames = NULL;
    
    // Set default paper to A4
    DEVMODE* pDevMode = (DEVMODE*)::GlobalLock(dlg.m_pdex.hDevMode);
    if (pDevMode)
    {
    	pDevMode->dmFields |= DM_PAPERSIZE;
    	pDevMode->dmPaperSize = nPaperA4;
    	::GlobalUnlock(dlg.m_pdex.hDevMode);
    }
    
    dlg.DoModal();
    

    RestoreDefault:
    if (!strOldDefault.IsEmpty())
    ::SetDefaultPrinter(strOldDefault);
    }

    hi All,

    unable to to set paper size in printer properties UI windows print. can you please help me for the same

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups