It is currently Wed Oct 23, 2019 7:00 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: ListIcon Column Header Text Colour
PostPosted: Thu Jul 27, 2017 2:51 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5837
Location: Wales, UK
I have an app with multiple ListIcons. When the app is in help mode, I temporarily change the backcolour and gridlines of the ListIcons, but I would also like to change either the backcolour or the text colour of the Column Headers. There is very simple code to change the Header font height. I have tried to mimic this for text colour, no joy:
Code:
EnableExplicit

Enumeration
#MyWin
#MyList
#Font12
#Font16
EndEnumeration

LoadFont(#Font12, "Arial", 12, #PB_Font_HighQuality)
LoadFont(#Font16, "Arial", 16, #PB_Font_Bold)

Procedure MyWindow()
;#------------------
Protected   iRow.i
Protected iFlags.i = #PB_Window_SystemMenu | #PB_Window_ScreenCentered

              If OpenWindow(#MyWin, 0, 0, 420, 220, "ListIcon Font", iFlags)

                       ListIconGadget(#MyList, 10, 10, 400, 200, "Col 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
                      AddGadgetColumn(#MyList, 1, "Col 1", 100)
                      AddGadgetColumn(#MyList, 2, "Col 2", 100)
                      AddGadgetColumn(#MyList, 3, "Col 3", 100)

                      For iRow = 0 To 10

                              AddGadgetItem(#MyList, iRow, "Col 0" + #LF$ + "Col 1" + #LF$ + "Col 2" + #LF$ + "Col 3")
                      Next

                      SetGadgetItemColor(#MyList, #PB_All, #PB_Gadget_FrontColor, RGB(0,0,255))
                           SetGadgetFont(#MyList, FontID(#Font12))
                            SendMessage_(SendMessage_(GadgetID(#MyList), #LVM_GETHEADER, 0, 0), #WM_SETFONT, FontID(#Font16), 1)
                            SendMessage_(SendMessage_(GadgetID(#MyList), #LVM_GETHEADER, 0, 0), #LVM_SETTEXTCOLOR, RGB(255, 0, 0), 1) ;<-- fail!
              EndIf
EndProcedure

Procedure WaitForUser()
;#---------------------
Protected iExit.i = #False

              Repeat

                    Select WaitWindowEvent(1)

                               Case #PB_Event_CloseWindow: iExit = #True
                    EndSelect

              Until iExit = #True
EndProcedure

   MyWindow()
WaitForUser()
End


sRod posted code years ago that can change header backcolour and font colour, but:
1) Huge amount of code
2) Turns nice Win7 Headers into ugly classic headers
http://www.purebasic.fr/english/viewtopic.php?t=27488

So, has anyone got a magic wand solution for this?

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIcon Column Header Text Colour
PostPosted: Wed Aug 02, 2017 11:00 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1651
Location: Germany
The following code example demonstrates how to change the color of the header text without being forced to use the ugly classic headers (option "Enable modern theme support" may remain enabled, exception: Windows XP SP3).

Image

I tested the example successfully with option "Enable modern theme support" both enabled and disabled on these Windows versions:
- Windows XP SP3 (PB 5.44 x86 in both ASCII and Unicode mode and PB 5.60 x86; works only with option "Enable modern theme support" disabled!)
- Windows 7 x86 SP1 (PB 5.44 x86 in both ASCII and Unicode mode and PB 5.60 x86)
- Windows 7 x64 SP1 (PB 5.44 x86 and x64 in both ASCII and Unicode mode and PB 5.60 x86 and x64)
- Windows 8.1 x64 (PB 5.44 x86 and x64 in both ASCII and Unicode mode and PB 5.60 x86 and x64)

Code:
EnableExplicit

#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

    If *NMHDR\code = #NM_CUSTOMDRAW
      *NMCUSTOMDRAW = LParam
     
      Select *NMCUSTOMDRAW\dwDrawStage
        Case #CDDS_PREPAINT
          Result = #CDRF_NOTIFYITEMDRAW
        Case #CDDS_ITEMPREPAINT
          SetTextColor_(*NMCUSTOMDRAW\hdc, #HeaderTextColor)
      EndSelect
    EndIf
  EndIf

  ProcedureReturn Result
EndProcedure

OpenWindow(0, 200, 100, 400, 100, "ListIconGadget with colored header text")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20,
  "Name", 110, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", GadgetWidth(0) - GetGadgetItemAttribute(0, 0,
  #PB_ListIcon_ColumnWidth) - 4)
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


Last edited by Shardik on Thu Aug 03, 2017 2:31 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: ListIcon Column Header Text Colour
PostPosted: Thu Aug 03, 2017 12:24 am 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5837
Location: Wales, UK
That is brilliant Shardik, small amount of code! Thank you.
I have bodged your code to show it can be applied to more than one ListIcon and the colour can be changed dynamically:
Code:
;PB5.60 Run-time change of ListIcon column header text colour

EnableExplicit

Enumeration
#Win
#List1
#List2
#BtnB
#BtnR
EndEnumeration

#Ig = #PB_Ignore

Global igExit.i = #False
Global igDefListIconCallback.i
Global igHdTxtClr.i = RGB(0,0,0)

Procedure CustomListIconCallback(iWinHandle.i, iMsg.i, wParam.i, lParam.i)
;#------------------------------------------------------------------------
Protected *NMCUSTOMDRAW.NMCUSTOMDRAW
Protected *NMHDR.NMHDR
Protected iResult.i = CallWindowProc_(igDefListIconCallback, iWinHandle, iMsg, wParam, lParam)

          If iMsg = #WM_NOTIFY

                 *NMHDR = lParam

                 If *NMHDR\code = #NM_CUSTOMDRAW

                         *NMCUSTOMDRAW = lParam

                         Select *NMCUSTOMDRAW\dwDrawStage

                                Case #CDDS_PREPAINT
                                     iResult = #CDRF_NOTIFYITEMDRAW

                                Case #CDDS_ITEMPREPAINT
                                     SetTextColor_(*NMCUSTOMDRAW\hdc, igHdTxtClr)
                         EndSelect
                 EndIf
          EndIf

          ProcedureReturn iResult
EndProcedure

OpenWindow(#Win, 200, 100, 400, 400, "ListIcon: change header text colour")

 ListIconGadget(#List1, 10, 10, 380, 150, "Name", 110, #PB_ListIcon_GridLines)
AddGadgetColumn(#List1, 1, "Address", 260)
  AddGadgetItem(#List1, -1, "Harry Rannit"   + #LF$ + "12 Parliament Way, Battle Street, By the Bay")
  AddGadgetItem(#List1, -1, "Ginger Brokeit" + #LF$ + "130 PureBasic Road, BigTown, CodeCity")
  AddGadgetItem(#List1, -1, "Didi Foundit"   + #LF$ + "321 Logo Drive, Mouse House, Downtown")

 ListIconGadget(#List2, 10, 200, 380, 150, "Name", 110, #PB_ListIcon_GridLines)
AddGadgetColumn(#List2,  1, "Address", 260)
  AddGadgetItem(#List2, -1, "Harry Rannit"   + #LF$ + "12 Parliament Way, Battle Street, By the Bay")
  AddGadgetItem(#List2, -1, "Ginger Brokeit" + #LF$ + "130 PureBasic Road, BigTown, CodeCity")
  AddGadgetItem(#List2, -1, "Didi Foundit"   + #LF$ + "321 Logo Drive, Mouse House, Downtown")

   ButtonGadget(#BtnB, 100, 360, 100, 25, "Blue")
   ButtonGadget(#BtnR, 200, 360, 100, 25, "Red")


igDefListIconCallback = SetWindowLongPtr_(GadgetID(#List1), #GWL_WNDPROC, @CustomListIconCallback())
igDefListIconCallback = SetWindowLongPtr_(GadgetID(#List2), #GWL_WNDPROC, @CustomListIconCallback())

Repeat
         Select  WaitWindowEvent(1)

                 Case #PB_Event_CloseWindow: igExit = #True
                 Case #PB_Event_Gadget

                           Select EventGadget()

                                  Case #BtnB
                                              igHdTxtClr = RGB(0,0,200)
                                              ResizeGadget(#List1,#Ig,#Ig,#Ig,#Ig) ;"Refresh"
                                              ResizeGadget(#List2,#Ig,#Ig,#Ig,#Ig)

                                  Case #BtnR
                                              igHdTxtClr = RGB(200,0,0)
                                              ResizeGadget(#List1,#Ig,#Ig,#Ig,#Ig)
                                              ResizeGadget(#List2,#Ig,#Ig,#Ig,#Ig)
                           EndSelect
         EndSelect

Until igExit = #True

End


Edit: One of the reasons why this is a good method, apart from code simplicity, is that it's Tablet friendly. The window or the gadgets can be zoomed and WinOS maintains the quality of the text rendering.

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIcon Column Header Text Colour
PostPosted: Wed Aug 15, 2018 9:28 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Nov 09, 2011 8:58 am
Posts: 484
Is it possible to set the header color only for a specific column ?

_________________
Warning - Proud GOTO lover ahead!


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIcon Column Header Text Colour
PostPosted: Wed Aug 15, 2018 12:04 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1651
Location: Germany
firace wrote:
Is it possible to set the header color only for a specific column ?
Code:
EnableExplicit

#ColoredColumn = 1
#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

    If *NMHDR\code = #NM_CUSTOMDRAW
      *NMCUSTOMDRAW = LParam
      Select *NMCUSTOMDRAW\dwDrawStage
        Case #CDDS_PREPAINT
          Result = #CDRF_NOTIFYITEMDRAW
        Case #CDDS_ITEMPREPAINT
          If *NMCUSTOMDRAW\dwItemSpec = #ColoredColumn
            SetTextColor_(*NMCUSTOMDRAW\hdc, #HeaderTextColor)
          EndIf
      EndSelect
    EndIf
  EndIf

  ProcedureReturn Result
EndProcedure

OpenWindow(0, 200, 100, 400, 100, "ListIconGadget with colored header text")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20,
  "Name", 110, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", GadgetWidth(0) - GetGadgetItemAttribute(0, 0,
  #PB_ListIcon_ColumnWidth) - 4)
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


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIcon Column Header Text Colour
PostPosted: Wed Aug 15, 2018 12:13 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Nov 09, 2011 8:58 am
Posts: 484
Excellent! Thanks Shardik.

_________________
Warning - Proud GOTO lover ahead!


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIcon Column Header Text Colour
PostPosted: Sat Aug 18, 2018 5:31 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4511
Location: Lyon - France
Works very well
Thanks at you two for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIcon Column Header Text Colour
PostPosted: Sun Feb 03, 2019 6:08 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4493
Location: Not Sydney!!! (Bad water, no goats)
Shardik, can you set the header background colour as well or is that more complicated?

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIcon Column Header Text Colour
PostPosted: Fri Feb 22, 2019 11:05 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1651
Location: Germany
Fangbeast wrote:
Shardik, can you set the header background colour as well or is that more complicated?
It's indeed more complicated. To change the header's text color I stripped down a lot of unnessary stuff from old header coloring examples in order to present an easy and short example that works with modern theme support.

Have you alread tried the old header backcolor example you have asked for in this forum in 2006? Sparkie had given you this example.

You may also try out these examples:
- srod
- srod
- srod
- srod
- RASHAD (with gradient)

All examples still work on Windows 10 x64!


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIcon Column Header Text Colour
PostPosted: Sun Jul 28, 2019 7:29 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4493
Location: Not Sydney!!! (Bad water, no goats)
Good heavens, how on earth did I miss your reply????

AAARRRGHGHGHGH. I actually need this as the windows 10 updates constantly kill things.

Even SetGadgetItemColor doesn't work in my full program properly, only the simpler example from the manual.
Have to test if some api in my code that deals with the gadget is trashing it.

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye