Page 1 of 1

Rigth click detection on listicon header

Posted: Thu May 28, 2020 7:31 am
by tatanas
Hi,

I've achieved the detection of right click on listicon header (not possible with purebasic function) by subclassing the gadget but I'm surprised that it's working that way.
Look at the code, the right click event is triggered only on header? Why not in the entire listicon ?

Code: Select all

Global oldproc

Procedure SubClass_LV(hwnd, msg, wparam, lparam)
	Protected result = CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
	
	Protected *nmh.NMHDR
	
	If msg = #WM_NOTIFY
		*nmh = lparam
		Select *nmh\code
			Case #NM_RCLICK
				Debug "rclick"
				
		EndSelect
	EndIf

;       Another solution
; 	If msg = #WM_PARENTNOTIFY And wparam = #WM_RBUTTONDOWN
; 		Debug "rclick"
; 	EndIf

	
	ProcedureReturn result
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")

	oldproc = SetWindowLongPtr_(GadgetID(ListView_ConsoleRA), #GWL_WNDPROC, @SubClass_LV())

   Repeat
     Event = WaitWindowEvent()
   Until Event = #PB_Event_CloseWindow
 EndIf


Re: Rigth click detection on listicon header

Posted: Thu May 28, 2020 3:38 pm
by RASHAD
Hi
Header is totally different Class than ListView(ListIcon)

Code: Select all

Global oldproc ,header

Procedure SubClass_LV(hWnd, uMsg, wParam, lParam)
  result = CallWindowProc_(oldproc, hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_NOTIFY      
      *nmh.NMHDR  = lParam
      Select *nmh\code
        Case #NM_RCLICK
          GetCursorPos_ (@p.POINT)
          ScreenToClient_ (header, @p)
          nmhi.HD_HITTESTINFO
          nmhi\pt\x = p\x
          nmhi\pt\y = p\y
          SendMessage_(header,#HDM_HITTEST,0,@nmhi)
          index = nmhi\iItem
          Debug index 
      EndSelect        
    
    Case #WM_RBUTTONDOWN           
      nmlv.LVHITTESTINFO
      nmlv\pt\x = (lParam & $FFFF) 
      nmlv\pt\y = (lParam>> 16 & $FFFF)                    
      SendMessage_(GadgetID(0),#LVM_SUBITEMHITTEST,0,@nmlv)
      row = nmlv\iItem
      col = nmlv\iSubItem 
      Debug row 
      Debug col    
    EndSelect
    
   ProcedureReturn result
EndProcedure

 If OpenWindow(0, 0, 0, 300, 200, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
   ListIconGadget(0, 5, 5, 290, 190, "Name", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
   header = SendMessage_(GadgetID(0),#LVM_GETHEADER,0,0)
   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")

   oldproc = SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @SubClass_LV())

   Repeat
     Event = WaitWindowEvent()
   Until Event = #PB_Event_CloseWindow
 EndIf


Re: Rigth click detection on listicon header

Posted: Fri May 29, 2020 12:50 pm
by tatanas
Oh I see.
Thank you RASHAD.

Re: Rigth click detection on listicon header

Posted: Tue Jun 02, 2020 5:40 pm
by Kwai chang caine
Thanks RASHAD :wink: