Listicongadget column header color

Just starting out? Need help? Post your questions and find answers here.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Listicongadget column header color

Post by srod »

Code: Select all

#LVM_GETHEADER = #LVM_FIRST + 31 

; Globals 
  Global oldListIconCallback, hHeader, brush
  brush=CreateSolidBrush_(#Yellow)


Procedure SubclassedListIcon(hWnd, uMsg, wParam, lParam) 
  Protected hdi.hd_item
  result = CallWindowProc_(oldListIconCallback, hWnd, uMsg, wParam, lParam) 
  Select uMsg
    Case #WM_NOTIFY 
      *pnmh.NMHDR = lparam 
      ;--> Get handle to ListIcon header control 
        If *pnmh\code = #NM_CUSTOMDRAW
        *pnmcd.NMCUSTOMDRAW = lparam 
        ;--> Determine drawing stage 
        Select *pnmcd\dwDrawStage 
          Case #CDDS_PREPAINT 
            result = #CDRF_NOTIFYITEMDRAW 
          Case #CDDS_ITEMPREPAINT 
            text$=GetGadgetItemText(0, -1, *pnmcd\dwItemSpec)
            If *pnmcd\uItemState & #CDIS_SELECTED
              DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH|#DFCS_PUSHED)
              *pnmcd\rc\left+2 : *pnmcd\rc\top+1
            Else
              DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH)
            EndIf
            *pnmcd\rc\bottom-1 : *pnmcd\rc\right-1
            SetBkMode_(*pnmcd\hdc,#TRANSPARENT) 
            If *pnmcd\dwItemSpec&1
              FillRect_(*pnmcd\hdc, *pnmcd\rc, brush)
              SetTextColor_(*pnmcd\hdc, #Blue) 
            Else
              FillRect_(*pnmcd\hdc, *pnmcd\rc, brush)
              SetTextColor_(*pnmcd\hdc, #Red) 
            EndIf
            If *pnmcd\rc\right>*pnmcd\rc\left
              DrawText_(*pnmcd\hdc, @text$, Len(text$), *pnmcd\rc, #DT_CENTER|#DT_VCENTER|#DT_SINGLELINE|#DT_END_ELLIPSIS)
            EndIf
            result = #CDRF_SKIPDEFAULT
        EndSelect 
      EndIf 
  EndSelect 
  ProcedureReturn result 
EndProcedure 


If OpenWindow(0, 100, 100, 415, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 5, 5, 405, 200, "col 0", 50, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection) 
  hHeader = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0) 
;Subclass ListIcon so we can customdraw the header text 
  oldListIconCallback = SetWindowLong_(GadgetID(0), #GWL_WNDPROC, @SubclassedListIcon()) 

;Add 10 more columns.
  For i = 1 To 10
    AddGadgetColumn(0, i, "col "+Str(i), 50) 
  Next  
;Add some data
  For b=0 To 99; Add 100 rows.
    AddGadgetItem(0,-1,"")
  Next
  For i = 0 To 99
    For j = 0 To 50
      SetGadgetItemText(0,i,Str(i+j),j)
    Next j
  Next i            

  Repeat 
  Until WaitWindowEvent() = #PB_Event_CloseWindow 
  DeleteObject_(brush)
EndIf 

I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Listicongadget column header color

Post by netmaestro »

Beating me now, are you? Is that how it is? I should call for an umpire ruling though, that looks suspiciously like code ripped from ESGrid. My forensic scientists tell me that you wrote ESGrid before #LVM_GETHEADER became a native constant and so your first line gives it away.

Btw, very nice piece of code you wrote there. 8)
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Listicongadget column header color

Post by srod »

Yes some old code I had lying around. Not sure if it came before EsGRID or not? :)
I may look like a mule, but I'm not a complete ass.
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

Re: Listicongadget column header color

Post by karu »

srod wrote:

Code: Select all

#LVM_GETHEADER = #LVM_FIRST + 31 

; Globals 
  Global oldListIconCallback, hHeader, brush
  brush=CreateSolidBrush_(#Yellow)


Procedure SubclassedListIcon(hWnd, uMsg, wParam, lParam) 
  Protected hdi.hd_item
  result = CallWindowProc_(oldListIconCallback, hWnd, uMsg, wParam, lParam) 
  Select uMsg
    Case #WM_NOTIFY 
      *pnmh.NMHDR = lparam 
      ;--> Get handle to ListIcon header control 
        If *pnmh\code = #NM_CUSTOMDRAW
        *pnmcd.NMCUSTOMDRAW = lparam 
        ;--> Determine drawing stage 
        Select *pnmcd\dwDrawStage 
          Case #CDDS_PREPAINT 
            result = #CDRF_NOTIFYITEMDRAW 
          Case #CDDS_ITEMPREPAINT 
            text$=GetGadgetItemText(0, -1, *pnmcd\dwItemSpec)
            If *pnmcd\uItemState & #CDIS_SELECTED
              DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH|#DFCS_PUSHED)
              *pnmcd\rc\left+2 : *pnmcd\rc\top+1
            Else
              DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH)
            EndIf
            *pnmcd\rc\bottom-1 : *pnmcd\rc\right-1
            SetBkMode_(*pnmcd\hdc,#TRANSPARENT) 
            If *pnmcd\dwItemSpec&1
              FillRect_(*pnmcd\hdc, *pnmcd\rc, brush)
              SetTextColor_(*pnmcd\hdc, #Blue) 
            Else
              FillRect_(*pnmcd\hdc, *pnmcd\rc, brush)
              SetTextColor_(*pnmcd\hdc, #Red) 
            EndIf
            If *pnmcd\rc\right>*pnmcd\rc\left
              DrawText_(*pnmcd\hdc, @text$, Len(text$), *pnmcd\rc, #DT_CENTER|#DT_VCENTER|#DT_SINGLELINE|#DT_END_ELLIPSIS)
            EndIf
            result = #CDRF_SKIPDEFAULT
        EndSelect 
      EndIf 
  EndSelect 
  ProcedureReturn result 
EndProcedure 


If OpenWindow(0, 100, 100, 415, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 5, 5, 405, 200, "col 0", 50, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection) 
  hHeader = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0) 
;Subclass ListIcon so we can customdraw the header text 
  oldListIconCallback = SetWindowLong_(GadgetID(0), #GWL_WNDPROC, @SubclassedListIcon()) 

;Add 10 more columns.
  For i = 1 To 3
    AddGadgetColumn(0, i, "col "+Str(i), 50) 
  Next  
;Add some data
  For b=0 To 99; Add 100 rows.
    AddGadgetItem(0,-1,"")
  Next
  For i = 0 To 99
    For j = 0 To 50
      SetGadgetItemText(0,i,Str(i+j),j)
    Next j
  Next i            

  Repeat 
  Until WaitWindowEvent() = #PB_Event_CloseWindow 
  DeleteObject_(brush)
EndIf 

Thanks, but how to color 'undefined' header area, if your example have only 3 columns, then the undefined column area still grey?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Listicongadget column header color

Post by srod »

Have to subclass the header and intercept #WM_PAINT and #WM_ERASEBKGND etc. It is quite fiddly.
I may look like a mule, but I'm not a complete ass.
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

Re: Listicongadget column header color

Post by karu »

srod wrote:Have to subclass the header and intercept #WM_PAINT and #WM_ERASEBKGND etc. It is quite fiddly.
Can you show me example please?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Listicongadget column header color

Post by srod »

Nope. :)

Haven't the time I'm afraid... too tired right now. I did it with EsGRID; it's a case of determining the combined width of all columns and then filling the remaining area up to the right hand edge of the header control.
I may look like a mule, but I'm not a complete ass.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Listicongadget column header color

Post by RASHAD »

Workaround for srod coloring ListIcon Header code

Code: Select all


; Globals
  Global oldListIconCallback, hHeader, brush
  brush=CreateSolidBrush_(#Yellow)


Procedure SubclassedListIcon(hWnd, uMsg, wParam, lParam)
  Protected hdi.hd_item
  result = CallWindowProc_(oldListIconCallback, hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_NOTIFY
      *pnmh.NMHDR = lparam
      ;--> Get handle to ListIcon header control
        If *pnmh\code = #NM_CUSTOMDRAW
        *pnmcd.NMCUSTOMDRAW = lparam
        ;--> Determine drawing stage
        Select *pnmcd\dwDrawStage
          Case #CDDS_PREPAINT
            result = #CDRF_NOTIFYITEMDRAW
          Case #CDDS_ITEMPREPAINT
            text$=GetGadgetItemText(0, -1, *pnmcd\dwItemSpec)
            If *pnmcd\uItemState & #CDIS_SELECTED
              DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH|#DFCS_PUSHED)
              *pnmcd\rc\left+2 : *pnmcd\rc\top+1
            Else
              DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH)
            EndIf
            *pnmcd\rc\bottom-1 : *pnmcd\rc\right-1
            SetBkMode_(*pnmcd\hdc,#TRANSPARENT)
            If *pnmcd\dwItemSpec&1
              FillRect_(*pnmcd\hdc, *pnmcd\rc, brush)
              SetTextColor_(*pnmcd\hdc, #Blue)
            Else
              FillRect_(*pnmcd\hdc, *pnmcd\rc, brush)
              SetTextColor_(*pnmcd\hdc, #Red)
            EndIf
            GetClientRect_(GadgetID(0),r.RECT)
            SendMessage_(GadgetID(0),#LVM_GETSUBITEMRECT,4,rc.RECT)
            MoveWindow_(GadgetID(1),rc\right+6,5, r\right-rc\right+2,26,1)
            ;ResizeGadget(1,rc\right+6,#PB_Ignore, r\right-rc\right+2,#PB_Ignore)
            If *pnmcd\rc\right>*pnmcd\rc\left
              DrawText_(*pnmcd\hdc, @text$, Len(text$), *pnmcd\rc, #DT_CENTER|#DT_VCENTER|#DT_SINGLELINE|#DT_END_ELLIPSIS)
            EndIf
            result = #CDRF_SKIPDEFAULT
        EndSelect
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure


If OpenWindow(0, 100, 100, 415, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 5, 5, 405, 200, "col 0", 50, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#WS_CLIPSIBLINGS)


  hHeader = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
;Subclass ListIcon so we can customdraw the header text
  oldListIconCallback = SetWindowLong_(GadgetID(0), #GWL_WNDPROC, @SubclassedListIcon())

;Add 10 more columns.
  For i = 1 To 4
    AddGadgetColumn(0, i, "col "+Str(i), 50)
  Next 
;Add some data
  For b=0 To 99; Add 100 rows.
    AddGadgetItem(0,-1,"")
  Next
  For i = 0 To 99
    For j = 0 To 50
      SetGadgetItemText(0,i,Str(i+j),j)
    Next j
  Next i 
  
  GetClientRect_(GadgetID(0),r.RECT)
  SendMessage_(GadgetID(0),#LVM_GETSUBITEMRECT,4,rc.RECT)
  TextGadget(1,rc\right+6,5,r\right-rc\right+2,26,"",#WS_BORDER)
  SetGadgetColor(1, #PB_Gadget_BackColor, #Yellow)
  SetWindowPos_(GadgetID(1),#HWND_TOP,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)          

  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
  DeleteObject_(brush)
EndIf 

Egypt my love
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

Re: Listicongadget column header color

Post by karu »

Thank you all
Post Reply