listicongadget Column header detect
listicongadget Column header detect
I know this may be a case of RTFM but I have been having trouble figuring out how to detect which column header has been clicked on when using the listicongadget?
Cheers
Andrewr
			
			
									
									
						Cheers
Andrewr
Here's one way :
			
			
									
									Code: Select all
Procedure.l WinProc(hWnd, uMsg, wParam, lParam) 
  Protected *nml.NM_LISTVIEW 
  result = #PB_ProcessPureBasicEvents 
  Select uMsg 
    Case #WM_NOTIFY 
      *nml = lParam 
      Select *nml\hdr\code 
        Case #LVN_COLUMNCLICK 
          Debug "Header item "+Str(*nml\iSubItem)+" clicked!" 
      EndSelect 
  EndSelect 
  ProcedureReturn result 
EndProcedure 
If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateGadgetList(WindowID(0))
    ListIconGadget(0, 5, 5, 290, 90, "Name", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
    AddGadgetColumn(0, 1, "Address", 250)
    AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
    AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
    SetWindowCallback(@WinProc())
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
EndIf
I may look like a mule, but I'm not a complete ass.
						thanks, what if Panel_0 stops working?
Hi,
At first I just wanted to say Thanks you guys!!
I tried the above code snippet and it works pretty well.
Couple things:
1) Any idea why the very first time I click on any column header it seems to be ignored? I have to click one more time and after that I only have to click once on each column header and it works great! But that very first click just doesn't do a thing...
2) Now the Tabs / Panel gadget seems to be failing altogether. It has the standard name of Panel_0 and works fine so long as I comment out the above code. But then I don't have column header click detection so it's a bit of a trade off it seems.
Either I get column header click notifications (and then Panel_0 fails) or I can have Panel_0 back if I forfeit having the Windows call back that makes the header click notifiers kick in.
Anyone have a recommendation for dealing with this side effect?
Thanks!!
Roark
			
			
									
									
						At first I just wanted to say Thanks you guys!!
I tried the above code snippet and it works pretty well.
Couple things:
1) Any idea why the very first time I click on any column header it seems to be ignored? I have to click one more time and after that I only have to click once on each column header and it works great! But that very first click just doesn't do a thing...
2) Now the Tabs / Panel gadget seems to be failing altogether. It has the standard name of Panel_0 and works fine so long as I comment out the above code. But then I don't have column header click detection so it's a bit of a trade off it seems.
Either I get column header click notifications (and then Panel_0 fails) or I can have Panel_0 back if I forfeit having the Windows call back that makes the header click notifiers kick in.
Anyone have a recommendation for dealing with this side effect?
Thanks!!
Roark
- netmaestro
 - PureBasic Bullfrog

 - Posts: 8452
 - Joined: Wed Jul 06, 2005 5:42 am
 - Location: Fort Nelson, BC, Canada
 
You can use a subclass as an alternative to a window callback, this way you can find the click message in your PB event loop. Also, it won't interfere with your panel gadget.
			
			
													Code: Select all
#HEADERCLICKED = #WM_APP + 1 
Procedure HeaderProc(hwnd, msg, wparam, lparam) 
  
  oldproc = GetProp_(hwnd, "oldproc") 
  Select msg 
    Case #WM_NCDESTROY 
      RemoveProp_(hwnd, "oldproc") 
      
    Case #WM_LBUTTONUP 
      With hd_hti.HD_HITTESTINFO 
        \pt\x=lparam&$FFFF 
        \pt\y=lparam>>16 
      EndWith 
      SendMessage_(hwnd, #HDM_HITTEST,0,hd_hti) 
      If hd_hti\flags & #HHT_NOWHERE=0 And hd_hti\flags&#HHT_ONDIVIDER=0 And hd_hti\iItem>=0
        PostMessage_(WindowID(0),#HEADERCLICKED, hd_hti\iItem, GetDlgCtrlID_(GetParent_(hwnd))) 
      EndIf 
      
  EndSelect 
  
  ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam) 
EndProcedure 
If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
    ListIconGadget(0, 5, 5, 290, 90, "Name", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection) 
    AddGadgetColumn(0, 1, "Address", 250) 
    AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay") 
    AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity") 
    
    header = SendMessage_(GadgetID(0),#LVM_GETHEADER,0,0) 
    SetProp_(header, "oldproc", SetWindowLongPtr_(header,#GWL_WNDPROC,@HeaderProc())) 
    
    Repeat 
      Event = WaitWindowEvent() 
      Select Event 
        Case #HEADERCLICKED 
          button = EventwParam() 
          gadget = EventlParam() 
          Debug "Header button " + Str(button) + " clicked on gadget# "+Str(gadget) 
      EndSelect 
    Until Event = #PB_Event_CloseWindow 
EndIf 
					Last edited by netmaestro on Wed Apr 22, 2009 11:55 am, edited 1 time in total.
									
			
									BERESHEIT
						thanks netmaestro
Thanks netmaestro,
It can be a lonely world out there so it's always nice to feel like other PB enthusiasts are around and willing to share. Thanks for sharing as often as you do. Your code snippets are often just the trick that is needed to solve the problem at hand.
I only now was able to open t his message or I would have responded to thank you earlier, but the link in the email that arrived was slightly garbled. Fortunately I was eventually able to piece things together to figure out what the link should be to read your helpful response!
I'll let you know if I have any other questions on this topic but I suspect this code snippet you were kind enough to provide will be all that is needed.
Cheers,
Roark
			
			
									
									
						It can be a lonely world out there so it's always nice to feel like other PB enthusiasts are around and willing to share. Thanks for sharing as often as you do. Your code snippets are often just the trick that is needed to solve the problem at hand.
I only now was able to open t his message or I would have responded to thank you earlier, but the link in the email that arrived was slightly garbled. Fortunately I was eventually able to piece things together to figure out what the link should be to read your helpful response!
I'll let you know if I have any other questions on this topic but I suspect this code snippet you were kind enough to provide will be all that is needed.
Cheers,
Roark
- netmaestro
 - PureBasic Bullfrog

 - Posts: 8452
 - Joined: Wed Jul 06, 2005 5:42 am
 - Location: Fort Nelson, BC, Canada
 
Listicon Gadget, finer details
Well netmaestro, all I can say is you certainly pay attention to some of the finer details and.. you rock!
I tried implementing your fix into the program and it works. Not only that, I managed to have it working on several listicon gadgets!
Mille Grazie,
Roark
