Setting bold font for Listicon column headers

Just starting out? Need help? Post your questions and find answers here.
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Setting bold font for Listicon column headers

Post by Blue »

Does anyone know a way to assign a bold font ONLY to the headers of a Listicon gadget ?
Everything I've tried so far assigns my chosen font to every entry of the gadget.

Here's some code to play with :

Code: Select all

Procedure initListe()
  Protected w = 150
   ClearGadgetItems(0)                    ; supprime toutes les entrées
   RemoveGadgetColumn(0,#PB_All)          ; supprime toutes les colonnes
   AddGadgetColumn(0, 0, "0: Nom", w-25)
   AddGadgetColumn(0, 1, "1: Adresse", w)
   AddGadgetColumn(0, 2, "2: Ville", w)
   AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way"+Chr(10)+"ByTheBay, England")
   AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road"+Chr(10)+"BigTown, Somewhere")
   AddGadgetItem(0, -1, "Guy Lebleu"+Chr(10)+"5431 MacMahon"+Chr(10)+"LaVille, Canada")
   AddGadgetItem(0, -1, "Maxime Monsieur"+Chr(10)+"99, chemin d'en Haut"+Chr(10)+"Ici, PasAilleurs")
   AddGadgetItem(0, -1, "Madame Buttefly"+Chr(10)+"77, chemin d'en Bas"+Chr(10)+"Là-bas, Pays-Bas")
EndProcedure

 #zTXT_infos = 9
Procedure ShowCount(msg.s)
  SetGadgetText(#zTXT_infos,"  " + msg+", we count " + CountGadgetItems(0) +" items in the List.")
EndProcedure


Procedure GetiTems()
  Protected i, n, c, m$
  c = Val(GetGadgetText(4))
  If c > GetGadgetAttribute(0,#PB_ListIcon_ColumnCount)
    m$ = " il n'y pas de colonne " + c
  Else
    n = CountGadgetItems(0)-1
    m$ = " entrées de la colonne "+ c
    c-1
    For i = 0 To n
      m$ + EoL+"  "+ i + ": '" + GetGadgetItemText(0,i,c)+"' "
    Next
  EndIf
  m$ + EoL
  MsgBox (m$)
  Debug m$
  Debugg
EndProcedure

; ---------------------------
OpenWindow(0, 100, 100, 444, 222, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
;:: fenêtre et gadgets
  SetGadgetFont(#PB_Default, LoadFont(0, "Segoe UI", 10))
  
  ListIconGadget(0, 5, 5, WindowWidth(0)-10, 150, "", 0, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
  SetGadgetFont(0, LoadFont(1, "Segoe UI", 9,#PB_Font_Bold))
  initListe()

  Define gi, gX, gY = 160, gW = 84, gH=20
  gi = 1
    gW = 96
    gX = 5
    ButtonGadget(gi,gX,gY,gW,gH,"delete column ")
  gi = 2
    gX + gW + 3 
    gW = 32
    OptionGadget(gi,gX,gY,gW,gH,"all")
  gi = 3
    gX + gW + 3 
    gW = 18
    OptionGadget(gi,gX,gY,gW,gH,"")
    SetGadgetState(gi,1)
  gi = 4
    gX + gW-2 
    gW = 24
    StringGadget(gi,gX,gY,gW,gH,"1", #PB_String_Numeric)

  gi = 5
   gW = 84
   gX = WindowWidth(0)-5 - gW 
   ButtonGadget(gi,gX,gY,gW,gH,"Reset")

  gi = 6
    gX - gW -3
    ButtonGadget(gi,gX,gY,gW,gH,"clear")
 
  gi = 7
    gX - gW -3
    ButtonGadget(gi,gX,gY,gW,gH,"Get")
 
  gi = #zTXT_infos
    TextGadget(gi,10,188,WindowWidth(0)-20,20,"")
    SetGadgetColor(gi, #PB_Gadget_BackColor, #Yellow) 
    ShowCount("Initially")
  ;.
; --- boucle Windows --------------
  Define event  
  Repeat
    event = WaitWindowEvent()
    Select event
    Case #PB_Event_CloseWindow : Break
    Case #PB_Event_Gadget : 
      Select EventGadget()
        Case 1 : Gosub removeColumns
        Case 6 : ClearGadgetItems(0)
                 ShowCount("After clearing it")
        Case 5 : initListe()
                 ShowCount("After initialising it")
        Case 7 : GetiTems() ;: Stop()
      EndSelect
    EndSelect
   ;.
  ForEver 
End
;:: remove colonnes 
removeColumns:
  If GetGadgetState(2) > 0          ; bouton radio actif ?
    RemoveGadgetColumn(0, #PB_All)  ; Remove all columns
    ShowCount("After removing all columns")
    Return
  EndIf

  nColonnes = GetGadgetAttribute(0,#PB_ListIcon_ColumnCount)
  column = Val(GetGadgetText(4))
  If column > 0 
    If column <= nColonnes
      column -1
      RemoveGadgetColumn(0, column)       ; Remove column
      ShowCount("After removing column " + column)
    Else
      SetGadgetText(#zTXT_infos,"  Il n'y a pas de colonne "+column)
    EndIf
  EndIf
;.
Return
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
jacdelad
Addict
Addict
Posts: 2000
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Setting bold font for Listicon column headers

Post by jacdelad »

Code: Select all

SendMessage_(SendMessage_(GadgetID(ListIconID),#LVM_GETHEADER,0,0),#WM_SETFONT,FontID(Font),0)
Only Windows, obviously.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Setting bold font for Listicon column headers

Post by Blue »

Thank you, jacdelad
I'll try that.
If it's not indiscreet, may I ask where you came upon this complicated (and obscure) line of code ? On Planet Riesa ?

-------------------------------------------
Sometime later, on planet Earth...

Works perfectly !!
If now I could only figure out how to manipulate SendMessage() by myself to do what I want...
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
AZJIO
Addict
Addict
Posts: 2154
Joined: Sun May 14, 2017 1:48 am

Re: Setting bold font for Listicon column headers

Post by AZJIO »

Google LVM_GETHEADER and see the list of functions supported by LVM. You can also search for features for any standard Windows gadgets

BS - ButtonGadget, CheckBoxGadget, OptionGadget
CBS, CBES_EX - ComboBox
DTS - DateGadget
ES - EditorGadget, StringGadget
SB, ESB - ScrollBarGadget
IPM - IPAddressGadget
LBS - ListViewGadget
LVS, LVS_EX, HDS - ListIconGadget
MCS - CalendarGadget
PBS - ProgressBarGadget
SS - TextGadget
TBS - TrackBarGadget
TBSTYLE, TBSTYLE_EX - Toolbar
TCS - PanelGadget
TTS - GadgetToolTip
TVM - TreeGadget
UDS - SpinGadget
WS, WS_EX, DS - OpenWindow
SCI - ScintillaGadget
Last edited by AZJIO on Thu Jun 22, 2023 5:19 pm, edited 14 times in total.
User avatar
jacdelad
Addict
Addict
Posts: 2000
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Setting bold font for Listicon column headers

Post by jacdelad »

Simple Windows API. I like Windows ListViews (which are PureBasic ListIcons), so I use a lot of API to enhance them.
Windows APIs are pretty well documented and offer about 40000 functions. Now, SendMessage alone is a plethora of enhancements.

For this specific API call: the ListIcon and the header are basically two gadgets, but act mostly as one. Get the handle of the header of the ListIcon via one SendMessage call and set the font via another one.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Setting bold font for Listicon column headers

Post by Blue »

Thank you AZJIO for your detailed answer (all those time-saving links. Wow !) and well-organized explanations. Much appreciated.

I spent a couple of hours this morning reading the Microsoft pages on Window API functions, trying to understand the code that jacdelad kindly provided to me. Once you break everything down into logical pieces, the whole thing is not that difficult to understand. It's figuring where to start that is the challenge ! Plus, of course, the hurdle of the repetitive code along with the mind-numbing abreviations.

I'm happy that I now fully understand jacdelad 's seemingly magical code. Of course, i'll have forgotten most everything tomorrow morning (that's the curse of aging beyond a reasonable number of years ! )... but i won't forget the logical path leading to the solution. That's the main thing.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Setting bold font for Listicon column headers

Post by Blue »

jacdelad wrote: Thu Jun 22, 2023 3:03 pm Simple Windows API. [...]
:D :lol: :lol:
Simple ? Really ?
I can think of many words to qualify Windows' API, but "Simple" is not one that comes to mind.
Although I did break down what you sent me and now understand how you cobbled it together.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Setting bold font for Listicon column headers

Post by Blue »

Blue wrote: Thu Jun 22, 2023 5:17 pm Thank you AZJIO for your detailed answer (all those time-saving links. Wow !) and well-organized explanations. Much appreciated. (Edited 14 times ? you worked really hard !)

I spent a couple of hours this morning reading the Microsoft pages on Window API functions, trying to understand the code that jacdelad kindly provided to me. Once you break everything down into logical pieces, the whole thing is not that difficult to understand. It's figuring where to start that is the challenge ! Plus, of course, the hurdle of the repetitive code along with the mind-numbing abreviations.

I'm happy that I now fully understand jacdelad 's seemingly magical code. Of course, i'll have forgotten most everything tomorrow morning (that's the curse of aging beyond a reasonable number of years ! )... but i won't forget the logical path leading to the solution. That's the main thing.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
AZJIO
Addict
Addict
Posts: 2154
Joined: Sun May 14, 2017 1:48 am

Re: Setting bold font for Listicon column headers

Post by AZJIO »

1. To make it even easier for you, check out this
2. You can open a section with "Gui" prefix. For example ListView. Next, look for a function with the suffix "_Create". Now you see the constants LVS_... и LVS_EX_... Next in the example, you look for a lot of "Case" and next to that is the event that sends the ListIconGadget to WM_NOTIFY in the callback. There are a lot of them. Now you also know how the ListIconGadget reacts to user actions.
3. Install AutoIt3, open the "AutoIt3\Include\" folder, find the GuiListView.au3 file there, open it and see how the function works. It will be difficult for you because you do not know this programming language, especially the structures are difficult to understand. All structures are prefixed with "$tag", for example $tagLVITEM, now you can understand that you need an LVITEM structure.

4. You can search for constants in the code archive (WinAPI Library, CodeArchiv_v4-Beta, PB-CodeArchiv-Rebirth-master). I use my search program (screenshot).
User avatar
blueb
Addict
Addict
Posts: 1115
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Setting bold font for Listicon column headers

Post by blueb »

AZJIO wrote: Thu Jun 22, 2023 2:49 pm Google LVM_GETHEADER and see the list of functions supported by LVM.
Thanks AZJIO.

I followed the link and it took me to: LVM_GETHEADER message.

I happened to look in the bottom left of the screen and noted a PDF file download link.

Downloaded it and 'Wow' .. a veritable gold mine of information that I can search offline.

Thanks again :D
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Setting bold font for Listicon column headers

Post by Caronte3D »

blueb wrote: Fri Jun 23, 2023 12:56 pm I happened to look in the bottom left of the screen and noted a PDF file download link.

Downloaded it and 'Wow' .. a veritable gold mine of information that I can search offline.
:shock: awesome info!
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Setting bold font for Listicon column headers

Post by Blue »

blueb wrote: Fri Jun 23, 2023 12:56 pm I happened to look in the bottom left of the screen and noted a PDF file download link.
Indeed ! Thanks blueb for paying attention and for taking the time to let us know.

How many times have i been on this page, and similar MS pages, and not seen this...
And now I see that there is a similar PDF on many, if not most, MS Windows API pages.
They are all huge as well.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Post Reply