Page 1 of 1

ListIconGadget Header with Toggle columns

Posted: Thu Jul 25, 2019 1:16 pm
by Lite
Hello

Search a solution for toogle columns in a header of listicongadget.
if pressed second column then colored to blue and the other should to red.

Here is my startcode:

Code: Select all


#ColoredColumn = 0


Global col=0
#HeaderTextColor = #Blue
#LVM_GETHEADER = #LVM_FIRST + 31

Define DefaultListIconCallback.I

Procedure CustomListIconCallback(WindowHandle.I, Msg.I, WParam.I, LParam.I)
  Shared DefaultListIconCallback.I

  Protected *NMCUSTOMDRAW.NMCUSTOMDRAW
  Protected *NMHDR.NMHDR
  Protected Result.I

  Result = CallWindowProc_(DefaultListIconCallback, WindowHandle.I, Msg.I,
    WParam.I, LParam.I)

  If Msg = #WM_NOTIFY
    *NMHDR = LParam
    
          *NMCUSTOMDRAW = LParam
      
      
       SetTextColor_(*NMCUSTOMDRAW\hdc, #Red)
    
    If *NMHDR\code = #NM_CUSTOMDRAW
          
      *NMCUSTOMDRAW = LParam
      
      Select *NMCUSTOMDRAW\dwDrawStage
        Case #CDDS_PREPAINT
          Result = #CDRF_NOTIFYITEMDRAW
        Case #CDDS_ITEMPREPAINT
          If *NMCUSTOMDRAW\dwItemSpec = col
            SetTextColor_(*NMCUSTOMDRAW\hdc, #HeaderTextColor)
          Else  
            SetTextColor_(*NMCUSTOMDRAW\hdc, #Red)
          EndIf
          
                     
         If *NMCUSTOMDRAW\uItemState & #CDIS_SELECTED  

         col=*NMCUSTOMDRAW\dwItemSpec
        EndIf  
      
   
      EndSelect
    EndIf
  EndIf

  ProcedureReturn Result
EndProcedure

OpenWindow(0, 200, 100, 400, 150, "ListIconGadget with colored header text")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20,  "Name", 110, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", 150)  
AddGadgetColumn(0, 2, "test", 120)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ +
  "12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit" + #LF$ +
  "130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Didi Foundit" + #LF$ +
  "321 Logo Drive, Mouse House, Downtown")

DefaultListIconCallback = SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC,
  @CustomListIconCallback())

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Please help

Lite

Re: ListIconGadget Header with Toggle columns

Posted: Thu Jul 25, 2019 2:37 pm
by RASHAD
Hi

Code: Select all


Global header,col
col = -1

Procedure winCB(hWnd, uMsg, wParam, lParam)
 result = #PB_ProcessPureBasicEvents
 Select uMsg
    Case #WM_NOTIFY
      *pnmh.NMHEADER = lParam 
      Select *pnmh\hdr\code      
        Case #NM_CUSTOMDRAW       
          *nmcustom.NMCUSTOMDRAW = lParam     
            Select *nmcustom\dwDrawStage
              Case #CDDS_PREPAINT
                Result = #CDRF_NOTIFYITEMDRAW
              Case #CDDS_ITEMPREPAINT
                If *nmcustom\dwItemSpec = col
                  SetTextColor_(*nmcustom\hdc, #Red)
                Else
                  SetTextColor_(*nmcustom\hdc, #Blue)
                EndIf
                InvalidateRect_(header,0,1)
            EndSelect        
       
        Case #LVN_COLUMNCLICK
          *nmlv.NM_LISTVIEW = lParam
          col = *nmlv\iSubItem          
 
       EndSelect
               
 EndSelect
 ProcedureReturn result
EndProcedure


LoadFont(0,"Tahoma",12)

OpenWindow(0, 200, 100, 600, 150, "ListIconGadget with colored header text")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20,  "Name", 110, #PB_ListIcon_GridLines)
SetGadgetFont(0,FontID(0))
Header = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
AddGadgetColumn(0, 1, "Address", 150) 
AddGadgetColumn(0, 2, "test", 120)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ +
  "12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit" + #LF$ +
  "130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Didi Foundit" + #LF$ +
  "321 Logo Drive, Mouse House, Downtown")
SetWindowCallback(@winCB())
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: ListIconGadget Header with Toggle columns

Posted: Fri Jul 26, 2019 10:58 am
by Lite
@RASHAD

YEEEEEEEEEEEAAAAAAASSSSSSSSS, thats is it, thanks

Lite