Rigth click detection on listicon header

Windows specific forum
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Rigth click detection on listicon header

Post 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

Windows 10 Pro x64
PureBasic 6.04 x64
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Rigth click detection on listicon header

Post 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

Egypt my love
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: Rigth click detection on listicon header

Post by tatanas »

Oh I see.
Thank you RASHAD.
Windows 10 Pro x64
PureBasic 6.04 x64
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Rigth click detection on listicon header

Post by Kwai chang caine »

Thanks RASHAD :wink:
ImageThe happiness is a road...
Not a destination
Post Reply