
Here's the tuned up code.
#3 is now handled with the subclass procedure, ExListCallback(), in lines 12 - 39. This way we don't have to loop through all items when there is a change.

Code: Select all
; Based on example by freak
#LVM_SETEXTENDEDLISTVIEWSTYLE = #LVM_FIRST + 54
#LVS_EX_CHECKBOXES = 4
#ExpListG = 0
#ButtonG1 = 1
#ButtonG2 = 2
Global oldCallback
Procedure ExListCallback(hwnd, msg, wparam, lparam)
result = CallWindowProc_(oldCallback, hwnd, msg, wparam, lparam)
Select msg
Case #WM_NOTIFY
*pNMHDR.NMHDR = lparam
Select *pNMHDR\code
Case #LVN_ITEMCHANGED
*pNML.NMLISTVIEW = lparam
State = SendMessage_(GadgetID(#ExpListG), #LVM_GETITEMSTATE, *pNML\iItem, #LVIS_STATEIMAGEMASK)
If State = 8192
;--> Checked so select
eItem.LV_ITEM
eItem\mask = #LVIF_STATE
eItem\stateMask = #LVIS_STATEIMAGEMASK | #LVIS_SELECTED
eItem\State = 8194
SendMessage_(GadgetID(#ExpListG), #LVM_SETITEMSTATE, *pNML\iItem, eItem)
ElseIf State = 4096
;--> No check, unselect
eItem.LV_ITEM
eItem\mask = #LVIF_STATE
eItem\stateMask = #LVIS_STATEIMAGEMASK | #LVIS_SELECTED
eItem\State = 4096
SendMessage_(GadgetID(#ExpListG), #LVM_SETITEMSTATE, *pNML\iItem, eItem)
EndIf
EndSelect
EndSelect
ProcedureReturn result
EndProcedure
Procedure RemoveIcons(gad)
;--> To remove the icons, we make a duplicate the current ImageList for the small icons
hIList = SendMessage_(GadgetID(#ExpListG), #LVM_GETIMAGELIST, #LVSIL_SMALL, 0)
hImageList = ImageList_Duplicate_(hIList)
;--> When we resize the icons, they all are removed
;--> I will resize the ImageList icons to a width of 1 and height of 16
ImageList_SetIconSize_(hImageList, 1, 16)
;--> Send the new ImageList to the ExplorerListGadget
SendMessage_(GadgetID(#ExpListG), #LVM_SETIMAGELIST, #LVSIL_SMALL, hImageList)
ProcedureReturn hImageList
EndProcedure
Procedure RemoveExt(gad)
;--> Remove file extension
For i = 0 To CountGadgetItems(gad) - 1
t$ = GetGadgetItemText(gad, i, 0)
dot = FindString(t$, ".", 1) - 1
SetGadgetItemText(gad, i, Left(t$, dot), 0)
Next i
EndProcedure
Procedure CheckAll(gad)
eItem.LV_ITEM
eItem\mask = #LVIF_STATE
eItem\stateMask = #LVIS_STATEIMAGEMASK | #LVIS_SELECTED
eItem\State = 8194 ; 0010 0000 00000010
SendMessage_(GadgetID(gad), #LVM_SETITEMSTATE, -1, eItem)
EndProcedure
Procedure UnCheckAll(gad)
eItem.LV_ITEM
eItem\mask = #LVIF_STATE
eItem\stateMask = #LVIS_STATEIMAGEMASK | #LVIS_SELECTED
eItem\State = 4096 ; 0001 0000 00000000
SendMessage_(GadgetID(gad), #LVM_SETITEMSTATE, -1, eItem)
EndProcedure
If OpenWindow(0,0,0,400,300,#PB_Window_SystemMenu | #PB_Window_ScreenCentered, "File Selection") And CreateGadgetList(WindowID(0))
ButtonGadget(#ButtonG2, 10, 220, 100, 20, "Check All")
ButtonGadget(#ButtonG1, 180, 220, 80, 20, "Process")
; Set flags for the Explorer List
Flag = #PB_Explorer_AlwaysShowSelection | #PB_Explorer_MultiSelect | #PB_Explorer_NoParentFolder | #PB_Explorer_AutoSort | #PB_Explorer_NoFolders
ExplorerListGadget(#ExpListG, 10, 10, 380, 180, "\purebasic\examples\sources\*.PB", Flag)
; Change to List format
ChangeListIconGadgetDisplay(#ExpListG, 2)
; Remove unwanted columns
RemoveGadgetColumn(#ExpListG, 3)
RemoveGadgetColumn(#ExpListG, 2)
RemoveGadgetColumn(#ExpListG, 1)
; Enable Checkboxes in the ExplorerListGadget
SendMessage_(GadgetID(#ExpListG), #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_CHECKBOXES, #LVS_EX_CHECKBOXES)
;--> Remove Icons
dupImageList = RemoveIcons(#ExpListG)
;--> Remove file extension
RemoveExt(#ExpListG)
hExListParent = GetParent_(GadgetID(#ExpListG))
oldCallback = SetWindowLong_(hExListParent, #GWL_WNDPROC, @ExListCallback())
Repeat
event = WaitWindowEvent()
If event = #PB_EventGadget And EventGadgetID() = #ButtonG2
Select GetGadgetText(2)
Case "Check All"
CheckAll(#ExpListG)
SetGadgetText(2, "Uncheck All")
Case "Uncheck All"
UnCheckAll(#ExpListG)
SetGadgetText(2, "Check All")
EndSelect
EndIf
If event = #PB_EventGadget And EventGadgetID() = #ButtonG1
Count = SendMessage_(GadgetID(#ExpListG), #LVM_GETSELECTEDCOUNT, 0, 0)
; MessageRequester("Debug","The number of file selected: " + Str(count),0)
; Loop through all displayed items
For i = 0 To CountGadgetItems(#ExpListG) - 1
State = SendMessage_(GadgetID(#ExpListG), #LVM_GETITEMSTATE, i, #LVIS_STATEIMAGEMASK)
If State >> 12 > 1
; The checkbox is checked, do processing here
MessageRequester("Debug","Process this file: " + GetGadgetItemText(#ExpListG, i, 0),0)
; Uncheck the box
eItem.LV_ITEM
eItem\mask = #LVIF_STATE
eItem\stateMask = #LVIS_STATEIMAGEMASK | #LVIS_SELECTED
eItem\State = 4096 ; 0001 0000 00000000
State = SendMessage_(GadgetID(#ExpListG), #LVM_SETITEMSTATE, i, eItem)
EndIf
Next i
EndIf
Until event = #PB_Event_CloseWindow
;--> Clean up
ImageList_Destroy_(dupImageList)
EndIf