Page 1 of 1

Posted: Thu Nov 29, 2007 9:00 pm
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

Posted: Thu Nov 29, 2007 9:17 pm
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

Posted: Fri Nov 30, 2007 4:31 am
by netmaestro
Fixed a bug in the posted code where the #gadget was being reported incorrectly, also streamlined the code a bit.