ListIconGadget - capture header click {FIXED}

Just starting out? Need help? Post your questions and find answers here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Here's how I'd do it:

Code: Select all

CompilerIf #PB_OS_Windows 
  #WM_CUSTOM_LVH_RBUTTONDOWN = #WM_APP + 1 
  #WM_CUSTOM_LVH_RBUTTONUP   = #WM_APP + 2 
  #WM_CUSTOM_LVH_LBUTTONDOWN = #WM_APP + 3 
  #WM_CUSTOM_LVH_LBUTTONUP   = #WM_APP + 4 

  Procedure HitTest(hwnd, lparam)
    hti.hd_hittestinfo 
    hti\pt\x = lparam&$FFFF 
    hti\pt\y = lparam>>16 
    SendMessage_(hwnd, #HDM_HITTEST,0,@hti) 
    ProcedureReturn hti\iItem
  EndProcedure
  
  Procedure LV_HeaderCallBack(hwnd, msg, wparam, lparam) 
    Protected oldproc = GetProp_(hwnd, "oldproc") 
    Protected topwindow = GetProp_(hwnd, "topwindow")
    Select msg 
      Case #WM_NCDESTROY 
        RemoveProp_(hwnd, "oldproc") 
        RemoveProp_(hwnd, "topwindow") 
      Case #WM_RBUTTONUP 
        PostMessage_(topwindow,#WM_CUSTOM_LVH_RBUTTONUP,GetDlgCtrlID_(GetParent_(hwnd)),HitTest(hwnd,lparam)) 
      Case #WM_RBUTTONDOWN 
        PostMessage_(topwindow,#WM_CUSTOM_LVH_RBUTTONDOWN,GetDlgCtrlID_(GetParent_(hwnd)),HitTest(hwnd,lparam)) 
     Case #WM_LBUTTONDOWN 
        PostMessage_(topwindow,#WM_CUSTOM_LVH_LBUTTONDOWN,GetDlgCtrlID_(GetParent_(hwnd)),HitTest(hwnd,lparam)) 
      Case #WM_LBUTTONUP 
        PostMessage_(topwindow,#WM_CUSTOM_LVH_LBUTTONUP,GetDlgCtrlID_(GetParent_(hwnd)),HitTest(hwnd,lparam)) 
    EndSelect 
    ProcedureReturn CallWindowProc_(oldproc,hwnd,msg,wparam,lparam)  
  EndProcedure 
CompilerElse 
  ; Linux code 
CompilerEndIf 

OpenWindow(0,0,0,320,240,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
CreateGadgetList(WindowID(0)) 
ListIconGadget(33,0,0,320,240,"Column 0",100) 
AddGadgetColumn(33,1,"Column 1",215) 

CompilerIf #PB_OS_Windows 
  header = SendMessage_(GadgetID(33),#LVM_GETHEADER,0,0) 
  oldproc = SetWindowLong_(header,#GWL_WNDPROC, @LV_HeaderCallBack()) 
  SetProp_(header, "oldproc", oldproc) 
  SetProp_(header, "topwindow", WindowID(0)) 
CompilerElse #PB_OS_Linux 
  ; linux code 
CompilerEndIf 

Repeat 
  ev = WaitWindowEvent() 
  Select ev  
    CompilerIf #PB_OS_Windows 
      Case #WM_CUSTOM_LVH_LBUTTONDOWN 
        Debug "Left Button down for header item "+Str(EventlParam()) +" of ListIcon "+Str(EventwParam()) 
      Case #WM_CUSTOM_LVH_LBUTTONUP 
        Debug "Left Button up for header item "+Str(EventlParam()) +" of ListIcon "+Str(EventwParam()) 
      Case #WM_CUSTOM_LVH_RBUTTONDOWN 
        Debug "Right Button down for header item "+Str(EventlParam()) +" of ListIcon "+Str(EventwParam()) 
      Case #WM_CUSTOM_LVH_RBUTTONUP 
        Debug "Right Button up for header item "+Str(EventlParam()) +" of ListIcon "+Str(EventwParam()) 
    CompilerElse #PB_OS_Linux 
      ; Linux code 
    CompilerEndIf 
    ; more event tests 
  EndSelect 
Until ev = #WM_CLOSE
Last edited by netmaestro on Fri Nov 30, 2007 4:30 am, edited 1 time in total.
BERESHEIT
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Post by kinglestat »

thanks netmaestro
saved by the bell
I was tacking the wrong wind
I like the approach as its easier to make the diff linux/windows stuff
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Fixed a bug in the posted code where the #gadget was being reported incorrectly, also streamlined the code a bit.
BERESHEIT
Post Reply