Re: Scrolling.
I have a problem.
If I place my new owner draw based word wrap ListBox on a resizable dialog,
I have problems. When the dialog is resized the ListBox is resized. The
problem occurs if you stretch the dialog horizontally. This stretches the
list box horizontally. Initially the text in the ListBox was not adjusting.
To fix this... In my ListBox subclass I setup an OnSize handler. In the
handler I put an Invalidate();
So now the text is redrawn as I stretch the dialog horizontally. That part
works.
The problem is that the height of each text entry is not being recalculated
as the ListBox is stretched. So if initially a text entry is word wrapped
into two display lines, and then I stretch the dialog wide enough so all the
text fits on one display line, the height of the entry does not adjust to a
single line.
The problem is worse if you shrink the dialog horizontally, At some point
the text will need to be displayed on three lines, but the height of the
entry remains at two lines so some text isn't displayed.
Any ideas?
"AliR (VC++ MVP)" <AliR@online.nospam> wrote in message
news:syEbi.3280$c06.2624@newssvr22.news.prodigy.net...
Here is what you want to do.
Make your listbox an owner draw variable listbox. Also make sure you set
the Has Strings flag.
Then inherite a class from CListBox and implement MeasureItem and DrawItem
methods.
MeasureItem will tell the listbox how tall each item in the listbox is,
since one can be 3 lines and one 1 line.
DrawItem actually draws the text.
Here is an example:
void CMultiLineListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CString Text;
GetText(lpDrawItemStruct->itemID,Text);
DrawText(lpDrawItemStruct->hDC,Text,Text.GetLength(),&lpDrawItemStruct->rcItem,DT_WORDBREAK);
}
void CMultiLineListBox::MeasureItem(LPMEASUREITEMSTRUCT
lpMeasureItemStruct)
{
CFont *pFont = GetFont();
CRect Rect;
GetClientRect(&Rect);
CDC *pDC = GetDC();
CFont *pOldFont = pDC->SelectObject(pFont);
CString Text;
GetText(lpMeasureItemStruct->itemID,Text);
pDC->DrawText(Text,&Rect,DT_CALCRECT|DT_WORDBREAK);
pDC->SelectObject(pOldFont);
ReleaseDC(pDC);
lpMeasureItemStruct->itemHeight = Rect.Height()+5;
}
AliR.
"TonyG" <TonyG@junk.com> wrote in message
news:iHDbi.25288$YL5.11281@newssvr29.news.prodigy.net...
I though about using an edit control, but that won't work easily.
Sometimes my dialog is opened and then whenever my program want's to add
a line of text to it, I send the dialog a new line of text. The dialog
uses CListBox's InsertString to add the new string to the display. And in
some uses the list box could possibly contain hundreds of lines of text.
CEdit can't handle easy insertions.
I will look at using an owner draw list box, but I have never implemented
owner draw anything in any program I have written. I guess there is a
first time for everything. Any hints to help me?
"AliR (VC++ MVP)" <AliR@online.nospam> wrote in message
news:LbDbi.3515$bP5.105@newssvr19.news.prodigy.net...
Obviously a standard listbox doesn't do that, but you can easily create
an owner draw list box, and when you draw the text using DrawText pass
it DT_WORDBREAK.
Or you can use an read only edit control.
AliR.
"TonyG" <TonyG@junk.com> wrote in message
news:W%Cbi.25286$YL5.10549@newssvr29.news.prodigy.net...
I have a simple dialog that I have used in many programs. Most of the
dialog is covered by a giant list box. Whenever I have a bunch of text
to display to the operator, I use this dialog. An example is a bunch of
configuration errors that I detect during program startup. I have a nice
way of passing a title, my text and some other stuff to the dialog's
constructor. There is also some other class methods for other
interactions.
My problem is this: The list box does not word wrap. If I submit a text
line wider then the list box, my subclassed list box automatically
adjusts the horizontal scroll bars. But what I would really want is
word wrap.
Is there a way to implement word wrap with a list box?
OR
Should I be using some other control?
OR
Is there some other way to accomplish my needs?