Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
%IDC_ListView = 500
Global hDlg,hListView As Dword 'main dialog handle
Global CD() As Single, wCol() As Long
Function PBMain() As Long
Local i As Long
Dialog New Pixels, 0, "ListView Test",300,300,300,95,%WS_OverlappedWindow, 0 To hDlg
Control Add ListView, hDlg, %IDC_ListView, "", 10,10,280,75
Control Handle hDlg, %IDC_ListView To hListView
ReDim CD(1 To 3), wCol(1 To 3)
CD(1) = 0.6 : CD(2) = 0.25 : CD(3) = 0.15
For i = 1 To UBound(CD) : ListView Insert Column hDlg, %IDC_ListView, i, "Col"+Str$(i), CD(i)*280, 0 : Next i
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Static wOld As Long
Select Case Cb.Msg
Case %WM_Size
Local i,w,h,wTotal,wNew As Long
Dialog Get Client hDlg To wNew,h
If wNew > wOld Then 'getting bigger
Control Set Size hDlg, %IDC_ListView, wNew-20, h-20
Control Get Client hDlg, %IDC_ListView To w,h 'with no border, same as size
Else 'getting smaller
w = wNew - 20
End If
For i = 1 To UBound(CD) : wCol(i) = CD(i) * (w) : wTotal = wTotal + wCol(i) : Next i 'get total width
If wTotal > w Then wCol(UBound(CD)) = wCol(UBound(CD)) - (wTotal-w) '<-- resize rightmost column width as needed
For i = 1 To UBound(CD)
ListView Set Column hDlg, %IDC_ListView, i, wCol(i)
Next i
If wNew <= wOld Then Control Set Size hDlg, %IDC_ListView, w, h-20
Dialog Get Client hDlg To wOld,h
End Select
End Function
'gbs_00985
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm