Avatar of Václav Jedlička
Václav Jedlička
 asked on

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

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.
Microsoft ApplicationsPrinters and ScannersVisual C++.NET* MFCC++

Avatar of undefined
Last Comment
Zoppo

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Zoppo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Václav Jedlička

ASKER
Thanks!
Vaclav
Václav Jedlička

ASKER
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
Zoppo

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.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Václav Jedlička

ASKER
There are many pages there. This code is for printing just the current page.
SOLUTION
Zoppo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Václav Jedlička

ASKER
Thank you very much!
Vaclav
Zoppo

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

Have a nice weekend,

best regards,

ZOPPO
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.