Trying to create a custom CListBox control that uses a CRichEditCt

G

Guest

Today, we have an informational dialog where the information is displayed in
a RichText control. The only action for the user is to press the OK button
to dismiss the dialog.



My desire is to enhance this dialog by adding a “Go To†button where the
user would select one of the informational items in the list, press the “Go
To†button, the dialog would disappear, and then the “go to†action occurs.
I still need to display the information using RichText.



Following an example, I attempted to create a custom CListBox control where
the items in the listbox would be displayed using the CRichTextCtrl. The
custom CListBox control contains owner methods of DrawItem and MeasureItem.
The first draft for DrawItem is included. This code appears to work but is
far from perfect. It lacks code for item selection and in my sample code I
can get it to write outside of the boundary of the control. Furthermore, I
am not sure what needs to be done for MeasureItem method.





void CRichEditListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)

{

CDC* pDC = CDC::FromHandle (lpDrawItemStruct->hDC);



if (lpDrawItemStruct->itemID != -1)

{

COLORREF TextBkClr = SysColor (COLOR_WINDOW);



CString Text;

GetText (lpDrawItemStruct->itemID, Text);



CRect rect;

GetItemRect (lpDrawItemStruct->itemID, rect);



// Format the text and render it

UINT Left = ::MulDiv (rect.left, 1440, pDC->GetDeviceCaps
(LOGPIXELSX));

UINT Top = ::MulDiv (rect.top, 1440, pDC->GetDeviceCaps
(LOGPIXELSY));

UINT Right = ::MulDiv (rect.right, 1440, pDC->GetDeviceCaps
(LOGPIXELSX));

UINT Bottom = ::MulDiv (rect.bottom, 1440, pDC->GetDeviceCaps
(LOGPIXELSY));



CRect Rect (Left, Top, Right, Bottom);



FORMATRANGE fr;

fr.hdc = pDC->m_hDC;

fr.hdcTarget = pDC->m_hDC;

fr.rc = Rect;

fr.rcPage = Rect;

fr.chrg.cpMin = 0;

fr.chrg.cpMax = -1;



UINT StreamType;

if (Text.Left (6) == "{\\rtf1")

StreamType = SF_RTF;

else

StreamType = SF_TEXT;



EDITSTREAM es =

{

(DWORD)&Text, 0, EditStreamCallBack

};



m_pRichEditTemp->SetSel (0,-1);

m_pRichEditTemp->SetBackgroundColor (FALSE, TextBkClr);

m_pRichEditTemp->Clear ();

m_pRichEditTemp->StreamIn (StreamType, es);

m_pRichEditTemp->FormatRange (&fr, TRUE);



// Update the display with the new formatting

CRect rcClient;

m_pRichEditTemp->GetClientRect (&rcClient);

m_pRichEditTemp->DisplayBand (&rcClient);

}

}



I have examined the internet and information is scarce. My hope is that
some one can point me in the correct direction or can suggest another
approach.



Thank you for your support.
 
D

David Ching

Pat Moline said:
Today, we have an informational dialog where the information is displayed
in
a RichText control. The only action for the user is to press the OK
button
to dismiss the dialog.

My desire is to enhance this dialog by adding a "Go To" button where the
user would select one of the informational items in the list, press the
"Go
To" button, the dialog would disappear, and then the "go to" action
occurs.
I still need to display the information using RichText.

Later versions of the RichEdit control support embedding hyperlinks, like an
HTML page. Perhaps this suits your need better than adding a "Go To"
button.

-- David
http://www.dcsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

RTF Render with Scale 3

Top