We help IT Professionals succeed at work.

How to preselect "pages" option in the print dialog (MFC)

242 Views
Last Modified: 2019-01-26
I am trying to customize a print dialog in a MFC app.
I want the "pages" option to be preselected.

In CMyView::OnPreparePrinting(CPrintInfo* pInfo)
I added this at the end of the function:
      pInfo->SetMinPage(10);
      pInfo->SetMaxPage(20);
      pInfo->m_pPD->m_pd.nFromPage = 10;
      pInfo->m_pPD->m_pd.nToPage = 20;
      pInfo->m_pPD->m_nFlags |= PD_PAGENUMS;
      return DoPreparePrinting(pInfo);

When the print dialog comes up, the "all" option is preselected.
Comment
Watch Question

CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Thanks!
Vaclav

Author

Commented:
Unfortunately there is still a problem. If the range of pages is just one page, the "pages" option does not get preselected:

      pInfo->SetMinPage(10);
      pInfo->SetMaxPage(10);
      pInfo->m_pPD->m_pd.nFromPage = 10;
      pInfo->m_pPD->m_pd.nToPage = 10;
      pInfo->m_pPD->m_pd.Flags |= PD_PAGENUMS;
      return DoPreparePrinting(pInfo);

It prints correctly page 10, but the print dialog has option "all" selected
CERTIFIED EXPERT

Commented:
Hm - does this really matter a lot? I mean: why offer two options at all if there's only one page, regardless what options the user can select only that single page can be printed. IMO it would would make more sense to remove the page-selection completeley ...

Beside this: it might be complicated (and probably only possible with huge effort) to change this behavior, this dialog is a common dialog which is created and handled by Windows, to change behavior of this dialog with is not provided by its common implementation is quite hard.

Author

Commented:
There are many pages there. This code is for printing just the current page.
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Thank you very much!
Vaclav
CERTIFIED EXPERT

Commented:
You're welcome, I'm glad I could help ...

Have a nice weekend,

best regards,

ZOPPO