Hi,
I want to add functionality to an owner-drawn listbox. I seem to run into a memory related problem. Since I just became a member, I have only 80 points available, which I offer for an answer.
Here is some code (not complete, just to outline my problem):
A User-Datatype is used to store additional information for each listbox item. Note bDontShowIcon as Boolean. This is the variable that I need to add to the Type definition.
Type ICONLISTBOXITEMINFO
lItemData As Long
lExtraData As Long
lIconIndex As Long
lIndentSize As Long
lItemHeight As Long
lForeColour As OLE_COLOR
lBackColour As OLE_COLOR
bUnderLineItem As Boolean
bOverLineItem As Boolean
dFontSize As Single
tLF As LOGFONT
lTextAlignX As Long
lTextAlignY As Long
bDontShowIcon As Boolean '<==
End Type
....
'Itemdata is written into a block of memory and attached to the listbox-item
'len(tLI)=105 without bDontShowIcon
'len(tLI)=107 with bDontShowIcon
Dim tLI as ICONLISTBOXITEMINFO
' Allocate the global memory to store the extended
' properties for this item:
hMem = GlobalAlloc(GPTR, Len(tLI))
tLI.lBackColour = lBackColour
tLI.lForeColour = lForeColour
tLI.lIndentSize = lIndent
tLI.lIconIndex = lIconIndex
tLI.lItemData = lItemData
tLI.bDontShowIcon = True '<==
....
' Store the item properties in memory
LPtr = GlobalLock(hMem)
' Copy the memory into tLI
CopyMemory ByVal lPtr, tLI, Len(tLI)
' Lock the memory again:
GlobalUnlock hMem
' Attach the block of memory to the listbox-item
wMsg = LB_SETITEMDATA
m_lR = SendMessageByLong(m_hWnd, wMsg, m_lNewItem, hMem)
-----------
Whenever I later access tLI.bDontShowIcon it is set to False. However, if I put "bDontShowIcon As Boolean" in first position in the Type definition
it later provides the correct value (that makes me wonder what this means for "lTextAlignY as Long", which will then be the last item in the Type definition). Also, if I keep "bDontShowIcon" where it is in the Type definition but add another *pseudo* variable after it, let's say: "lTest As Long", then subsequently tLI.bDontShowIcon works as expected everywhere in the code. Am I encountering a memory allocating problem here?
I am new to memory management functions, so I might be overlooking some simple mechanism here. Thanks for any help.
Start Free Trial