Some said it was too hard...
Others said it was useless...
Localmotion34 was bothered by this problem...
So here it is COMBOCHECKLISTBOX. a combobox with the ability to check and uncheck items, and even use radio or pushbuttons in the combobox. the dafualt behavior is the checkbox, but you can comment out or use whatever combination of drawframecontrol you like.
HERE IS THE SECRET:
buried DEEP in the MSDN code is:
Structure comboboxinfo
cbSize.l
rcItem.RECT
rcButton.RECT
stateButton.l
hwndCombo.l
hwndEdit.l
hwndList.l
EndStructure
*combostruct.comboboxinfo=HeapAlloc_(GetProcessHeap_(), 0, SizeOf(comboboxinfo))
*combostruct\cbSize=SizeOf(comboboxinfo)
GetComboBoxInfo_(GadgetID(combo),*combostruct.comboboxinfo)
GETCOMBOBOXINFO returns the actual HANDLE of the combo's listbox!!!! hence you may SUBCLASS the listbox and do what you want. HMMM, think for this one i could get a bump up on the tickmarks of my name?? hmmmm........
here is the example:
Code: Select all
Enumeration
#Window_0
EndEnumeration
Enumeration
#Gadget_0
EndEnumeration
#DI_NORMAL = $0003
Structure combo
State.l
hwnd.l
subclassed.l
EndStructure
Structure comboboxinfo
cbSize.l
rcItem.RECT
rcButton.RECT
stateButton.l
hwndCombo.l
hwndEdit.l
hwndList.l
EndStructure
Procedure MakeLong1(low, high)
ProcedureReturn low | high <<16
EndProcedure
#LB_ITEMFROMPOINT=$1A9
Procedure checkProc( hwnd, msg,wParam,lParam)
*class.s=Space(255)
cs=GetClassName_(hwnd,*class,Len(*class))
If *class="ComboLBox"
Select msg
Case #WM_LBUTTONDOWN
If wParam = #MK_LBUTTON
xloc.w=lParam&$FFFF
yloc.w = (lParam>>16)
t = SendMessage_(hwnd, #LB_ITEMFROMPOINT, 0, MakeLong1(xloc,yloc))
y=SendMessage_(hwnd, #LB_GETITEMRECT, t, @rct.RECT)
rct\left=2
rct\right=15
If PtInRect_(rct, xloc, yloc)
*combostruct.comboboxinfo=GetProp_(hwnd,"LBinfo")
State=SendMessage_(*combostruct\hwndCombo, #CB_GETITEMDATA, t, 0)
If State=0
SendMessage_(*combostruct\hwndCombo, #CB_SETITEMDATA, t, 1)
InvalidateRect_(hwnd, rct, 0): UpdateWindow_(hwnd )
ElseIf State=1
SendMessage_(*combostruct\hwndCombo, #CB_SETITEMDATA, t, 0)
InvalidateRect_(hwnd, rct, 0): UpdateWindow_(hwnd)
EndIf
EndIf
EndIf
ProcedureReturn CallWindowProc_(GetProp_(hwnd,"oldproc4"),hwnd,msg,wParam,lParam)
EndSelect
EndIf
ProcedureReturn CallWindowProc_(GetProp_(hwnd,"oldproc4"),hwnd,msg,wParam,lParam)
EndProcedure
Procedure WindowCallback(WindowID, message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
Select message
Case #WM_DRAWITEM
*DrawItem.DRAWITEMSTRUCT = lParam
listhwnd=WindowFromDC_(*DrawItem\hdc)
If *DrawItem\CtlType = #ODT_COMBOBOX
SetBkMode_(*DrawItem\hdc, #TRANSPARENT) ; Text is rendered transparent
If *DrawItem\itemState & #ODS_FOCUS
Brush = CreateSolidBrush_($FFEEFF)
FillRect_(*DrawItem\hdc, *DrawItem\rcItem, Brush)
DeleteObject_(Brush)
SetTextColor_(*DrawItem\hdc, $FF)
Else
FillRect_(*DrawItem\hdc, *DrawItem\rcItem, GetStockObject_(#WHITE_BRUSH))
EndIf
If *DrawItem\itemID <> -1
Text$ = Space(512)
SendMessage_(*DrawItem\hwndItem, #CB_GETLBTEXT, *DrawItem\itemID, @Text$)
TextOut_ (*DrawItem\hdc, *DrawItem\rcItem\left+2+20, *DrawItem\rcItem\top+1, Text$, Len(Text$))
*DrawItem\rcItem\left = 2 : *DrawItem\rcItem\right = 15
*DrawItem\rcItem\top + 2
*DrawItem\rcItem\bottom - 1
State=SendMessage_(*DrawItem\hwndItem, #CB_GETITEMDATA, *DrawItem\itemID, 0)
If State=0
DrawFrameControl_(*DrawItem\hdc,*DrawItem\rcItem,#DFC_BUTTON,#DFCS_BUTTONCHECK)
;drawframecontrol_(*DrawItem\hdc,*DrawItem\rcItem,#DFC_BUTTON, #DFCS_BUTTONPUSH)
;drawframecontrol_(*DrawItem\hdc,*DrawItem\rcItem,#DFC_BUTTON, #DFCS_BUTTONRADIO)
ElseIf State=1
DrawFrameControl_(*DrawItem\hdc,*DrawItem\rcItem,#DFC_BUTTON,#DFCS_BUTTONCHECK|#DFCS_CHECKED)
;drawframecontrol_(*DrawItem\hdc,*DrawItem\rcItem,#DFC_BUTTON, #DFCS_BUTTONPUSH |#DFCS_CHECKED)
;drawframecontrol_(*DrawItem\hdc,*DrawItem\rcItem,#DFC_BUTTON,#DFCS_BUTTONRADIO|#DFCS_CHECKED)
EndIf
EndIf
EndIf
EndSelect
ProcedureReturn Result
EndProcedure
Procedure Open_Window_0()
If OpenWindow(#Window_0, 0, 0, 400, 100, "New window ( 0 )", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_TitleBar)
If CreateGadgetList(WindowID(#Window_0))
ComboBoxGadget(#Gadget_0, 60, 40, 330, 200, #CBS_OWNERDRAWFIXED)
*combostruct.comboboxinfo=HeapAlloc_(GetProcessHeap_(), 0, SizeOf(comboboxinfo))
*combostruct\cbSize=SizeOf(comboboxinfo)
GetComboBoxInfo_(GadgetID(#Gadget_0),*combostruct.comboboxinfo)
SetProp_(*combostruct\hwndList,"OldProc4",SetWindowLong_(*combostruct\hwndList, #GWL_WNDPROC, @checkProc()))
SetProp_(*combostruct\hwndList,"LBinfo",*combostruct.comboboxinfo)
EndIf
EndIf
EndProcedure
Open_Window_0()
SetWindowCallback(@WindowCallback())
AddGadgetItem(#Gadget_0, -1, "Test1")
AddGadgetItem(#Gadget_0, -1, "Test2")
AddGadgetItem(#Gadget_0, -1, "Test3")
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End