I've been working on an owner drawn listbox, in Visual Basic. But, I've come to some problems... When running the program in VB, it works correctly, but if I compile it, and run it out of VB, it doesn't work at all how I want it too!
In VB =(http://darknet.darktech.org/1.png)
Compiled = (http://darknet.darktech.org/2.png)
(chose those icons because they're l33t :))
With DIS
'
' Get the text, indicated by DrawItemStruct.iItemID,
' from the listbox.
'
sString = Space$(128)
lRet = SendMessage(.hwndItem, LB_GETTEXT, .itemID, ByVal sString)
sString = Left$(sString, lRet)
'
' Create a logical font based on the font specified
' in the listbox.
'
lFont = CreateFont(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sString)
'
' Select the font into the new device context.
' Compute the width and height of a string of text (font name).
' Set the height of the listbox item accordingly.
'
Call SelectObject(.hdc, lFont)
Call GetTextExtentPoint32(.hdc, sString, Len(sString), tSize)
Call SendMessage(.hwndItem, LB_SETITEMHEIGHT, .itemID, ByVal tSize.cy)
'
' Set the color of the text of the list item
' based on whether the item is selected or not.
'
If .itemState And ODS_SELECTED Then
Call SetBkColor(.hdc, GetSysColor(COLOR_HIGHLIGHT))
Call SetTextColor(.hdc, GetSysColor(COLOR_HIGHLIGHTTEXT))
Else
Call SetBkColor(.hdc, GetSysColor(COLOR_WINDOW))
Call SetTextColor(.hdc, GetSysColor(COLOR_WINDOWTEXT))
End If
End With
'
' Draw the text in the listbox.
'
With DIS.rcItem
Call ImageList_Draw(Form1.ImageList1.hImageList, 0, DIS.hdc, .Left, .Top, 0)
Call TextOut(DIS.hdc, .Left + 30, .Top, sString, Len(sString))
Call ImageList_Draw(Form1.ImageList1.hImageList, 1, DIS.hdc, .Left + 115, .Top, 0)
End With
Call DeleteObject(lFont)
Its kinda like most XP manifest, except in a vice-versa way; they work when there compiled. Try using it on a listview while listbox inherits ListControl and a listview inherits control.