Re: How to automatically resize the last column of a ListIco
Posted: Tue Jul 06, 2010 2:35 am
Hi, I explained in 1st post why I didn't want to use this lib.GeBonet wrote:Hi,
I thing you can try the "PureLVSORT_SetLastColumnAutoResize(GadgetNumber.l, TrueOrFalse.l)"
of Gnozal Library... ?
Well, lately I tried a lot of ways, subclasssing listicon gadget or modifying window callback, intercepting listiscon messages or header messages, etc etc.Jihugen wrote:It would be the equivalent of PureLVSORT_SetLastColumnAutoResize() in one of the excellent Gnozal's libs (PureLVSORT).
But I don't want to be dependent of this lib, because I don't need sorting features, and I'm using Set/GetGadgetItemData().
I think the best I have achieved for now is by intercepting CDDS_PREPAINT message of the listicon header:
Code: Select all
Enumeration
#Window
EndEnumeration
Enumeration
#ListIcon
#Button
EndEnumeration
Procedure CallBack_MainWin (iWindowID, iMessage, wParam, lParam)
result = #PB_ProcessPureBasicEvents
Select iMessage
Case #WM_NOTIFY
*pnmh.NMHDR = lParam
If *pnmh\code = #NM_CUSTOMDRAW
*lpNMCustomDraw.NMLVCUSTOMDRAW = lParam
*pnmcd.NMCUSTOMDRAW = *lpNMCustomDraw\nmcd
Select *pnmcd\dwDrawStage
Case #CDDS_PREPAINT
Static a : Debug a : a+1 ; Display counter
SendMessage_(*pnmh\hwndFrom, #LVM_SETCOLUMNWIDTH, 1, #LVSCW_AUTOSIZE_USEHEADER)
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(#Window, 450, 200, 400, 185, "test", #PB_Window_SystemMenu|#PB_Window_TitleBar)
ListIconGadget(#ListIcon, 15, 20, 200, 150, "1", 150, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(#ListIcon, 1, "2", 50)
ButtonGadget(#Button, 240, 20, 140, 30, "Add items", #PB_Button_Toggle)
SetWindowCallback(@CallBack_MainWin())
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #Button
ClearGadgetItems(#ListIcon)
If GetGadgetState(#Button)
For i = 0 To 20
AddGadgetItem(#ListIcon, -1, Str(i))
Next
EndIf
EndSelect
Case #PB_Event_CloseWindow
CloseWindow(#Window)
Break
EndSelect
ForEver
EndIf
I'm getting quite bored not being able to get a better result after all my attempts, and trying to modify some code blindly with hope it will magically works is not very fun...
For now, I think I can't do better, so I'll probably stick with the code above, or just use LVSCW_AUTOSIZE_USEHEADER each time I modify the content of my list, or maybe simply the PB's tip.