By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,965 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,965 IT Pros & Developers. It's quick & easy.

Trying to create a custom CListBox control that uses a CRichEditCt

P: n/a
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.

Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Pat Moline" <Pa*******@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
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
Dec 3 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.