I'm using a listicons with already a popup menu when right-clicking on cells, I'm wondering if it's possible to have another popup menu when right-clicking on header. Also I need to know on which column there was right-click.
for the moment I'm using something modified from the following, coming from Rashad:
Code: Select all
Global oldCallback,ListIcon,CurSelItem,CurSelSubItem
Global pInfo.LVHITTESTINFO, pInfoold.LVHITTESTINFO
Procedure LIcallback(hwnd, msg, wparam, lparam)
result = CallWindowProc_(oldCallback, hwnd, msg, wparam, lparam)
Select msg
Case #WM_LBUTTONDOWN
pInfo\pt\x = (lParam & $FFFF)
pInfo\pt\y = (lParam>> 16 & $FFFF)
SendMessage_(hwnd,#LVM_SUBITEMHITTEST,0,@pInfo)
; ----- Backcolor the selected subitem -----
SetGadgetItemColor(0, pInfoold\iItem, #PB_Gadget_BackColor, $FFFFFF, pInfoold\iSubItem)
SetGadgetItemColor(0, pInfo\iItem, #PB_Gadget_BackColor, $DAD8FF, pInfo\iSubItem)
pInfoold=pInfo
Case #WM_RBUTTONDOWN
pInfo\pt\x = (lParam & $FFFF)
pInfo\pt\y = (lParam>> 16 & $FFFF)
SetGadgetItemColor(0, pInfoold\iItem, #PB_Gadget_BackColor, $FFFFFF, pInfoold\iSubItem)
SendMessage_(hwnd,#LVM_SUBITEMHITTEST,0,@pInfo)
pInfoold=pInfo
; ----- Backcolor the selected subitem -----
SetGadgetItemColor(0, pInfo\iItem, #PB_Gadget_BackColor, $DAD8FF, pInfo\iSubItem)
; ----- Find its rectangle
ItemRect.RECT
GetWindowRect_(hwnd, @GadgetRect.RECT)
If pInfo\iSubItem > 0 And pInfo\iItem >= 0
RtlZeroMemory_(@ItemRect,SizeOf(RECT))
ItemRect\top = pInfo\iSubItem
SendMessage_(hwnd,#LVM_GETSUBITEMRECT, pInfo\iItem, @ItemRect)
EndIf
; Position the rightclick menu tied to lower right of subitem's rectangle
DisplayPopupMenu(1, WindowID(5), GadgetRect\left + ItemRect\right, GadgetRect\top + ItemRect\top)
; ----- Reset the selected subitem's backcolor
SetGadgetItemColor(0, pInfo\iItem, #PB_Gadget_BackColor, $FFFFFF, pInfo\iSubItem)
; -------------------------------------
EndSelect
ProcedureReturn result
EndProcedure
OpenWindow(5,0,0,640,480,"Test",#PB_Window_SystemMenu| #PB_Window_ScreenCentered)
ListIcon = ListIconGadget(0,10,10,620,460,"",0,#PB_ListIcon_GridLines)
AddGadgetColumn(0,1,"Column 1",210)
AddGadgetColumn(0,2,"Column 2",200)
AddGadgetColumn(0,3,"Column 3",200)
For i = 1 To 16
linestr.s = LSet(Str(i),3," ")
AddGadgetItem(0, -1, Chr(10)+"Text on Line "+linestr+" in Column 1"+Chr(10)+"Text on Line "+linestr+" in Column 2"+Chr(10)+"Text on Line "+linestr+" in Column 3")
Next
oldCallback = SetWindowLongPtr_(ListIcon, #GWL_WNDPROC, @LIcallback())
hPMenu = CreatePopupMenu(1)
MenuItem(1, "Cut")
MenuItem(2, "Copy")
MenuItem(3, "Paste")
MenuItem(4, "Edit")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Menu
Select EventMenu()
Case 1 ; cut
SetClipboardText(GetGadgetItemText(0, pInfo\iItem, pInfo\iSubItem))
SetGadgetItemText(0, pInfo\iItem,"" ,pInfo\iSubItem)
Case 2 ; copy
ClearClipboard()
SetClipboardText(GetGadgetItemText(0, pInfo\iItem, pInfo\iSubItem))
Case 3 ; paste
SetGadgetItemText(0, pInfo\iItem,GetClipboardText(), pInfo\iSubItem)
Case 4 ; edit
ColumnHeader.s = GetGadgetItemText(0, -1, pInfo\iSubItem)
SetGadgetItemText(0, pInfo\iItem, InputRequester(ColumnHeader,"Make the changes desired to " + ColumnHeader+ "'s data.",GetGadgetItemText(0, pInfo\iItem, pInfo\iSubItem)), pInfo\iSubItem)
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow