Here are my 3 callbacks. One for each ListIconGadget
Code: Select all
;============================================================================================================================
; Subclass ListIcon so we can customdraw the header text and colour the header area
;============================================================================================================================
Procedure BookListSubclassed(hwnd, msg, wparam, lparam)
Protected hdi.hd_item
result = CallWindowProc_(form\BookCallback, hwnd, msg, wparam, lparam)
Select msg
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 ; Get header text.
text$ = Space(100)
hdi\mask = #HDI_TEXT
hdi\psztext = @text$
hdi\cchtextmax = Len(text$)
SendMessage_(form\hBooklist, #HDM_GETITEM, *pnmcd\dwItemSpec, hdi) ; Check button state.
If *pnmcd\uItemState & #CDIS_SELECTED
DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH | #DFCS_PUSHED) ; Offset text because of the selected button.
InflateRect_(*pnmcd\rc, -1, -1)
Else
DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH)
EndIf ; Draw background. ; Here we alternate red text on blue background.
InflateRect_(*pnmcd\rc, -1, -1)
SetBkMode_(*pnmcd\hdc, #TRANSPARENT)
;If *pnmcd\dwItemSpec & 1
FillRect_(*pnmcd\hdc, *pnmcd\rc, Colour)
SetTextColor_(*pnmcd\hdc, $000000)
;Else
; FillRect_(*pnmcd\hdc, *pnmcd\rc, Colour)
; SetTextColor_(*pnmcd\hdc, $000000)
;EndIf
DrawText_(*pnmcd\hdc, @text$, Len(text$), *pnmcd\rc, #DT_LEFT | #DT_VCENTER | #DT_END_ELLIPSIS)
result = #CDRF_SKIPDEFAULT
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
;============================================================================================================================
; Subclass ListIcon so we can customdraw the header text and colour the header area
;============================================================================================================================
Procedure BorrowListSubclassed(hwnd, msg, wparam, lparam)
Protected hdi.hd_item
result = CallWindowProc_(form\BorrowCallback, hwnd, msg, wparam, lparam)
Select msg
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 ; Get header text.
text$ = Space(100)
hdi\mask = #HDI_TEXT
hdi\psztext = @text$
hdi\cchtextmax = Len(text$)
SendMessage_(form\hBorrowlist, #HDM_GETITEM, *pnmcd\dwItemSpec, hdi) ; Check button state.
If *pnmcd\uItemState & #CDIS_SELECTED
DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH | #DFCS_PUSHED) ; Offset text because of the selected button.
InflateRect_(*pnmcd\rc, -1, -1)
Else
DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH)
EndIf ; Draw background. ; Here we alternate red text on blue background.
InflateRect_(*pnmcd\rc, -1, -1)
SetBkMode_(*pnmcd\hdc, #TRANSPARENT)
;If *pnmcd\dwItemSpec & 1
FillRect_(*pnmcd\hdc, *pnmcd\rc, Colour)
SetTextColor_(*pnmcd\hdc, $000000)
;Else
; FillRect_(*pnmcd\hdc, *pnmcd\rc, Colour)
; SetTextColor_(*pnmcd\hdc, $000000)
;EndIf
DrawText_(*pnmcd\hdc, @text$, Len(text$), *pnmcd\rc, #DT_LEFT | #DT_VCENTER | #DT_END_ELLIPSIS)
result = #CDRF_SKIPDEFAULT
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
;============================================================================================================================
; Subclass ListIcon so we can customdraw the header text and colour the header area
;============================================================================================================================
Procedure TitleListSubclassed(hwnd, msg, wparam, lparam)
Protected hdi.hd_item
result = CallWindowProc_(form\TitleCallback, hwnd, msg, wparam, lparam)
Select msg
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 ; Get header text.
text$ = Space(100)
hdi\mask = #HDI_TEXT
hdi\psztext = @text$
hdi\cchtextmax = Len(text$)
SendMessage_(form\hTitlelist, #HDM_GETITEM, *pnmcd\dwItemSpec, hdi) ; Check button state.
If *pnmcd\uItemState & #CDIS_SELECTED
DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH | #DFCS_PUSHED) ; Offset text because of the selected button.
InflateRect_(*pnmcd\rc, -1, -1)
Else
DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH)
EndIf ; Draw background. ; Here we alternate red text on blue background.
InflateRect_(*pnmcd\rc, -1, -1)
SetBkMode_(*pnmcd\hdc, #TRANSPARENT)
;If *pnmcd\dwItemSpec & 1
FillRect_(*pnmcd\hdc, *pnmcd\rc, Colour)
SetTextColor_(*pnmcd\hdc, $000000)
;Else
; FillRect_(*pnmcd\hdc, *pnmcd\rc, Colour)
; SetTextColor_(*pnmcd\hdc, $000000)
;EndIf
DrawText_(*pnmcd\hdc, @text$, Len(text$), *pnmcd\rc, #DT_LEFT | #DT_VCENTER | #DT_END_ELLIPSIS)
result = #CDRF_SKIPDEFAULT
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
When I open the main program window, I colour the two primary gadget headings.
Code: Select all
;------------------------------------------------------------------------------------------------
; Subclass the main form ListIcongadgets to allow the headings to be coloured
;------------------------------------------------------------------------------------------------
form\hBooklist = SendMessage_(GadgetID(#Gadget_booklist_booklist), #LVM_GETHEADER, 0, 0) ; Subclass ListIcon so we can customdraw the header text
form\BookCallback = SetWindowLong_(GadgetID(#Gadget_booklist_booklist), #GWL_WNDPROC, @BookListSubclassed())
form\hBorrowlist = SendMessage_(GadgetID(#Gadget_booklist_borrowlist), #LVM_GETHEADER, 0, 0) ; Subclass ListIcon so we can customdraw the header text
form\BorrowCallback = SetWindowLong_(GadgetID(#Gadget_booklist_borrowlist), #GWL_WNDPROC, @BorrowListSubclassed())
When I open my secondary window to show other titles for the highlighted author, I attempt to colour that third ListIconGadget and get a syntax error. For the life of me, I cannot figure out why.
Code: Select all
;============================================================================================================================
; Get all other titles for a highlighted author in the list
;============================================================================================================================
Procedure ShowOtherTitles()
If form\mutex <> 1 ; Only open if no other window is open
program\curbookline = GetGadgetState(#Gadget_booklist_booklist) ; Get the current line number from highlight
If program\curbookline <> -1 ; If a line is highlighted
If Window_titleform() ; Can the window be opened?
form\hTitlelist = SendMessage_(GadgetID(#Gadget_titleform_titles), #LVM_GETHEADER, 0, 0) ; Subclass ListIcon so we can customdraw the header text
form\TitleCallback = SetWindowLong_(GadgetID(#Gadget_titleform_titles), #GWL_WNDPROC, @TitleListSubclassed())
; Coming up As Syntax Error And I cannot see why yet, looks the same As main form
author.s = GetGadgetItemText(#Gadget_booklist_booklist, program\curbookline, 1) ; Get the author name
form\mutex = 1 ; No other window allowed to be open!
FadeInMyWindow(#Window_titleform) ; Fade in the window gently
AddKeyboardShortcut(#Window_titleform, #PB_Shortcut_Escape, #Shortcut_titleform_escape)
form\lastwindow = "othertitles" ; Set window tracking mode
SetWindowTitle(#Window_titleform, "<°)))o><²³ Other titles by [ " + author.s + " ]") ; Set the window title
SetActiveWindow(#Window_titleform) ; Set this as the active window
If SQL3GetTable("Select title, record FROM library WHERE author Like '%" + author.s + "%'", @myRows, @myCols, program\dbhandle)
If CountList(SqlData.s()) <> 0 ; Check if any data was returned even if query worked
program\titlecounter = 0 ; List display counter is empty
ForEach SqlData.s()
AddGadgetItem(#Gadget_titleform_titles, -1, StringField(SqlData.s(), 1, "|") + Chr(10) + StringField(SqlData.s(), 2, "|"))
program\titlecounter + 1
Next
EndIf
EndIf
FillCombo(#Gadget_titleform_authors, "SELECT DISTINCT author FROM library ORDER BY author")
SetGadgetText(#Gadget_titleform_authors, author.s)
MessageHandler(#StatusBar_booklist_messages, "ShowOtherTitles()", "Found all titles for author matching " + title.s, 1)
Else
MessageHandler(#StatusBar_booklist_messages, "ShowOtherTitles()", "Cannot open the get other titles window, possible memory error Or program.", 2)
EndIf
Else
MessageHandler(#StatusBar_booklist_messages, "ShowOtherTitles()", "Cannot open the other titles window, no record selected.", 1)
EndIf
Else
MessageHandler(#StatusBar_booklist_messages, "ShowOtherTitles()", form\lastwindow + " is still open, close it before trying this operation again", 1)
EndIf
EndProcedure