I was looking for a way to get multiple lines in a ListiconGadget header. I found a code on AutoIt forum and adapted it.
Here is an example :
Code: Select all
Global oldListIconCallback, hHeader
Global g_hHdrFont
Global ColumnHeaderTitle_LeftMargin = 4
Global ColumnHeaderTitle_TopMargin = 2
Global ColumnHeaderTitle_Height_Offset = 14
Global Column_Count = 4
Global Dim array_ColumnHeaderTitle.s(Column_Count - 1)
array_ColumnHeaderTitle(0) = "Title line 1" + Chr(10) + "Title line 2"
array_ColumnHeaderTitle(1) = "Title line 1"
array_ColumnHeaderTitle(2) = "Title line 1" + Chr(10) + "Title line 2" + Chr(10) + "Title line 3"
array_ColumnHeaderTitle(3) = "Title line 1" + Chr(10) + "Title line 2"
Procedure Header_SetItemHeightByFont(hHeader, iHeight, FontName.s = "Arial", bRestoreTheme = #True)
; Remove Header theme
SetWindowTheme_(hHeader, @null.w, @null.w)
Protected hDC = GetDC_(hHeader)
Protected hFont = SendMessage_(hHeader, #WM_GETFONT, 0, 0)
Protected hObject = SelectObject_(hDC, hFont)
Protected lvLogFont.LOGFONT
GetObject_(hFont, SizeOf(lvLogFont), @lvLogFont)
Protected hHdrfont = CreateFontIndirect_(lvLogFont) ; Original Header font
SelectObject_(hDC, hObject)
ReleaseDC_(hHeader, hDC)
; Set height of Header items by applying text font with suitable height
hFont = CreateFont_(iHeight, 0, 0, 0, #FW_NORMAL, #False, #False, #False, #DEFAULT_CHARSET, #OUT_DEFAULT_PRECIS, #CLIP_DEFAULT_PRECIS, #DEFAULT_QUALITY, 0, FontName)
SendMessage_(hHeader, #WM_SETFONT, hFont, #True)
DeleteObject_(hFont)
; Return original Header font
ProcedureReturn hHdrfont
EndProcedure
Procedure SubclassedListIcon(hWnd, uMsg, wParam, lParam)
Protected result = CallWindowProc_(oldListIconCallback, hWnd, uMsg, wParam, lParam)
Protected lines.i, field.s, i
Select uMsg
Case #WM_NOTIFY
Protected *pnmh.NMHDR = lparam
;--> Get handle to ListIcon header control
If *pnmh\hwndFrom = hHeader
If *pnmh\code = #NM_CUSTOMDRAW
Protected *pnmcd.NMCUSTOMDRAW = lparam
;--> Determine drawing stage
Select *pnmcd\dwDrawStage
Case #CDDS_PREPAINT ; Before the paint cycle begins
result = #CDRF_NOTIFYITEMDRAW ; Notify parent window of any item related drawing operations
Case #CDDS_ITEMPREPAINT ; Before an item is drawn: Default painting (frames and background)
result = #CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations
Case #CDDS_ITEMPOSTPAINT ; After an item is drawn: Custom painting (item texts)
Protected iIndex = *pnmcd\dwItemSpec ; Item index
Protected hDC = *pnmcd\hdc ; Device context
SelectObject_(hDC, g_hHdrFont) ; Set text font
SetBkMode_(hDC, #TRANSPARENT) ; Transparent background
*pnmcd\rc\left = *pnmcd\rc\left + ColumnHeaderTitle_LeftMargin ; Left margin
*pnmcd\rc\top = *pnmcd\rc\top + ColumnHeaderTitle_TopMargin ; Top margin
lines = CountString(array_ColumnHeaderTitle(iIndex), Chr(10)) + 1
For i = 1 To lines
field = StringField(array_ColumnHeaderTitle(iIndex), i, Chr(10))
DrawText_(hDC, @field, Len(field), *pnmcd\rc, #DT_WORD_ELLIPSIS)
*pnmcd\rc\top = *pnmcd\rc\top + ColumnHeaderTitle_Height_Offset ; Line top
*pnmcd\rc\bottom = *pnmcd\rc\bottom + ColumnHeaderTitle_Height_Offset ; Line height
Next
ProcedureReturn #CDRF_NEWFONT ; CDRF_NEWFONT must be returned after changing font or colors
EndSelect
EndIf
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 100, 100, 415, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 405, 200, "", 80, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines)
hHeader = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
Define iHeaderHeight = 50 ; Header height 50 pixels
; Set height of Header items by applying a text font with a suitable height
g_hHdrFont = Header_SetItemHeightByFont(hHeader, iHeaderHeight)
; Add columns
For a = 1 To Column_Count - 1
AddGadgetColumn(0, a, "", 80)
Next
; Add some data
For b = 0 To 6 ; Add 7 rows
AddGadgetItem(0, -1, "")
Next
For i = 0 To 6
For j = 0 To Column_Count - 1
SetGadgetItemText(0,i,Str(i+j),j)
Next
Next
; Subclass ListIcon so we can customdraw the header text
oldListIconCallback = SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @SubclassedListIcon())
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf