2

I can enable the print dialog to show the option to print the selection by pInfo->m_pPD->m_pd.Flags &= ~PD_NOSELECTION; in OnPreparePrinting() just before the DoPreparePrinting() function but if you select the option the object is still printing everything.

If you choose just to print certain pages that works.

So how do you have the CRichEditView support the print selection option?

TIA!!

user3161924
  • 1,849
  • 18
  • 33
  • 2
    I think MFC ignores that flag, because printing is handled by `CView` which doesn't know RTF selection. Add `void CMyRichView::OnBeginPrinting(CDC *pdc, CPrintInfo* pinfo){call default ... if(pinfo->m_pPD->m_nFlags || PD_SELECTION){...}}` This tells you if user wants to print the selection. At this point you can save the document, delete the stuff before/after selection, continue with printing, and then restore the document. – Barmak Shemirani May 28 '21 at 03:54

1 Answers1

0

According to https://learn.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-printdlga:

PD_NOSELECTION

Disables the Selection radio button.

Try:

PD_SELECTION

If this flag is set, the Selection radio button is selected.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Vlad Feinstein
  • 10,960
  • 1
  • 12
  • 27