help with get list in checkboxs

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

help with get list in checkboxs

09 May 2018, 07:06

Hye,

in the sample code below i get a list only in one checkbox for all the folders\files found,
i need help to get the list of each folder\file in separately checkbox.

thanks in advance!

Code: Select all

vDir1 := "C:"
vList := ""
CSize := 0

; folders
foldersBlacklist := "Windows,Users,$Recycle.Bin,Program Files,Program Files (x86),ProgramData"
excludedFolders := ""

; files
filesExtBlacklist := "log,sys,cmd,bat,bak,ini,txt,dll,err,db"
filesBlacklist := "bootmgr,kk1.exe,pv.exe,Uninstal.exe"
excludedFiles := ""

Loop, Files, % vDir1 "\*", D ; folders
{
	if A_LoopFileName in %foldersBlacklist%
	{
		excludedFolders .= """" . A_LoopFileFullPath . """ "
		continue
	}
	
	vList .= A_LoopFileFullPath . "|"
}

Loop, Files, % vDir1 "\*", F ; files
{
	if A_LoopFileExt in %filesExtBlacklist%
	{
		excludedFiles .= """" . A_LoopFileFullPath . """ "
		continue
	}
	if A_LoopFileName in %filesBlacklist%
	{
		excludedFiles .= """" . A_LoopFileFullPath . """ "
		continue
	}
	
	vList .= A_LoopFileFullPath . "|"
	CSize += A_LoopFileSize ; count in c:\ root only
}

vList := SubStr(vList, 1, -1)
listC := % StrReplace(vList, "|", "`n")

Loop, Parse, vList, |
	Loop, Files, % A_LoopField "\*", FR
			CSize += A_LoopFileSize ; count in c:\ folders



;~ MsgBox, % StrReplace(vList, "|", "`n") ; show white list
;~ MsgBox, % StrReplace(excludedFolders, (vDir1 . "\"), "") ; show foldersBlacklist
;~ MsgBox, % StrReplace(excludedFiles, (vDir1 . "\"), "") ; show filesExtBlacklist & filesBlacklist



Gui Add, Checkbox, vResotreChoice, % StrReplace(vList, "|", "`n")
Gui Show


User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: help with get list in checkboxs

10 May 2018, 04:54

If you want to use a ComboBox/ListBox, perhaps this:
StrReplace(vList, "|", "`n")
should be this:
StrReplace(vList, "`n", "|")

Or you need to do a loop (Loop Parse) and create a checkbox for each item via Gui Add.

I'm not sure what the best control is for a list where each item has a checkbox. Maybe ComboBox/ListBox/listview.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Re: help with get list in checkboxs

10 May 2018, 05:18

thanks jeeswg,
i considering to use ListBox if its easier method,
my qusetsion is if i can get a variable for each selected item from the outcome ListBox ?
and if its possible to select more then one item from the ListBox (e.x holding ctrl & left click) ?

Thanks

Code: Select all

vDir1 := "C:"
vList := ""
CSize := 0

; folders
foldersBlacklist := "Windows,Users,$Recycle.Bin,Program Files,Program Files (x86),ProgramData"
excludedFolders := ""

; files
filesExtBlacklist := "log,sys,cmd,bat,bak,ini,txt,dll,err,db"
filesBlacklist := "bootmgr,kk1.exe,pv.exe,Uninstal.exe"
excludedFiles := ""

Loop, Files, % vDir1 "\*", D ; folders
{
	if A_LoopFileName in %foldersBlacklist%
	{
		excludedFolders .= """" . A_LoopFileFullPath . """ "
		continue
	}
	
	vList .= A_LoopFileFullPath . "|"
}

Loop, Files, % vDir1 "\*", F ; files
{
	if A_LoopFileExt in %filesExtBlacklist%
	{
		excludedFiles .= """" . A_LoopFileFullPath . """ "
		continue
	}
	if A_LoopFileName in %filesBlacklist%
	{
		excludedFiles .= """" . A_LoopFileFullPath . """ "
		continue
	}
	
	vList .= A_LoopFileFullPath . "|"
	CSize += A_LoopFileSize ; count in c:\ root only
}


Gui Add, ListBox,h500 w500, % StrReplace(vList, "`n", "|")
Gui Show


Last edited by Tomer on 16 May 2018, 10:28, edited 1 time in total.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: help with get list in checkboxs

16 May 2018, 10:54

Try replacing ListBox with ListView, as suggested by jeeswg, like so:

Replace this:

Code: Select all

Gui, Add, ListBox,h500 w500, % StrReplace(vList, "`n", "|")
with this:

Code: Select all

Gui Add, ListView, h500 w500 Checked, Path
For each, file in % StrSplit(vList, "|")
    LV_Add(, file)
I hope that helps.
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Re: help with get list in checkboxs

16 May 2018, 11:06

Thanks Wolf!
Ill try it and update later.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: help with get list in checkboxs

16 May 2018, 11:21

The top row of ListView only contains text, and it's not needed here.
To not display the header row, use this: -Hdr

Code: Select all

Gui Add, ListView, h500 w500 Checked -Hdr, FileFullPath
For each, file in % StrSplit(RTrim(vList, "|"), "|")
    LV_Add(, file)
Gui Show
I also used RTrim() on vList.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: help with get list in checkboxs

16 May 2018, 13:54

Here's an example of a listview control with checkboxes. You can use space to toggle the checked state of an item.

Code: Select all

;listview control with checkboxes

Gui, New, +HwndhGui, MyWinTitle
Gui, Add, ListView, r3 +Checked, LVH 1|LVH 2|LVH 3
Loop, 3
	if (A_Index = 1)
		LV_Add("Select", "LV A" A_Index, "LV B" A_Index, "LV C" A_Index)
	else
		LV_Add("", "LV A" A_Index, "LV B" A_Index, "LV C" A_Index)
Gui, Show, w300 h300
return

;==================================================

q:: ;get checkbox states
ControlGet, hCtl, Hwnd,, SysListView321, % "ahk_id " hGui
SendMessage, 0x1004, 0, 0,, % "ahk_id " hCtl ;LVM_GETITEMCOUNT := 0x1004
vCount := ErrorLevel
vOutput := ""
Loop, % vCount
{
	;LVIS_STATEIMAGEMASK := 0xF000
	SendMessage, 0x102C, % A_Index-1, 0xF000,, % "ahk_id " hCtl ;LVM_GETITEMSTATE := 0x102C
	vIsChecked := (ErrorLevel >> 12) - 1
	vOutput .= (A_Index=1?"":" ") vIsChecked
}
MsgBox, % vOutput
return

;==================================================

GuiClose:
ExitApp
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Re: help with get list in checkboxs

17 May 2018, 03:08

thank you very much wolf and jeeswg!!
works good!!

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, DavidP, haichen, hasantr, holahapi, mikeyww, RubbeH and 44 guests