
Is there a native way or a Windows API to get the size of a ListIcon gadget column, so I can resize it programmatically, like if I were double-clicking on the title bar of the gadget between two columns (when the cursor changes to a bidirectional arrow) ?
Here an example to start with, where I would like to resize automatically the columns:
Code: Select all
; Original Author: Karbon
; Date: 15. December 2003
; OS: Windows
; C++ LVCOLUMN structure (https://msdn.microsoft.com/en-us/library/windows/desktop/bb774743%28v=vs.85%29.aspx)
; typedef struct _LVCOLUMN {
; UINT mask;
; int fmt;
; int cx;
; LPTSTR pszText;
; int cchTextMax;
; int iSubItem;
; #if (_WIN32_IE >= 0x0300)
; int iImage;
; int iOrder;
; #endif
; #if (_WIN32_WINNT >= 0x0600)
; int cxMin;
; int cxDefault;
; int cxIdeal;
; #endif
; } LVCOLUMN, *LPLVCOLUMN;
; ---------------------------------------------------------------------------------------------
; Structure LVCOLUMN
; mask.l
; fmt.l
; cx.l
; pszText.s
; cchTextMax.l
; iSubItem.l
; iImage.l
; iOrder.l
; EndStructure
Procedure SetListIconColumnText(Gadget,ColumnIndex,HeaderText.s)
lvc.LVCOLUMN
lvc\mask = #LVCF_TEXT
lvc\pszText = @HeaderText
SendMessage_(GadgetID(Gadget),#LVM_SETCOLUMN,ColumnIndex,@lvc)
EndProcedure
Procedure.s GetListIconColumnText(Gadget,ColumnIndex)
Protected.s Fill.s=Space(255)
lvc.LVCOLUMN
lvc\mask = #LVCF_TEXT
lvc\pszText = @Fill
lvc\cchTextMax = 255
SendMessage_(GadgetID(Gadget),#LVM_GETCOLUMN,ColumnIndex,@lvc)
ProcedureReturn PeekS(lvc\pszText)
EndProcedure
;-------------------------------------------------------------------------------
Procedure zJustifyColumn(Gadget.i,Column.i,Format.i)
Lvc.LVCOLUMN
Lvc\mask = #LVCF_FMT
Select Format
Case 0
Lvc\fmt = #LVCFMT_LEFT
Case 1
Lvc\fmt = #LVCFMT_CENTER
Case 2
Lvc\fmt = #LVCFMT_RIGHT
EndSelect
SendMessage_(GadgetID(Gadget), #LVM_SETCOLUMN, Column, @Lvc)
EndProcedure
F1=LoadFont(#PB_Any,"Verdana",10,#PB_Font_Bold)
W=800
H=500
Win=OpenWindow(#PB_Any, 100, 100, W, H, "Justify ListIcon Column (Aligment)", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Lgad=ListIconGadget(#PB_Any, 5, 5, W-10, H-10, "Name", 200, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines)
AddGadgetColumn(Lgad, 1, "Address", 400)
AddGadgetColumn(Lgad, 2, "Amount", 170)
AddGadgetItem(Lgad, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay"+Chr(10)+"4,125.00")
AddGadgetItem(Lgad, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity"+Chr(10)+"12.50")
AddGadgetItem(Lgad, -1, "René Gängar"+Chr(10)+"78 Harvett Avenue, Hollywood"+Chr(10)+"1,841,422.71")
SetGadgetFont(Lgad,FontID(F1))
zJustifyColumn(Lgad,1,1)
zJustifyColumn(Lgad,2,2)
For i=0 To 2
Debug "Column="+GetListIconColumnText(Lgad,i) + " Width="+Str(GetGadgetItemAttribute(Lgad,0,#PB_ListIcon_ColumnWidth,i))
Next i
;SetGadgetItemAttribute(Lgad,0,#PB_ListIcon_ColumnWidth,250,1)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
CloseWindow(Win)
