Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode=1
#Include "win32api.inc"
Type IndexType
Index As Long
End Type
%MaxCount = 1000000
%IDC_ListView = 500
Global hDlg, hListView As Dword, SortDirection As Long, T() As IndexType, D() As String 'will put ListView data in D()
Global qFreq, qStart, qStop As Quad
Function PBMain() As Long
Dialog Default Font "Tahoma", 12, 1
Dialog New Pixels, 0, "Virtual ListView", , , 250,300, %WS_SysMenu,, To hDlg
Control Add ListView, hDlg, %IDC_ListView,"", 10,10,220,280, %WS_Child Or %WS_TabStop Or %WS_Visible Or %LVS_ShowSelAlways Or %LVS_Report Or %LVS_OwnerData Or %LVS_SingleSel
Control Handle hDlg, %IDC_ListView To hListView 'handle to ListView
ListView Set StyleXX hDlg, %IDC_ListView, %LVS_Ex_CheckBoxes
ListView Insert Column hDlg, %IDC_Listview, 1, "Data", 200,0 'set headers
ListView_SetItemCountEx(hListView, %MaxCount, %LVSICF_noInvalidateAll) 'max rows
SendMessage (hListView, %WM_NOTIFYFORMAT, hDlg, %NF_REQUERY)
Dialog Show Modal hDlg, Call CBProc
End Function
CallBack Function CBProc
Local iRow As Long, pLVDI As LV_DISPINFOW Ptr, LVData As NM_ListView, temp$$
Select Case Cb.Msg
Case %WM_InitDialog
QueryPerformanceFrequency qFreq
MakeData
Array Sort T(), Call SortDataA()
Case %WM_Help
ListView Sort hDlg, %IDC_ListView, 1, Ascend 'has no effect
Case %WM_Notify
Select Case Cb.NmId
Case %IDC_ListView
Select Case Cb.NmCode
Case %LVN_GetDispInfo 'notification to ask for data
pLVDI = Cb.LParam 'pointer to LVDISPINFO structure for requested subitem
iRow = @pLVDI.item.iItem+1 'row being asked for
temp$$ = D(T(iRow).Index)
@pLVDI.item.pszText = StrPtr(temp$$) 'text sent to ListView
Case %LVN_ColumnClick
SortDirection Xor=1
QueryPerformanceCounter qStart
If 0 Then
If SortDirection=0 Then Array Sort T(), Call SortDataA()
If SortDirection=1 Then Array Sort T(), Call SortDataD()
Else
If SortDirection=0 Then Array Sort D(), Collate UCase, Ascend
If SortDirection=1 Then Array Sort D(), Collate UCase, Descend
End If
Control ReDraw hDlg, %IDC_ListView
QueryPerformanceCounter qStop
Dialog Set Text hDlg, Format$((qStop-qStart)/qFreq,"###.000") & " seconds"
End Select
End Select
End Select
End Function
Sub MakeData 'some random alpha strings
Local i,iRow As Long
ReDim D(1 To %MaxCount), T(1 To %MaxCount)
For iRow = 1 To %MaxCount
T(iRow).Index = iRow
D(iRow) = Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122))
Next i
End Sub
Function SortDataD(A As IndexType, B As IndexType) As Long
Function = IIf(D(A.Index)>D(B.Index),-1,+1)
End Function
Function SortDataA(A As IndexType, B As IndexType) As Long
Function = IIf(D(A.Index)<D(B.Index),-1,+1)
End Function
http://www.garybeene.com/sw/gbsnippets.htm