GetGadgetItemState and ListIconGadget

Just starting out? Need help? Post your questions and find answers here.
User avatar
HeX0R
Addict
Addict
Posts: 1218
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: GetGadgetItemState and ListIconGadget

Post by HeX0R »

So windows only?

Code: Select all

EnableExplicit

Import "Comctl32.lib" 
  SetWindowSubclass(hWnd, *fnSubclass, uIdSubclass, dwRefData)
  GetWindowSubclass(hWnd, *fnSubclass, uIdSubclass, *dwRefData)
  RemoveWindowSubclass(hWnd, *fnSubclass, uIdSubclass)
  DefSubclassProc(hWnd, uMsg, wParam, lParam)
EndImport 

Structure _DATA_
	window.i
	gadget.i
EndStructure

#Type_Checkbox_Changed = #PB_EventType_FirstCustomValue

Define i

Procedure LVProc(hwnd, msg, wparam, lparam, uIdSubclass, *d._DATA_)
	Protected hitinfo.LVHITTESTINFO

	Select msg
		Case #WM_NCDESTROY
			RemoveWindowSubclass(hWnd, @LVProc(), uIdSubclass)
			FreeStructure(*d)
		Case #WM_LBUTTONDOWN
			With hitinfo
				\pt\x = lparam & $FFFF
				\pt\y = lparam >> 16
			EndWith
			SendMessage_(hwnd, #LVM_SUBITEMHITTEST, 0, @hitInfo)
			PostEvent(#PB_Event_Gadget, *d\window, *d\gadget, #Type_Checkbox_Changed, hitinfo\iItem)
	EndSelect

	ProcedureReturn DefSubclassProc(hwnd, msg, wparam, lparam)
EndProcedure

Procedure AddSpecialListIconHandling(ParentWindow.i, ListIconGadget.i)
	Protected *d._DATA_
	
	*d         = AllocateStructure(_DATA_)
	*d\window  = ParentWindow
	*d\gadget  = ListIconGadget
	SetWindowSubclass(GadgetID(ListIconGadget), @LVProc(), 1, *d)
EndProcedure
	

OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 10, 10, 480, 380, "Column 1", 100, #PB_ListIcon_GridLines | #PB_ListIcon_CheckBoxes)
For i = 0 To 25
	AddGadgetItem(0, - 1, RSet(Chr(i + 65), 8, Chr(i + 65)))
Next i

AddSpecialListIconHandling(0, 0)


Repeat
	Select WaitWindowEvent()
		Case #PB_Event_CloseWindow
			Break
		Case #PB_Event_Gadget
			Select EventGadget()
				Case 0
					Select EventType()
						Case #Type_Checkbox_Changed
							i = EventData()
							If GetGadgetItemState(0, i) & #PB_ListIcon_Checked
								Debug "Checkbox #" + Str(i) + " => ticked!"
							Else
								Debug "Checkbox #" + Str(i) + " => unticked!"
							EndIf
						Case #PB_EventType_Change
							Debug "Selected item changed? => " + Str(GetGadgetState(0))
					EndSelect
			EndSelect
	EndSelect
ForEver
jak64
Enthusiast
Enthusiast
Posts: 639
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: GetGadgetItemState and ListIconGadget

Post by jak64 »

Thanks mk-soft for your code
jak64
Enthusiast
Enthusiast
Posts: 639
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: GetGadgetItemState and ListIconGadget

Post by jak64 »

Thanks HeX0R,
It works great
User avatar
ChrisR
Addict
Addict
Posts: 1484
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: GetGadgetItemState and ListIconGadget

Post by ChrisR »

Nice example of subclass HeXOR
Works well if you click on the 1st column, but not if you click on the empty "2nd" column.
Looks good with hitinfo\pt\x = 0, by deleting or commenting the line:

Code: Select all

;\pt\x = lparam & $FFFF
User avatar
HeX0R
Addict
Addict
Posts: 1218
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: GetGadgetItemState and ListIconGadget

Post by HeX0R »

the "empy" column is in fact outside the defined area (there is no second column), so from my point of view the code works correct.
No idea why you want to catch clicks outside of the defined area, but sure, you can fool it by setting x position to 0.
User avatar
ChrisR
Addict
Addict
Posts: 1484
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: GetGadgetItemState and ListIconGadget

Post by ChrisR »

I understood well for the drawing area, although it appears as a 2nd column for the ListIcon. So, it is probably better not to send a Postevent if hitinfo\iItem = -1 (rather than \pt\x =0) to not receive a #Type_Checkbox_Changed msg, which can be confusing in this case.
Post Reply