Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting currupted DRAWITEMSTRUCT data while redrawing ownerdrawn ListBox in Windows NT.

334 views
Skip to first unread message

Venkat

unread,
Jul 21, 2003, 6:14:53 AM7/21/03
to
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.

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.

Doug Harrison [MVP]

unread,
Jul 21, 2003, 1:18:39 PM7/21/03
to
Venkat wrote:

>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++

Venkat

unread,
Jul 22, 2003, 6:07:01 AM7/22/03
to
 
"Doug Harrison [MVP]" <d...@mvps.org> wrote in message news:1l7ohvknjerdtarj9...@4ax.com...
LRESULT EXPORTAPI ListWndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
DWORD dwIFlag;
 case WM_DRAWITEM:
            lpDIS = (LPDRAWITEMSTRUCT)lParam;
 
=> dwIFlag = ((LISTITEMINFO)lpDIS->itemData)->dwFlags (Unhandled exception in *.exe (*.dll):0xC0000005: Access Violation)
}
 
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.

Doug Harrison [MVP]

unread,
Jul 22, 2003, 12:42:55 PM7/22/03
to
Venkat wrote:

>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.

Venkat

unread,
Jul 31, 2003, 12:16:09 PM7/31/03
to
Dear Doug Harrison,

Greetings.
 
In windowsNT if I add the item to Owner Drawn list box with message LB_ADDSTRING and
If I remove the string, if it is duplicate using the message LB_DELETESTRING
data in lpDis->itemID and lpDis->itemData is becoming -1 in message handler under WM_DRAWITEM.
List box is having items. List box is not empty.

LRESULT EXPORTAPI ListWndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
LPDRAWITEMSTRUCT lpDIS;
switch (iMsg)
    {

case WM_DRAWITEM:
            lpDIS = (LPDRAWITEMSTRUCT)lParam;
    }
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}
 
void ListMembersInsertItem()
{
 
// add list item
nIndex = (int)SendMessage(hWndList, LB_ADDSTRING, 0, (LONG)szListItem);
 
// if the item is duplicated delete item and dont set the list box
// item data.
SendMessage(hWndList, LB_DELETESTRING, nIndex, 0);
 
// if the item is not duplicated set the list box item data
// using LB_SETITEMDATA.
}
 
If I add string using message LB_ADDSTRING and delete the string
if it is duplicate with message LB_DELETESTRING.
 
I am getting -1 in itemID and itemData in DRAWITEMSTRUCTURE
 
- lpDIS 0x0012eeac

 CtlType 2
 CtlID 101
 itemID 4294967295
 itemAction 4
 itemState 16
+ hwndItem 0x0af200b2
+ hDC 0x0401063a
+ rcItem {top=-13 bottom=0 left=0 right=58}
 itemData 4294967295
 
What will be the reason?
 

Thanks & Regards,
Venkat.

Doug Harrison [MVP]

unread,
Jul 31, 2003, 2:10:16 PM7/31/03
to
Venkat wrote:

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?

Venkat

unread,
Aug 1, 2003, 6:51:42 AM8/1/03
to
"Doug Harrison [MVP]" <d...@mvps.org> wrote in message news:k8miivgg0i9p757h8...@4ax.com...
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
> --
> Doug Harrison
> Microsoft MVP - Visual C++
 
Thanks,
Venkat.

Doug Harrison [MVP]

unread,
Aug 1, 2003, 12:25:10 PM8/1/03
to
Venkat wrote:

>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.

0 new messages