From: Dinakara on
Hi,

I am using a list view in the icon mode and I need to display icon texts as
multilane strings. In order to do this, I am handling NM_CUSTOMDRAW as given
below :

void MyListViewC::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{

LPNMLVCUSTOMDRAW lpLVCustomDraw =
reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);
CListCtrl& list_ctrl = GetListCtrl();

CRect TextRect; //Store the rectangle in which text is dispayed in this
rectangle.
switch(lpLVCustomDraw->nmcd.dwDrawStage)
{
case CDDS_ITEMPREPAINT:
case CDDS_ITEMPREPAINT | CDDS_SUBITEM:

//Get the rectangle area at whcih the icon text is displayed. and
inflate it.
if( TRUE ==
list_ctrl.GetItemRect(lpLVCustomDraw->nmcd.dwItemSpec,&TextRect,LVIR_LABEL))
{
TextRect.bottom += 5;
lpLVCustomDraw->rcText = TextRect;
}
}
}

*pResult = 0;
*pResult |= CDRF_NOTIFYPOSTPAINT;
*pResult |= CDRF_NOTIFYITEMDRAW;
*pResult |= CDRF_NOTIFYSUBITEMDRAW;

}

But as soon as this function returns, the program crashes : the call stack
points at the BEGIN_MESSAGE_MAP line as the line at which the code has
crashed.

I have two questions :

1. Is that the correct way to increase the display area for the icon text ?
2. How do I find out what the problem is ;( Because the code point is
BEGIN_MESSAGE_MAP )

Thanks in advance.... and sorry for the big mail :-)

- GSD.


From: Doug Harrison [MVP] on
On Tue, 3 Oct 2006 19:20:24 +0530, "Dinakara" <Dinakara.gs(a)in.bosch.com>
wrote:

>Hi,
>
>I am using a list view in the icon mode and I need to display icon texts as
>multilane strings. In order to do this, I am handling NM_CUSTOMDRAW as given
>below :
>
>void MyListViewC::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
>{
>
> LPNMLVCUSTOMDRAW lpLVCustomDraw =
>reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);
> CListCtrl& list_ctrl = GetListCtrl();
>
> CRect TextRect; //Store the rectangle in which text is dispayed in this
>rectangle.
> switch(lpLVCustomDraw->nmcd.dwDrawStage)
> {
> case CDDS_ITEMPREPAINT:
> case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
>
> //Get the rectangle area at whcih the icon text is displayed. and
>inflate it.
> if( TRUE ==
>list_ctrl.GetItemRect(lpLVCustomDraw->nmcd.dwItemSpec,&TextRect,LVIR_LABEL))
> {
> TextRect.bottom += 5;
> lpLVCustomDraw->rcText = TextRect;
> }
> }
> }
>
>*pResult = 0;
>*pResult |= CDRF_NOTIFYPOSTPAINT;
>*pResult |= CDRF_NOTIFYITEMDRAW;
>*pResult |= CDRF_NOTIFYSUBITEMDRAW;
>
>}
>
>But as soon as this function returns, the program crashes : the call stack
>points at the BEGIN_MESSAGE_MAP line as the line at which the code has
>crashed.

What does your message map entry look like? It should resemble:

ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)

>I have two questions :
>
>1. Is that the correct way to increase the display area for the icon text ?

No. You will have to use an owner-draw control and handle WM_MEASUREITEM;
see this article for more:

http://www.codeproject.com/listctrl/changerowheight.asp

It might also be possible to control row height with a carefully
constructed image list.

>2. How do I find out what the problem is ;( Because the code point is
>BEGIN_MESSAGE_MAP )

Good question. Assuming your message map entry checks out, it will probably
involve some single-stepping.

--
Doug Harrison
Visual C++ MVP
From: Michael K. O'Neill on

"Dinakara" <Dinakara.gs(a)in.bosch.com> wrote in message
news:eftpks$up1$1(a)news4.fe.internet.bosch.com...
> Hi,
>
> I am using a list view in the icon mode and I need to display icon texts
as
> multilane strings. In order to do this, I am handling NM_CUSTOMDRAW as
given
> below :
>
> void MyListViewC::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
> {
>
> LPNMLVCUSTOMDRAW lpLVCustomDraw =
> reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);
> CListCtrl& list_ctrl = GetListCtrl();
>
> CRect TextRect; //Store the rectangle in which text is dispayed in
this
> rectangle.
> switch(lpLVCustomDraw->nmcd.dwDrawStage)
> {
> case CDDS_ITEMPREPAINT:
> case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
>
> //Get the rectangle area at whcih the icon text is displayed. and
> inflate it.
> if( TRUE ==
>
list_ctrl.GetItemRect(lpLVCustomDraw->nmcd.dwItemSpec,&TextRect,LVIR_LABEL))
> {
> TextRect.bottom += 5;
> lpLVCustomDraw->rcText = TextRect;



*** Possible problem right here: see below ***



> }
> }
> }
>
> *pResult = 0;
> *pResult |= CDRF_NOTIFYPOSTPAINT;
> *pResult |= CDRF_NOTIFYITEMDRAW;
> *pResult |= CDRF_NOTIFYSUBITEMDRAW;
>
> }
>
> But as soon as this function returns, the program crashes : the call stack
> points at the BEGIN_MESSAGE_MAP line as the line at which the code has
> crashed.
>
> I have two questions :
>
> 1. Is that the correct way to increase the display area for the icon text
?
> 2. How do I find out what the problem is ;( Because the code point is
> BEGIN_MESSAGE_MAP )
>
> Thanks in advance.... and sorry for the big mail :-)
>
> - GSD.
>
>

You might be encountering a problem because you are giving the list-view
control a stack rectangle that goes out of scope as soon as the function
returns.

Try setting the individual values in rcText instead:

lpLVCustomDraw->rcText.left = TextRect.left;
lpLVCustomDraw->rcText.top = TextRect.top;
....etc.

I don't think that this is the way to increase the display area for icon
text, but it might fix your crash.

Mike



 | 
Pages: 1
Prev: CString to constant char *
Next: PNG as a resource