When ever I am redrawing the Owner Drawn List box in Windows NT. I am
getting corrupted LPDRAWITEMSTRUCT structure.
I am sending LB_SETITEMDATA message to set a value(structure LISTITEMINFO)
associated with the specified item in the list box.
typedef struct tagLISTITEMINFO
{
DWORD dwType;
DWORD dwFlags;
LPSTR szString;
} LISTITEMINFO;
I am sending message WM_SETREDRAW to the list box to redraw the list box.
Message handler procedures lparam should be the structure LPDRAWITEMSTRUCT.
LPDRAWITEMSTRUCT is corrupting in windowsNT and in windows 2000 it is fine.
I am not able to under stand why LPDRAWITEMSTRUCT is corrupted in
windowsNT.
Please help me in this mater.
Thanks,
Venkat.
>Hi All,
>
>When ever I am redrawing the Owner Drawn List box in Windows NT. I am
>getting corrupted LPDRAWITEMSTRUCT structure.
>I am sending LB_SETITEMDATA message to set a value(structure LISTITEMINFO)
>associated with the specified item in the list box.
>
> typedef struct tagLISTITEMINFO
>{
> DWORD dwType;
> DWORD dwFlags;
> LPSTR szString;
>
>} LISTITEMINFO;
>
>
>I am sending message WM_SETREDRAW to the list box to redraw the list box.
Why? WM_SETREDRAW(false) turns off drawing so you can add or delete a bunch
of items without the listbox redrawing itself for each one.
WM_SETREDRAW(true) turns drawing back on.
>Message handler procedures lparam should be the structure LPDRAWITEMSTRUCT.
>LPDRAWITEMSTRUCT is corrupting in windowsNT and in windows 2000 it is fine.
>I am not able to under stand why LPDRAWITEMSTRUCT is corrupted in
>windowsNT.
In what way is it corrupted? What message handler are you talking about?
Show the code which obtains the pointer and then describe the corruption.
--
Doug Harrison
Microsoft MVP - Visual C++
>The data in the memory to which lpDIS is pointing is
>- lpDIS 0x0012ee50
> CtlType 2
> CtlID 101
> itemID 4294967295
> itemAction 4
> itemState 16
>+ hwndItem 0x009a0250
>+ hDC 0xeb010723
>+ rcItem {top=0 bottom=13 left=0 right=38}
> itemData 4294967295
>
>This exception is not happening always it is happening some times only.
>When ever this exception happens itemID and itemData are same.
They're both -1. As documented, the DRAWITEMSTRUCT for a listbox has itemID
equal to -1 when the listbox is empty, so that you can draw a focus
rectangle using rcItem.
I don't know; if it's like you say, it could be a Windows bug. However, note
that rcItem is completely above the client area of the listbox, so if you do
draw the focus rectangle, it will be outside the listbox's clipping
rectangle, and nothing will be drawn. Does the listbox draw itself OK?
>I am getting the itemData and based on that I am displaying the list box.
>Because I am not getting proper data in itemData when I try to type cast to
>the required struture, application gives the exception
>Unhandled exception in *.exe (*.dll):0xC0000005: Access Violation
You can't assume the itemID is valid. Cast it to int, and if it's negative,
don't look at itemData. Per the docs, look only at rcItem, and draw the
focus rectangle there. Even if Windows is sending you spurious WM_DRAWITEMs
for items that don't exist in non-empty listboxes, as long as you follow
this protocol, you'll never know, because per your last message, the rcItem
is outside the control's clipping rectangle. I use ownerdraw listboxes with
per-item data a lot and I've never noticed any problem in this area. If
Windows is sending me spurious WM_DRAWITEM messages, I've never noticed,
because per the docs, I know it can send me WM_DRAWITEM with itemID equal to
-1, and I don't use itemData in that case, because it would be meaningless.