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"
#Include "CommCtrl.inc"
%IDC_ListView = 400
Global hDlg, hListView,hListViewH As Dword, OrigLVProc, OrigLVHProc As Long
Global colName, colPath, colDate, colSize As Long 'percentage widths
Function PBMain() As Long
Dialog New Pixels, 0, "Outlook Resizing",300,300,400,150, %WS_OverlappedWindow To hDlg
colName = 15 : colPath = 60 : colDate = 15 : colSize = 10
CreateListViewControl
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
OrigLVProc = SetWindowLong(hListView, %GWL_WndProc, CodePtr(NewLVProc)) 'subclass
Case %WM_User + 500
ResizeColumns(Cb.WParam)
ResizeWindows
Case %WM_User + 501
? "dblclick"
Case %WM_Size
ResizeWindows
Case %WM_Destroy
SetWindowLong hListView, %GWL_WNDPROC, OrigLVProc
End Select
End Function
Sub CreateListViewControl
Control Add ListView, hDlg, %IDC_ListView,"", 10,10,380,200
Control Handle hDlg, %IDC_ListView To hListView
ListView Insert Column hDlg, %IDC_ListView, 1, "Name", 100, 0
ListView Insert Column hDlg, %IDC_ListView, 2, "Path", 100, 0
ListView Insert Column hDlg, %IDC_ListView, 3, "Date", 100, 0
ListView Insert Column hDlg, %IDC_ListView, 4, "Size", 100, 0
ListView Insert Item hDlg, %IDC_ListView, 1,0, "First Row"
ListView Set Text hDlg, %IDC_ListView, 1, 2, "Column two data which can be very long if you let it which we will in this case"
ListView Set Text hDlg, %IDC_ListView, 1, 3, "Column three data which is long but not all that long."
ListView Set Text hDlg, %IDC_ListView, 1, 4, "This is somewhat short"
End Sub
Function NewLVProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Local hdnptr As HD_NOTIFY Ptr, hdiptr As HD_ITEM Ptr, w,iResult As Long
Select Case Msg
Case %WM_Notify
hdnptr = lParam
hdiptr = @hdnptr.pitem
Select Case @hdnptr.hdr.code
' Case %hdn_dividerdblclick
' iResult = @hdnptr.iItem
' Dialog Post hDlg, %WM_User+501, iResult, 0
Case %hdn_EndTrackW
iResult = @hdnptr.iItem
Dialog Post hDlg, %WM_User+500, iResult, 0
End Select
End Select
Function = CallWindowProc(OrigLVProc, hWnd, Msg, wParam, lParam)
End Function
Sub ResizeWindows
Local x,y,w,h As Long
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %IDC_ListView, w-20, h-10
Control Get Client hDlg, %IDC_ListView To w,h
w = w + 20 * IsTrue(GetWindowLong(hListView, %GWL_STYLE) And %WS_VScroll) 'account for scrollbar
ListView Set Column hDlg, %IDC_ListView, 1, colName * w / 100
ListView Set Column hDlg, %IDC_ListView, 2, colPath * w / 100
ListView Set Column hDlg, %IDC_ListView, 3, colDate * w / 100
ListView Set Column hDlg, %IDC_ListView, 4, colSize * w / 100
End Sub
Sub ResizeColumns(iCol As Long)
Local w,h,iResult,wCol,ww As Long
Control Get Client hDlg, %IDC_ListView To w,h
ListView Get Column hDlg, %IDC_Listview, iCol+1 To wCol
Select Case iCol
Case 0 'name
ww = colPath + colDate + colSize
colName = 100 * wCol / w
colPath = colPath / ww * (100-colName)
colDate = colDate / ww * (100-colName)
colSize = colSize / ww * (100-colName)
Case 1 'path
ww = colDate + colSize
colPath = 100 * wCol / w
colDate = colDate / ww * (100-colName-colPath)
colSize = colSize / ww * (100-colName-colPath)
Case 2 'date
ww = colSize
colDate = 100 * wCol / w
colSize = colSize / ww * (100-colName-colPath-colDate)
Case 3 'size
ww = colPath + colName + colDate
colSize = 100 * wCol / w
colName = colName / ww * (100-colSize)
colPath = colPath / ww * (100-colSize)
colDate = colDate / ww * (100-colSize)
Case Else
End Select
End Sub
'gbs_01017
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm