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,Style As Long
Dialog Get Client hDlg To w,h
If w > wOld Then
Dialog Set Text hDlg, "getting bigger"
Control Set Size hDlg, %IDC_ListView, w-20, h-20
Control Get Client hDlg, %IDC_ListView To w,h 'with no border, same as size
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
Else
Dialog Set Text hDlg, "getting smaller"
w = w - 20
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
Control Set Size hDlg, %IDC_ListView, w, h-20
End If
Dialog Get Client hDlg To wOld,h
End Select
End Function
'gbs_00984
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm