Page 1 of 1

Re: Listicongadget column header color

Posted: Mon Oct 08, 2012 9:03 pm
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 


Re: Listicongadget column header color

Posted: Mon Oct 08, 2012 9:41 pm
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)

Re: Listicongadget column header color

Posted: Mon Oct 08, 2012 9:48 pm
by srod
Yes some old code I had lying around. Not sure if it came before EsGRID or not? :)

Re: Listicongadget column header color

Posted: Mon Oct 08, 2012 10:07 pm
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?

Re: Listicongadget column header color

Posted: Mon Oct 08, 2012 10:23 pm
by srod
Have to subclass the header and intercept #WM_PAINT and #WM_ERASEBKGND etc. It is quite fiddly.

Re: Listicongadget column header color

Posted: Mon Oct 08, 2012 10:25 pm
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?

Re: Listicongadget column header color

Posted: Mon Oct 08, 2012 10:28 pm
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.

Re: Listicongadget column header color

Posted: Tue Oct 09, 2012 5:00 pm
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 


Re: Listicongadget column header color

Posted: Tue Oct 23, 2012 10:13 pm
by karu
Thank you all