Listicongadget header color and resizing columns (Windows)

Just starting out? Need help? Post your questions and find answers here.
firace
Addict
Addict
Posts: 947
Joined: Wed Nov 09, 2011 8:58 am

Listicongadget header color and resizing columns (Windows)

Post by firace »

(For Windows API and subclassing wizards)

I'm trying to improve the looks of this dark listicongadget. How to fix the white patch? I'd like to make it black too.

Image

Code: Select all

Prototype.i DwmSetWindowAttribute(hWnd.i, dwAttribute.i, pvAttribute.i, cbAttribute.i)



#HeaderTextColor = $989898
#LVM_GETHEADER = #LVM_FIRST + 31

Define DefaultListIconCallback.I

Global bluebrush=CreateSolidBrush_($141414)

Procedure CustomListIconCallback(WindowHandle.I, Msg.I, WParam.I, LParam.I)
  Shared hHeader, 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
    
    If *NMHDR\code = #NM_CUSTOMDRAW
      *NMCUSTOMDRAW = LParam
      
      Select *NMCUSTOMDRAW\dwDrawStage
        Case #CDDS_PREPAINT
          
          Result = #CDRF_NOTIFYITEMDRAW
        Case #CDDS_ITEMPREPAINT
          
          hdi.hd_item
          text$=Space(100)
          hdi\mask = #HDI_TEXT
          hdi\psztext = @text$
          hdi\cchtextmax = Len(text$)
          SendMessage_(hHeader, #HDM_GETITEM,*NMCUSTOMDRAW\dwItemSpec,hdi)
          
          InflateRect_(*NMCUSTOMDRAW\rc,-1,-1)
          SetBkMode_(*NMCUSTOMDRAW\hdc,#TRANSPARENT) 
          
          FillRect_(*NMCUSTOMDRAW\hdc, *NMCUSTOMDRAW\rc, bluebrush)
          SetTextColor_(*NMCUSTOMDRAW\hdc, #HeaderTextColor)
          DrawText_(*NMCUSTOMDRAW\hdc, @text$, Len(text$), *NMCUSTOMDRAW\rc, #DT_CENTER|#DT_VCENTER|#DT_END_ELLIPSIS)
          
          result = #CDRF_SKIPDEFAULT
      EndSelect
    EndIf
  EndIf
  
  ProcedureReturn Result
EndProcedure

OpenWindow(0, 200, 100, 600, 400, "Demo")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20,              "Name", 110 , #PB_ListIcon_FullRowSelect)

AddGadgetColumn(0, 1, "Address", 240)

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")


SetGadgetColor(0, #PB_Gadget_BackColor, $303030)
SetGadgetColor(0, #PB_Gadget_FrontColor, $909090)

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

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5022
Joined: Sun Apr 12, 2009 6:27 am

Re: Listicongadget header color and resizing columns (Windows)

Post by RASHAD »

Hi

Code: Select all

Prototype.i DwmSetWindowAttribute(hWnd.i, dwAttribute.i, pvAttribute.i, cbAttribute.i)

#HeaderTextColor = $989898
#LVM_GETHEADER = #LVM_FIRST + 31

Define DefaultListIconCallback.I

Global bluebrush=CreateSolidBrush_($141414)

Procedure CustomListIconCallback(WindowHandle.I, Msg.I, WParam.I, LParam.I)
  Shared hHeader, 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
    
    If *NMHDR\code = #NM_CUSTOMDRAW
      *NMCUSTOMDRAW = LParam
      
      Select *NMCUSTOMDRAW\dwDrawStage
        Case #CDDS_PREPAINT
          
          Result = #CDRF_NOTIFYITEMDRAW
        Case #CDDS_ITEMPREPAINT
          
          hdi.hd_item
          text$=Space(100)
          hdi\mask = #HDI_TEXT
          hdi\psztext = @text$
          hdi\cchtextmax = Len(text$)
          SendMessage_(hHeader, #HDM_GETITEM,*NMCUSTOMDRAW\dwItemSpec,hdi)
          
          ;InflateRect_(*NMCUSTOMDRAW\rc,-1,-1)
          SetBkMode_(*NMCUSTOMDRAW\hdc,#TRANSPARENT) 
          FillRect_(*NMCUSTOMDRAW\hdc, *NMCUSTOMDRAW\rc, bluebrush)
          
          SetTextColor_(*NMCUSTOMDRAW\hdc, #HeaderTextColor)
          DrawText_(*NMCUSTOMDRAW\hdc, @text$, Len(text$), *NMCUSTOMDRAW\rc, #DT_CENTER|#DT_VCENTER|#DT_END_ELLIPSIS)
          
          result = #CDRF_SKIPDEFAULT
      EndSelect
    EndIf
  EndIf
  
  ProcedureReturn Result
EndProcedure

OpenWindow(0, 200, 100, 600, 400, "Demo")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20, "Name", 110 , #PB_ListIcon_FullRowSelect| #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", 240)

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")


SetGadgetColor(0, #PB_Gadget_BackColor, $0)
SetGadgetColor(0, #PB_Gadget_FrontColor, $909090)
SetGadgetColor(0, #PB_Gadget_LineColor, $303030)

hHeader = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
SetWindowTheme_(hHeader,"","STARTPANEL") 
DefaultListIconCallback = SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @CustomListIconCallback())

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Egypt my love
firace
Addict
Addict
Posts: 947
Joined: Wed Nov 09, 2011 8:58 am

Re: Listicongadget header color and resizing columns (Windows)

Post by firace »

Hi RASHAD,

Wow, that's a genius trick!! Thank you so much and Happy New Year.
User avatar
ChrisR
Addict
Addict
Posts: 1528
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Listicongadget header color and resizing columns (Windows)

Post by ChrisR »

I missed it and I just saw it, that's great.
Thanks RASHAD for the STARTPANEL Theme for the Listicon header. It seems to work for the ExplorerList header as well.
I added it to my ObjectTheme module.
Post Reply