Article ID: 150288
Article Last Modified on 11/21/2006
class CMyEditView : public CEditView
{
// TRUE for selection printing; FALSE otherwise.
BOOL m_bPrintSelection;
// Position of the next character to be printed in the current
// selection. It is 0 when no selection is found. If
// selection is found, then initially it will be equal to the
// position of the first character in the current selection.
// And its value will be incremented until you are done with
// selection printing.
int m_nNextSelCharToBePrint;
// Position of the first unselected character past the end of
// the current selection. It is 0 when no selection is found.
int m_nFirstNonSelChar;
...
};
CMyEditView::CMyEditView()
{
// Initially, no selected text is found from CEditView window.
m_bPrintSelection = FALSE;
m_nNextSelCharToBePrint = m_nFirstNonSelChar = 0;
...
}
BOOL CMyEditView::OnPreparePrinting(CPrintInfo* pInfo)
{
// Is there any selected text in CEditView window? If the
// selected text is found, enable the Selection button
// and then have it checked so selection printing is performed
// by default.
GetEditCtrl().GetSel(m_nNextSelCharToBePrint,
m_nFirstNonSelChar);
if (m_nNextSelCharToBePrint != m_nFirstNonSelChar)
{
// Enable the Selection button.
pInfo->m_pPD->m_pd.Flags &= ~PD_NOSELECTION;
// Checked the Selection button.
pInfo->m_pPD->m_pd.Flags |= PD_SELECTION;
}
// Call the base class OnPreparePrinting() to display the
// Print dialog box.
BOOL rvalue = CEditView::OnPreparePrinting(pInfo);
// Now check to see whether selection printing should be
// performed or not. TRUE if the user selects the selection
// printing; FALSE otherwise.
m_bPrintSelection = pInfo->m_pPD->PrintSelection();
return rvalue;
}
void CMyEditView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
// If this is for selection printing, you should check whether
// you are at the end of the selected text yet, i.e.
// m_nNextSelCharToBePrint equals to m_SelectionStop.
// m_bContinuePrinting is TRUE if you are not at the end of the
// selected text; FALSE otherwise.
if (m_bPrintSelection)
{
pInfo->m_bContinuePrinting =
m_nNextSelCharToBePrint < m_nFirstNonSelChar;
}
else
{
CEditView::OnPrepareDC(pDC, pInfo);
}
}
void CMyEditView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
if (m_bPrintSelection)
{
m_nNextSelCharToBePrint =
PrintInsideRect(pDC, pInfo->m_rectDraw,
m_nNextSelCharToBePrint, m_nFirstNonSelChar);
}
else
{
CEditView::OnPrint(pDC, pInfo);
}
}Additional query words: 1.50 1.51 1.52 1.00 2.00 2.10 2.20 4.00 4.10
Keywords: kbcmndlgprint kbcode kbhowto kbprint KB150288