Paul i cant get an ownerdrawn combobox to work, the items in the list are drawn correctly,
but it seems like i am not receiving the notification message to owner draw the text when
the combobox is closed...
Do you have an example?
Here is an example based on Borje's color selector combobox:
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Basic QB color function.
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
Function GetQBColor( ByVal c As Long ) As Long
Select Case c
Case 0 : Function = RGB(0,0,0) ' Black
Case 1 : Function = RGB(0,0,128) ' Blue
Case 2 : Function = RGB(0,128,0) ' Green
Case 3 : Function = RGB(0,128,128) ' Cyan
Case 4 : Function = RGB(196,0,0) ' Red
Case 5 : Function = RGB(128,0,128) ' Magenta
Case 6 : Function = RGB(128,64,0) ' Brown
Case 7 : Function = RGB(196,196,196) ' Light Gray
Case 8 : Function = RGB(128,128,128) ' Gray
Case 9 : Function = RGB(0,0,255) ' Light Blue
Case 10 : Function = RGB(0,255,0) ' Light Green
Case 11 : Function = RGB(0,255,255) ' Light Cyan
Case 12 : Function = RGB(255,0,0) ' Light Red
Case 13 : Function = RGB(255,0,255) ' Light Magenta
Case 14 : Function = RGB(255,255,0) ' Yellow
Case 15 : Function = RGB(255,255,255) ' Bright White
End Select
End Function
'------------------------------------------------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
hWndForm As Dword, _ ' handle of Form
ByVal UserData As Long _ 'optional user defined Long value
) As Long
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Black"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Blue"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Green"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Cyan"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Red"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Magenta"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Brown"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Light Gray"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Gray"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Light Blue"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Light Green"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Light Cyan"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Light Red"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Light Magenta"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Yellow"
FF_ComboBox_AddString HWND_FORM1_COMBO1, "Bright White"
FF_ComboBox_SetCurSel HWND_FORM1_COMBO1, 0
End Function
'------------------------------------------------------------------------------------------------------------------------
Function FORM1_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Local lpdis As DRAWITEMSTRUCT Ptr
Local rct As Rect
Local zTxt As Asciiz * 80
Local hBrush As Long
Select Case wMsg
Case %WM_DRAWITEM
lpdis = lParam
If @lpdis.itemID = &HFFFFFFFF& Then Exit Function
Select Case @lpdis.itemAction
Case %ODA_DRAWENTIRE, %ODA_SELECT
' CLEAR BACKGROUND
FillRect @lpdis.hDC, @lpdis.rcItem, GetSysColorBrush(%COLOR_WINDOW)
' GET/DRAW TEXT
SendMessage @lpdis.hWndItem, %CB_GETLBTEXT, @lpdis.itemID, VarPtr(zTxt) 'Get text
SetBkColor @lpdis.hDC, GetSysColor(%COLOR_WINDOW) 'Set text Background
SetTextColor @lpdis.hDC, GetSysColor(%COLOR_WINDOWTEXT) 'Set text color
rct = @lpdis.rcItem
rct.nLeft = 28
DrawText @lpdis.hDC, zTxt, Len(zTxt), rct, %DT_SINGLELINE Or %DT_LEFT Or %DT_VCENTER
' SELECTED ITEM
If (@lpdis.itemState And %ODS_SELECTED) Then 'if selected
If (@lpdis.itemState And &H1000) = 0 Then 'if not %ODS_COMBOBOXEDIT (= &H1000)
rct.nLeft = 26 : rct.nRight = @lpdis.rcItem.nRight 'Set cordinates
rct.ntop = @lpdis.rcItem.ntop
rct.nbottom = @lpdis.rcItem.nbottom
InvertRect @lpdis.hDC, rct 'invert area around text only
End If
DrawFocusRect @lpdis.hDC, @lpdis.rcItem 'and draw a focus rectangle around all
End If
' PAINT COLOR RECTANGLE (using RoundRect for nicer looks.. :-)
If (@lpdis.itemState And &H1000) Then 'if %ODS_COMBOBOXEDIT (= &H1000)
rct.nLeft = 4 : rct.nRight = 24 'Set cordinates
Else
rct.nLeft = 3 : rct.nRight = 23 'a tiny bit to the left in list..
End If
rct.ntop = @lpdis.rcItem.ntop + 2
rct.nbottom = @lpdis.rcItem.nbottom - 2
hBrush = CreateSolidBrush(GetQBColor(@lpdis.itemID)) 'Create brush with proper color
hBrush = SelectObject(@lpdis.hDC, hBrush) 'Select brush into device context
RoundRect @lpdis.hDC, rct.nLeft, rct.ntop, rct.nRight, rct.nbottom, 3, 3 'Draw
DeleteObject SelectObject(@lpdis.hDC, hBrush) 'Select old brush back and delete new one
End Select
Function = %TRUE : Exit Function
End Select
End Function
Perfect! Thanx. :)