GUI that shows multiple columns of multiple clickable items Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jwinfl
Posts: 89
Joined: 16 Aug 2017, 12:37

GUI that shows multiple columns of multiple clickable items

Post by jwinfl » 23 Sep 2022, 10:10

I am looking for GUI example(s) that can do the following...

Show multiple columns with multiple rows, example
image.png
image.png (511.05 KiB) Viewed 1822 times
When any item is clicked I would know which one was clicked.

I would like to load the item labels from a file.

Your help will be much appreciated.

Thank you for viewing my topic.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: GUI that shows multiple columns of multiple clickable items

Post by BoBo » 23 Sep 2022, 11:27

Gui > ListView > A_GuiEvent > …
FileRead/Loop, Read, …/Loop, Parse, …/StrSplit()/ …

You should attach/provide your "item" source file with your initial posting, so your supporters can work with it!

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: GUI that shows multiple columns of multiple clickable items

Post by flyingDman » 23 Sep 2022, 12:40

You could use Menu:

Code: Select all

lst =
(
x1
x2
x3
x4
x5
x6
x7
x8
x9
x10
y1
y2
y3
y4
y5
y6
y7
y8
y9
y10
z1
z2
z3
z4
z5
z6
z7
z8
z9
z10
)
for x,y in strsplit(lst,"`n")
	menu, test, add, %y%, execute, % (mod(x-1,10) = 0 && x>1)? "+barbreak" : ""
menu, test, show
return

execute:
msgbox % A_ThisMenuItem
return
14.3 & 1.3.7

jwinfl
Posts: 89
Joined: 16 Aug 2017, 12:37

Re: GUI that shows multiple columns of multiple clickable items

Post by jwinfl » 24 Sep 2022, 10:29

The code below has multiple columns and it actually works.

I would like to add to it, as follows...

1. When you select a second item from the same column the previously highlighted item is un-highlighted (just what I want), but if you select an item from a different column any highlighted item in any other column stays highlighted, I think every column is actually a separate list box. How do I un-highlight the selected item in MyListBox: (between line 46 & 47)? I assume it is something like; GuiControl , x , y , 0 but I am not sure what the x & y text needs to be.

2. Is there anyway to add the cnt variable (same as a_index) to line 34 so that the count is passed when the selection is clicked and ahk goes to line 45 MyListBox: so I don't have to lookup the the item (getSERVER) in the label array to find out what number in the label array it is?

3. When the script is run there is a blank item after .sunc (last item in column 1), since it is in that same location regardless of how I change the data, I assume it has something to do with the column 1 listbox, but I don't know how to get rid of the blank and have the .tdcc label be the last item in column 1 and not the first item in column 2.

4. Is there anyway to change the line spacing, vertical space between labels, make the space larger or smaller?

Any help will be appreciated.

Thank you

Code: Select all

data := "- VM 922-8777|!  To Do List|!! NOTES 3431 Calera|,  MAP  HOL|,  MAP BPD|, 11 x 17|, 8½ x 11  |..bonus|.53|.bmo|.boa|.cap1|.cha|.chabus|.citi|.hsbc|.hw|.mf call back|.mf|.pig|.pnc|.pp|.reg|.sal.bw|.sal.j&b|.sam|.ssa|.strust|.sunc|.tdcc|.tdck|.wf|_Aldi|_DollarGenMrkt|_Publix|_Save A Lot|_Sprouts|_Walmart|_Walmart_Phone_App|_Winn Dixie|AHK Create SCRIPT|AHK Web Search|AMZ Music|AMZ Prime Video|AutoBackup • Files|AutoBackup • Run|Bill of Sale  form|Bldg Code Res|Calculator|Calendar|Chrome Browser|CL   SEARCH   all|Date Calculator|Directv|Dish|Ebay|Ebay-Bidnapper|Email  Frontier|Email  USAWW|Email CLG|Email WCG|Emails to File DB|Envelope Printer|Excel • exe|File Compare Online|Find Company|Forum • AHK|Forum • Android|Forum • DesignCAD|Forum • MS|Forum • NPP|Forum • OL Slipstick|Frontier|Garmin Express|Gas Buddy $|Gas Buddy Chart|Gas Predictor|Gift Card HD|Gift Card HDvsLW|GMail|Google Block List|Google Express|Google Maps|Google Play|Google|GPS fm Addr|GPS Tracking|Health - Notes|Icon jpg to ico|IExplorer Browser|Job • Diary|Job • Inspections|Job • Permits|Label Keyboard|Labels 8066  File Folder|Labels 8066 1 Line|Labels 8066 2 Lines|Labels 8066 3 Lines|Labels 8066 4 Lines|Labels Folder (Avery)|Letterhead HOL|Library Hillsborough JW|Library NPR BW|Library NPR JW|Library Pasco BW|Library Pasco JW|Library Pinellas BW|Library Pinellas JW|MagicJack  Call Forwarding|MagicJack Call Blocking|MagicJack DL Call Log|MagicJack Login|MagicJack Open Call Log xls|MagicJack View Call Log|Medical • Notes|Movie List|Music_CD to MP3|NextDoor Free|PDF Acrobat|Phone  Contacts Google|Phone  Type LL,Cell|Phone Lookup 411.com|Phone Lookup Whitepages|Phone My List|Photoshop|RealEstate_Realtor.com|RealEstate_Trulia|RealEstate_Zillow|Rebate  Dir|Rebate  GivingAssitant|Rebate  Rakuten (Ebates)|Rebate Comparison 1|Rebate Comparison 2|Rebate Comparison 3|Rebate Comparison 4|Sams Club HOL|Scan Receipts|Scan_Ctrl Center|Scanner Dir|Search SuperPages|Search YellowPages|Search_TaxOff Addr|Search_TaxOff Hernando|Search_TaxOff PASCO|Search_TaxOff PIN|Ship - Pirate Ship|Slick Deals HF|Spectrum.com|Steeplechase Envera|Text Message|Tides NOAA|Tides4Fishing|TracFone|Tractor Supply|UnitedHealthCare|VB Dir|w 1  6 Days Hourly HOL|w 2  Radar |w 2  Radar Future|w 2  Radar Future|w 2  Radar|w 3  14 Days HOL|w 4  Temp Now HOL|W10_Notes|W10_SendTo|Word Online|x_Email|x_Excel exe|x_IExplorer|x_Msgs|x_Notepad|x_PDF|x_WExplorer|x_Word exe"
dFile := strreplace(data,"|","`n")

;; below is the actual code, disregard var... action,task,pass
label := [], action := [], task := [], pass := []
arr1 := strsplit(dFile,"`n")
lines := arr1.maxindex()
loop % lines
{
	txt := arr1[a_index]
	arr2 := strsplit(txt,"|")
	label[a_index] := " " . arr2[1]
	if strlen(label[a_index]) > mlen
		mlen := strlen(label[a_index])
	action[a_index] := arr2[2]
	task[a_index] := arr2[3]
	pass[a_index] := substr(arr2[4],1,-1)
}
columns := 6
maxRows := ceil(lines//columns)
clmWidth := 140
rowHeight := 30
xPos := 0
yPos := 0
wHeight := maxRows * 17 - 8
wWidth := clmWidth * columns + 2
Gui, Add, Text, x1 y1 h1 w1 Section 
GUI, font, s9, arial narrow
Loop % label.MaxIndex()
{   
	cnt++
  If (cnt>maxRows) or (A_index=label.MaxIndex())
	{
     Gui, Add, ListBox, xs+%xPos% ys%yPos% w%clmWidth% h%wHeight% vv_node%A_index% gMyListBox, %oListBOX%      
     xPos += clmWidth
     cnt:=0
     oListBOX:=""	  
  }
  oListBOX .= label[A_index] "|"
}
Gui, Show, xcenter ycenter h%wHeight% w%wWidth%, MY ASSISTANT
Return

MyListBox:           
GuiControlGet, getSERVER ,, % A_GuiControl
MsgBox % getSERVER
return

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: GUI that shows multiple columns of multiple clickable items

Post by flyingDman » 24 Sep 2022, 14:23

If you go that route, I think it would be better to use a ListView rather than a ListBox. It gives you more control. Issue 1 and 3 are fixed with what follows (although a grey highlight remains; you can get rid of that if needed). I did not understand your #2 but I have added in the msgbox the column (which listview) the row in that listview and the overall count of the item selected. re: 4 row height: see here: https://www.autohotkey.com/board/topic/74758-tip-how-to-set-row-height-for-listview/

Code: Select all

data := "- VM 922-8777|!  To Do List|!! NOTES 3431 Calera|,  MAP  HOL|,  MAP BPD|, 11 x 17|, 8½ x 11  |..bonus|.53|.bmo|.boa|.cap1|.cha|.chabus|.citi|.hsbc|.hw|.mf call back|.mf|.pig|.pnc|.pp|.reg|.sal.bw|.sal.j&b|.sam|.ssa|.strust|.sunc|.tdcc|.tdck|.wf|_Aldi|_DollarGenMrkt|_Publix|_Save A Lot|_Sprouts|_Walmart|_Walmart_Phone_App|_Winn Dixie|AHK Create SCRIPT|AHK Web Search|AMZ Music|AMZ Prime Video|AutoBackup • Files|AutoBackup • Run|Bill of Sale  form|Bldg Code Res|Calculator|Calendar|Chrome Browser|CL   SEARCH   all|Date Calculator|Directv|Dish|Ebay|Ebay-Bidnapper|Email  Frontier|Email  USAWW|Email CLG|Email WCG|Emails to File DB|Envelope Printer|Excel • exe|File Compare Online|Find Company|Forum • AHK|Forum • Android|Forum • DesignCAD|Forum • MS|Forum • NPP|Forum • OL Slipstick|Frontier|Garmin Express|Gas Buddy $|Gas Buddy Chart|Gas Predictor|Gift Card HD|Gift Card HDvsLW|GMail|Google Block List|Google Express|Google Maps|Google Play|Google|GPS fm Addr|GPS Tracking|Health - Notes|Icon jpg to ico|IExplorer Browser|Job • Diary|Job • Inspections|Job • Permits|Label Keyboard|Labels 8066  File Folder|Labels 8066 1 Line|Labels 8066 2 Lines|Labels 8066 3 Lines|Labels 8066 4 Lines|Labels Folder (Avery)|Letterhead HOL|Library Hillsborough JW|Library NPR BW|Library NPR JW|Library Pasco BW|Library Pasco JW|Library Pinellas BW|Library Pinellas JW|MagicJack  Call Forwarding|MagicJack Call Blocking|MagicJack DL Call Log|MagicJack Login|MagicJack Open Call Log xls|MagicJack View Call Log|Medical • Notes|Movie List|Music_CD to MP3|NextDoor Free|PDF Acrobat|Phone  Contacts Google|Phone  Type LL,Cell|Phone Lookup 411.com|Phone Lookup Whitepages|Phone My List|Photoshop|RealEstate_Realtor.com|RealEstate_Trulia|RealEstate_Zillow|Rebate  Dir|Rebate  GivingAssitant|Rebate  Rakuten (Ebates)|Rebate Comparison 1|Rebate Comparison 2|Rebate Comparison 3|Rebate Comparison 4|Sams Club HOL|Scan Receipts|Scan_Ctrl Center|Scanner Dir|Search SuperPages|Search YellowPages|Search_TaxOff Addr|Search_TaxOff Hernando|Search_TaxOff PASCO|Search_TaxOff PIN|Ship - Pirate Ship|Slick Deals HF|Spectrum.com|Steeplechase Envera|Text Message|Tides NOAA|Tides4Fishing|TracFone|Tractor Supply|UnitedHealthCare|VB Dir|w 1  6 Days Hourly HOL|w 2  Radar |w 2  Radar Future|w 2  Radar Future|w 2  Radar|w 3  14 Days HOL|w 4  Temp Now HOL|W10_Notes|W10_SendTo|Word Online|x_Email|x_Excel exe|x_IExplorer|x_Msgs|x_Notepad|x_PDF|x_WExplorer|x_Word exe"

mstrarr := [], mxrw := 30, clw := 130
gui, margin, 0, 0
gui, font, s10, arial narrow
for x,y in strsplit(data,"|")
	{
	cnt := (x-1)//mxrw + 1
	if (cnt > prvcnt)
		arr%cnt% := [], mstrarr.push(arr%cnt%), prvcnt := cnt
	arr%cnt%.push(y)
	}
for a,b in mstrarr
	{
	gui, add, listview, x+0 w%clw% r%mxrw% -hdr AltSubmit Backgroundfff8dc -E0x200 vLV%a% gMyLV,item
	for c,d in b
		LV_add("",d)
	}
gui, show
return

MyLV:
If(A_GuiEvent = "Normal")
	{
	GuiControlGet, LV#, focusV
	Gui, ListView, %LV#%
	LV_GetText(text, A_EventInfo)
	msgbox % text "`n" LV# "`n" A_EventInfo "`n" ((substr(LV#,-0) - 1) * mxrw) + A_EventInfo
	}
return
14.3 & 1.3.7

User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: GUI that shows multiple columns of multiple clickable items

Post by Smile_ » 24 Sep 2022, 16:31

Bootstrap buttons example:
2022-09-24_223107.png
2022-09-24_223107.png (163.23 KiB) Viewed 1662 times
Class_ScrollGUI
Class_ImageButton
UseGDIP

Code: Select all

#Include, Class_ScrollGUI.ahk
#Include, Class_ImageButton.ahk
#Include, UseGDIP.ahk

Bootstrap := [  [ [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 1]
              ,   [0, 0x80F0B9B8, , , 0, , 0x80D43F3A, 1]
              ,   [0, 0x80E27C79, , , 0, , 0x80D43F3A, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 1] ]
              , [ [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 1]
              ,   [0, 0x80FCEFDC, , , 0, , 0x80F0AD4E, 1]
              ,   [0, 0x80F6CE95, , , 0, , 0x80F0AD4E, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 1] ]
              , [ [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 1]
              ,   [0, 0x80C6E6C6, , , 0, , 0x805CB85C, 1]
              ,   [0, 0x8091CF91, , , 0, , 0x805CB85C, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 1] ]
              , [ [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 1]
              ,   [0, 0x80C6E9F4, , , 0, , 0x8046B8DA, 1]
              ,   [0, 0x8086D0E7, , , 0, , 0x8046B8DA, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 1] ]
              , [ [0, 0x80F0B9B8, , , 0, , 0x80D43F3A, 1]
              ,   [0, 0x80E27C79, , , 0, , 0x80D43F3A, 1]
              ,   [0, 0x80D43F3A, , , 0, , 0x80D43F3A, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 1] ]
              , [ [0, 0x80FCEFDC, , , 0, , 0x80F0AD4E, 1]
              ,   [0, 0x80F6CE95, , , 0, , 0x80F0AD4E, 1]
              ,   [0, 0x80F0AD4E, , , 0, , 0x80F0AD4E, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 1] ]
              , [ [0, 0x80C6E6C6, , , 0, , 0x805CB85C, 1]
              ,   [0, 0x8091CF91, , , 0, , 0x805CB85C, 1]
              ,   [0, 0x805CB85C, , , 0, , 0x805CB85C, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 1] ]
              , [ [0, 0x80C6E9F4, , , 0, , 0x8046B8DA, 1]
              ,   [0, 0x8086D0E7, , , 0, , 0x8046B8DA, 1]
              ,   [0, 0x8046B8DA, , , 0, , 0x8046B8DA, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 1] ]]

BLen := Bootstrap.MaxIndex()

Gui, New, +HwndMyGUI 
Gui, Font, s12 Bold, Calibri

Data    := "- VM 922-8777|! To Do List|!! NOTES 3431 Calera|, MAP HOL|, MAP BPD|, 11 x 17|, 8½ x 11 |..bonus|.53|.bmo|.boa|.cap1|.cha|.chabus|.citi|.hsbc|.hw|.mf call back|.mf|.pig|.pnc|.pp|.reg|.sal.bw|.sal.j&b|.sam|.ssa|.strust|.sunc|.tdcc|.tdck|.wf|_Aldi|_DollarGenMrkt|_Publix|_Save A Lot|_Sprouts|_Walmart|_Walmart_Phone_App|_Winn Dixie|AHK Create SCRIPT|AHK Web Search|AMZ Music|AMZ Prime Video|AutoBackup • Files|AutoBackup • Run|Bill of Sale form|Bldg Code Res|Calculator|Calendar|Chrome Browser|CL SEARCH all|Date Calculator|Directv|Dish|Ebay|Ebay-Bidnapper|Email Frontier|Email USAWW|Email CLG|Email WCG|Emails to File DB|Envelope Printer|Excel • exe|File Compare Online|Find Company|Forum • AHK|Forum • Android|Forum • DesignCAD|Forum • MS|Forum • NPP|Forum • OL Slipstick|Frontier|Garmin Express|Gas Buddy $|Gas Buddy Chart|Gas Predictor|Gift Card HD|Gift Card HDvsLW|GMail|Google Block List|Google Express|Google Maps|Google Play|Google|GPS fm Addr|GPS Tracking|Health - Notes|Icon jpg to ico|IExplorer Browser|Job • Diary|Job • Inspections|Job • Permits|Label Keyboard|Labels 8066 File Folder|Labels 8066 1 Line|Labels 8066 2 Lines|Labels 8066 3 Lines|Labels 8066 4 Lines|Labels Folder (Avery)|Letterhead HOL|Library Hillsborough JW|Library NPR BW|Library NPR JW|Library Pasco BW|Library Pasco JW|Library Pinellas BW|Library Pinellas JW|MagicJack Call Forwarding|MagicJack Call Blocking|MagicJack DL Call Log|MagicJack Login|MagicJack Open Call Log xls|MagicJack View Call Log|Medical • Notes|Movie List|Music_CD to MP3|NextDoor Free|PDF Acrobat|Phone Contacts Google|Phone Type LL,Cell|Phone Lookup 411.com|Phone Lookup Whitepages|Phone My List|Photoshop|RealEstate_Realtor.com|RealEstate_Trulia|RealEstate_Zillow|Rebate Dir|Rebate GivingAssitant|Rebate Rakuten (Ebates)|Rebate Comparison 1|Rebate Comparison 2|Rebate Comparison 3|Rebate Comparison 4|Sams Club HOL|Scan Receipts|Scan_Ctrl Center|Scanner Dir|Search SuperPages|Search YellowPages|Search_TaxOff Addr|Search_TaxOff Hernando|Search_TaxOff PASCO|Search_TaxOff PIN|Ship - Pirate Ship|Slick Deals HF|Spectrum.com|Steeplechase Envera|Text Message|Tides NOAA|Tides4Fishing|TracFone|Tractor Supply|UnitedHealthCare|VB Dir|w 1 6 Days Hourly HOL|w 2 Radar |w 2 Radar Future|w 2 Radar Future|w 2 Radar|w 3 14 Days HOL|w 4 Temp Now HOL|W10_Notes|W10_SendTo|Word Online|x_Email|x_Excel exe|x_IExplorer|x_Msgs|x_Notepad|x_PDF|x_WExplorer|x_Word exe"
Data    := StrSplit(Data, "|")

Columns := 6
Rows    := Data.MaxIndex() // Columns

Position := "", C := R := 1, A := {}
For Each, Title in Data {
    Gui, Add, Button, % Position " w200 HwndBTN vBTN" Each " gRun", % Title
    Random, Index, 1, BLen
    ImageButton.Create(BTN, Bootstrap[Index]*)
    A["BTN" Each] := [R, C]

    Position := Mod(Each, Rows) = 0 ? ("xp+230 ym", ++C, R -= Rows - 1) : ("xp yp+50", ++R)
}

SG := New ScrollGUI(MyGUI, A_ScreenWidth, A_ScreenHeight, "+Resize")
SG.Show("List View", "Maximize")
Return

GuiClose:
ExitApp

Run:
    Msgbox % A_GuiControl 
           . "`nRow`t`t= " A[A_GuiControl][1]
           . "`nColumn`t`t= " A[A_GuiControl][2]
           . "`nRun AHK File`t= " A_GuiControl ".ahk"
    If FileExist(A_GuiControl ".ahk")
        Run, % A_GuiControl ".ahk"
Return

jwinfl
Posts: 89
Joined: 16 Aug 2017, 12:37

Re: GUI that shows multiple columns of multiple clickable items

Post by jwinfl » 24 Sep 2022, 16:47

@flyingDman,

Thank you for your reply.
It works great, better than the code I was trying to use.
I went to where you suggested...https://www.autohotkey.com/board/topic/74758-tip-how-to-set-row-height-for-listview/

Code: Select all

Gui, Font, S8
Gui, Add, ListView, w325 r20 Grid, File|Size
LV_ModifyCol( 1, "200" ), LV_ModifyCol( 2, "100 Integer" )
LV_SetImageList( DllCall( "ImageList_Create", Int,2, Int,30, Int,0x18, Int,1, Int,1 ), 1 )
Loop %A_WinDir%\*.*
 LV_Add( "", A_LoopFileName, A_LoopFileSize )
Gui, Show,, Row Height for ListView
My understanding of what I read was line 4...LV_SetImageList( DllCall( "ImageList_Create", Int,2, Int,30, Int,0x18, Int,1, Int,1 ), 1 ) changes the row height to 30 in pixels, I tried putting it in different places in your code but unfortunately I still have no idea where it should go or if it has to be modified for your code, etc.

Again your help would be appreciated.

jwinfl
Posts: 89
Joined: 16 Aug 2017, 12:37

Re: GUI that shows multiple columns of multiple clickable items

Post by jwinfl » 24 Sep 2022, 17:05

@Smile_,
Thank you for your reply.
Your code looks interesting but I do not have the following files your code includes, so I can't run it...
Class_ScrollGUI.ahk
Class_ImageButton.ahk
UseGDIP.ahk
When I searched for them I get numerous hits but none I found appear to actually be the full files.
If you could point me in the right direction or include the files in a reply that would be very helpful.
I would like to try your code as it has some interesting items.
Thanks again

User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: GUI that shows multiple columns of multiple clickable items

Post by Smile_ » 24 Sep 2022, 17:11

I shared the classes links just below the picture.

jwinfl
Posts: 89
Joined: 16 Aug 2017, 12:37

Re: GUI that shows multiple columns of multiple clickable items

Post by jwinfl » 24 Sep 2022, 17:15

@Smile_,
Sorry, I completely missed them.
I will try your code tomorrow morning.
Thanks again.

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: GUI that shows multiple columns of multiple clickable items

Post by flyingDman » 24 Sep 2022, 17:21

The code to adjust the row height messes up the height of the listviews. It either leaves a space at the bottom or makes the scroll bars appear. So the code here adds gui, -dpiscale and sets the height of the listviews in pixels rather than in row count. It also adds a height "fudge factor". There might be a formula to get to the exact height (it does not seem to be lvh := mxrw * rwh). Play with it and see if it is usable.

Code: Select all

mstrarr := [], mxrw := 33, clw := 200, rwh := 31, lvh := mxrw * rwh + 50    ;50 is fudge factor
gui, -dpiscale
gui, margin, 0, 0
gui, -caption +border
gui, font, s10, arial narrow
for x,y in strsplit(data,"|")
	{
	cnt := (x-1)//mxrw + 1
	(cnt > pcnt) && (arr%cnt% := [], mstrarr.push(arr%cnt%), pcnt := cnt)
	arr%cnt%.push(y)
	}
for a,b in mstrarr
	{
	gui, add, listview, x+0 w%clw% h%lvh% -hdr AltSubmit Backgroundfff8dc -E0x200 vLV%a% gMyLV,item
	LV_SetImageList( DllCall( "ImageList_Create", Int,2, Int,rwh, Int,0x18, Int,1, Int,1 ), 1 )
	for c,d in b
		LV_add("",d)
	}
gui, show
return

MyLV:
GuiControlGet, LV#, focusV
If(A_GuiEvent = "Normal")
	{
	loop, % mstrarr.maxindex()
		if (a_index != substr(LV#,-0))
			{
			Gui, ListView, % "LV" a_index
			LV_Modify("","-select")
			}
	Gui, ListView, %LV#%
	LV_GetText(text, A_EventInfo)
	msgbox % text "`n" LV# "`n" A_EventInfo "`n" ((substr(LV#,-0) - 1) * mxrw) + A_EventInfo
	}
return

guiescape:
ExitApp
Edit: try lvh := mxrw * (rwh + 1)
The MyLV label now also includes code to remove the grey background in previously pressed items.
14.3 & 1.3.7

jwinfl
Posts: 89
Joined: 16 Aug 2017, 12:37

Re: GUI that shows multiple columns of multiple clickable items

Post by jwinfl » 25 Sep 2022, 06:35

@flyingDman,

Thanks again for your help. I tried your revised code, but I can't get it to do what I am trying to do.
I am trying to either eliminate or make as small as possible the space between the text items vertically.
The rwh variable (line 3) only worked to 25, after that there was no change in the space between items. Based on other gui's I have done before the dpi will probably need to be between 10 and 12 to eliminate the space between items vertically. I changed rwh to 12 and changed the fudge factor to 600 in the code below so you can easily see what I am describing below.
I added some code (lines 24,27-32) so the window can be moved, it moves the window ok but there is an unwanted side effect, when you hold the left mouse btn down and move the window the item's background below the mouse gets changed to gray and it doesn't go away when the left mouse btn is released. I am not sure why or how to fix it so the items background does not change when the window is being moved.

Code: Select all

data := "- VM 922-8777|!  To Do List|!! NOTES 3431 Calera|,  MAP  HOL|,  MAP BPD|, 11 x 17|, 8½ x 11  |..bonus|.53|.bmo|.boa|.cap1|.cha|.chabus|.citi|.hsbc|.hw|.mf call back|.mf|.pig|.pnc|.pp|.reg|.sal.bw|.sal.j&b|.sam|.ssa|.strust|.sunc|.tdcc|.tdck|.wf|_Aldi|_DollarGenMrkt|_Publix|_Save A Lot|_Sprouts|_Walmart|_Walmart_Phone_App|_Winn Dixie|AHK Create SCRIPT|AHK Web Search|AMZ Music|AMZ Prime Video|AutoBackup • Files|AutoBackup • Run|Bill of Sale  form|Bldg Code Res|Calculator|Calendar|Chrome Browser|CL   SEARCH   all|Date Calculator|Directv|Dish|Ebay|Ebay-Bidnapper|Email  Frontier|Email  USAWW|Email CLG|Email WCG|Emails to File DB|Envelope Printer|Excel • exe|File Compare Online|Find Company|Forum • AHK|Forum • Android|Forum • DesignCAD|Forum • MS|Forum • NPP|Forum • OL Slipstick|Frontier|Garmin Express|Gas Buddy $|Gas Buddy Chart|Gas Predictor|Gift Card HD|Gift Card HDvsLW|GMail|Google Block List|Google Express|Google Maps|Google Play|Google|GPS fm Addr|GPS Tracking|Health - Notes|Icon jpg to ico|IExplorer Browser|Job • Diary|Job • Inspections|Job • Permits|Label Keyboard|Labels 8066  File Folder|Labels 8066 1 Line|Labels 8066 2 Lines|Labels 8066 3 Lines|Labels 8066 4 Lines|Labels Folder (Avery)|Letterhead HOL|Library Hillsborough JW|Library NPR BW|Library NPR JW|Library Pasco BW|Library Pasco JW|Library Pinellas BW|Library Pinellas JW|MagicJack  Call Forwarding|MagicJack Call Blocking|MagicJack DL Call Log|MagicJack Login|MagicJack Open Call Log xls|MagicJack View Call Log|Medical • Notes|Movie List|Music_CD to MP3|NextDoor Free|PDF Acrobat|Phone  Contacts Google|Phone  Type LL,Cell|Phone Lookup 411.com|Phone Lookup Whitepages|Phone My List|Photoshop|RealEstate_Realtor.com|RealEstate_Trulia|RealEstate_Zillow|Rebate  Dir|Rebate  GivingAssitant|Rebate  Rakuten (Ebates)|Rebate Comparison 1|Rebate Comparison 2|Rebate Comparison 3|Rebate Comparison 4|Sams Club HOL|Scan Receipts|Scan_Ctrl Center|Scanner Dir|Search SuperPages|Search YellowPages|Search_TaxOff Addr|Search_TaxOff Hernando|Search_TaxOff PASCO|Search_TaxOff PIN|Ship - Pirate Ship|Slick Deals HF|Spectrum.com|Steeplechase Envera|Text Message|Tides NOAA|Tides4Fishing|TracFone|Tractor Supply|UnitedHealthCare|VB Dir|w 1  6 Days Hourly HOL|w 2  Radar |w 2  Radar Future|w 2  Radar Future|w 2  Radar|w 3  14 Days HOL|w 4  Temp Now HOL|W10_Notes|W10_SendTo|Word Online|x_Email|x_Excel exe|x_IExplorer|x_Msgs|x_Notepad|x_PDF|x_WExplorer|x_Word exe"

mstrarr := [], mxrw := 33, clw := 200, rwh := 12, lvh := mxrw * rwh + 600    ;600 so there is space below the row ends for testing

gui, -dpiscale
gui, margin, 0, 0
gui, -caption +border
gui, font, s10, arial narrow
for x,y in strsplit(data,"|")
	{
	cnt := (x-1)//mxrw + 1
	(cnt > pcnt) && (arr%cnt% := [], mstrarr.push(arr%cnt%), pcnt := cnt)
	arr%cnt%.push(y)
	}
for a,b in mstrarr
	{
	gui, add, listview, x+0 w%clw% h%lvh% -hdr AltSubmit Backgroundfff8dc -E0x200 vLV%a% gMyLV,item
	LV_SetImageList( DllCall( "ImageList_Create", Int,2, Int,rwh, Int,0x18, Int,1, Int,1 ), 1 )
	for c,d in b
		LV_add("",d)
	}
gui, show
OnMessage( 0x200, "WM_MOUSEMOVE9" ) ; so gui can be moved by mouse
return

WM_MOUSEMOVE9( wparam, lparam, msg, hwnd )
	{
		if wparam = 1 ; so Left Mouse Buttom can Drag Window
			PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
		return
	}

MyLV:
GuiControlGet, LV#, focusV
If(A_GuiEvent = "Normal")
	{
	loop, % mstrarr.maxindex()
		if (a_index != substr(LV#,-0))
			{
			Gui, ListView, % "LV" a_index
			LV_Modify("","-select")
			}
	Gui, ListView, %LV#%
	LV_GetText(text, A_EventInfo)
	msgbox % text "`n" LV# "`n" A_EventInfo "`n" ((substr(LV#,-0) - 1) * mxrw) + A_EventInfo
	}
return

guiescape:
ExitApp
I also noticed that selecting a blank area of the screen (no item below cursor, below the last item in any column) calls MyLV: which indicates that the last item in the column was selected, which is not the case, the variables, all except the label, are for the last item in the column, the selection's label which is "item" is not. Not a big deal as I can just check if the selection's label is "item" and continue.
Hopefully you will have more success with this than I am.
Thanks again for your help.

jwinfl
Posts: 89
Joined: 16 Aug 2017, 12:37

Re: GUI that shows multiple columns of multiple clickable items

Post by jwinfl » 25 Sep 2022, 08:32

Smile_ wrote:
24 Sep 2022, 17:11
I shared the classes links just below the picture.
@Smile_,
I downloaded the 3 files and ran your code.
I tried to modify it but none of the modifications appear to do anything and no matter what I tried the window's size, item sizes, font, etc. changed nothing in the output window.
It also takes over 6 seconds for the window to appear instead of instantly.
Here is your code with all the changes I tried, none of them made any difference.

Code: Select all


; clms := 4,hkstart := 6,mlen := 5,mtxtlen := 32
#Include, Class_ScrollGUI.ahk
#Include, Class_ImageButton.ahk
#Include, UseGDIP.ahk

Bootstrap := [  [ [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 1]
              ,   [0, 0x80F0B9B8, , , 0, , 0x80D43F3A, 1]
              ,   [0, 0x80E27C79, , , 0, , 0x80D43F3A, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 1] ]
              , [ [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 1]
              ,   [0, 0x80FCEFDC, , , 0, , 0x80F0AD4E, 1]
              ,   [0, 0x80F6CE95, , , 0, , 0x80F0AD4E, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 1] ]
              , [ [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 1]
              ,   [0, 0x80C6E6C6, , , 0, , 0x805CB85C, 1]
              ,   [0, 0x8091CF91, , , 0, , 0x805CB85C, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 1] ]
              , [ [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 1]
              ,   [0, 0x80C6E9F4, , , 0, , 0x8046B8DA, 1]
              ,   [0, 0x8086D0E7, , , 0, , 0x8046B8DA, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 1] ]
              , [ [0, 0x80F0B9B8, , , 0, , 0x80D43F3A, 1]
              ,   [0, 0x80E27C79, , , 0, , 0x80D43F3A, 1]
              ,   [0, 0x80D43F3A, , , 0, , 0x80D43F3A, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 1] ]
              , [ [0, 0x80FCEFDC, , , 0, , 0x80F0AD4E, 1]
              ,   [0, 0x80F6CE95, , , 0, , 0x80F0AD4E, 1]
              ,   [0, 0x80F0AD4E, , , 0, , 0x80F0AD4E, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 1] ]
              , [ [0, 0x80C6E6C6, , , 0, , 0x805CB85C, 1]
              ,   [0, 0x8091CF91, , , 0, , 0x805CB85C, 1]
              ,   [0, 0x805CB85C, , , 0, , 0x805CB85C, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 1] ]
              , [ [0, 0x80C6E9F4, , , 0, , 0x8046B8DA, 1]
              ,   [0, 0x8086D0E7, , , 0, , 0x8046B8DA, 1]
              ,   [0, 0x8046B8DA, , , 0, , 0x8046B8DA, 1]
              ,   [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 1] ]]

BLen := Bootstrap.MaxIndex()

Gui, New, +HwndMyGUI 
; Gui, Font, s12 Bold, Calibri
GUI, font, s9 bold, arial narrow

Data    := "- VM 922-8777|! To Do List|!! NOTES 3431 Calera|, MAP HOL|, MAP BPD|, 11 x 17|, 8½ x 11 |..bonus|.53|.bmo|.boa|.cap1|.cha|.chabus|.citi|.hsbc|.hw|.mf call back|.mf|.pig|.pnc|.pp|.reg|.sal.bw|.sal.j&b|.sam|.ssa|.strust|.sunc|.tdcc|.tdck|.wf|_Aldi|_DollarGenMrkt|_Publix|_Save A Lot|_Sprouts|_Walmart|_Walmart_Phone_App|_Winn Dixie|AHK Create SCRIPT|AHK Web Search|AMZ Music|AMZ Prime Video|AutoBackup • Files|AutoBackup • Run|Bill of Sale form|Bldg Code Res|Calculator|Calendar|Chrome Browser|CL SEARCH all|Date Calculator|Directv|Dish|Ebay|Ebay-Bidnapper|Email Frontier|Email USAWW|Email CLG|Email WCG|Emails to File DB|Envelope Printer|Excel • exe|File Compare Online|Find Company|Forum • AHK|Forum • Android|Forum • DesignCAD|Forum • MS|Forum • NPP|Forum • OL Slipstick|Frontier|Garmin Express|Gas Buddy $|Gas Buddy Chart|Gas Predictor|Gift Card HD|Gift Card HDvsLW|GMail|Google Block List|Google Express|Google Maps|Google Play|Google|GPS fm Addr|GPS Tracking|Health - Notes|Icon jpg to ico|IExplorer Browser|Job • Diary|Job • Inspections|Job • Permits|Label Keyboard|Labels 8066 File Folder|Labels 8066 1 Line|Labels 8066 2 Lines|Labels 8066 3 Lines|Labels 8066 4 Lines|Labels Folder (Avery)|Letterhead HOL|Library Hillsborough JW|Library NPR BW|Library NPR JW|Library Pasco BW|Library Pasco JW|Library Pinellas BW|Library Pinellas JW|MagicJack Call Forwarding|MagicJack Call Blocking|MagicJack DL Call Log|MagicJack Login|MagicJack Open Call Log xls|MagicJack View Call Log|Medical • Notes|Movie List|Music_CD to MP3|NextDoor Free|PDF Acrobat|Phone Contacts Google|Phone Type LL,Cell|Phone Lookup 411.com|Phone Lookup Whitepages|Phone My List|Photoshop|RealEstate_Realtor.com|RealEstate_Trulia|RealEstate_Zillow|Rebate Dir|Rebate GivingAssitant|Rebate Rakuten (Ebates)|Rebate Comparison 1|Rebate Comparison 2|Rebate Comparison 3|Rebate Comparison 4|Sams Club HOL|Scan Receipts|Scan_Ctrl Center|Scanner Dir|Search SuperPages|Search YellowPages|Search_TaxOff Addr|Search_TaxOff Hernando|Search_TaxOff PASCO|Search_TaxOff PIN|Ship - Pirate Ship|Slick Deals HF|Spectrum.com|Steeplechase Envera|Text Message|Tides NOAA|Tides4Fishing|TracFone|Tractor Supply|UnitedHealthCare|VB Dir|w 1 6 Days Hourly HOL|w 2 Radar |w 2 Radar Future|w 2 Radar Future|w 2 Radar|w 3 14 Days HOL|w 4 Temp Now HOL|W10_Notes|W10_SendTo|Word Online|x_Email|x_Excel exe|x_IExplorer|x_Msgs|x_Notepad|x_PDF|x_WExplorer|x_Word exe"
Data    := StrSplit(Data, "|")

Columns := 4
Rows    := Data.MaxIndex() // Columns

Position := "", C := R := 1, A := {}
For Each, Title in Data {
    ; Gui, Add, Button, % Position " w200 HwndBTN vBTN" Each " gRun", % Title
    Gui, Add, Button, % Position " w100 HwndBTN v12" Each " gRun", % Title
    Random, Index, 1, BLen
    ImageButton.Create(BTN, Bootstrap[Index]*)
    A["BTN" Each] := [R, C]

    ; Position := Mod(Each, Rows) = 0 ? ("xp+230 ym", ++C, R -= Rows - 1) : ("xp yp+50", ++R)
    Position := Mod(Each, Rows) = 0 ? ("xp+130 ym", ++C, R -= Rows - 1) : ("xp yp+20", ++R)
}

; SG := New ScrollGUI(MyGUI, A_ScreenWidth, A_ScreenHeight, "+Resize")
SG := New ScrollGUI(MyGUI, 1000, 1000, "+Resize")
; SG.Show("List View", "Maximize")
SG.Show
Return

GuiClose:
ExitApp

Run:
    Msgbox % A_GuiControl 
           . "`nRow`t`t= " A[A_GuiControl][1]
           . "`nColumn`t`t= " A[A_GuiControl][2]
           . "`nRun AHK File`t= " A_GuiControl ".ahk"
    If FileExist(A_GuiControl ".ahk")
        Run, % A_GuiControl ".ahk"
Return

[Codebox=autohotkey file=Untitled.ahk]
[/Codebox]

I'm not sure what the problem is but my guess is the #Include files are not setup to work with large screen sizes, mine is 4096 x 2122 (pixels) not including the task bar and maybe those files are defaulting to the window I am getting? Note, I can move the window and resize it, but when I maximize it, it looks like the following screen shot (same as when I run the code without modification), when maximized, instead of being 4096 pixels wide it is only 2199 and instead of being 2122 high it is 2178 which I believe is my total screen height including the taskbar.
Below is a screen shot of the window on my screen, running your original code, note, running the modified code, it looks exactly the same.
image.png
image.png (773.7 KiB) Viewed 1498 times
Hopefully it is not the #Include files but something I am doing wrong or missing when modifying your code.

The code's item (box) selection seems to work fine.

What I would like to have the code do is show the selection boxes the same height as the text height, the same width as the widest text item, with no space between the boxes, horizontally or vertically and for me to know how to change the spacing between boxes, the font, font size and the box width and height.

Again thank you for your help with this.

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: GUI that shows multiple columns of multiple clickable items

Post by flyingDman » 25 Sep 2022, 09:51

There is indeed a minimum vertical space. That said, I wouldn't personally want that space to be less than that minimum as it otherwise would look cluttered. I fixed the issue with the window move leaving a gray background where the window is "grabbed":

Code: Select all

data := "- VM 922-8777|!  To Do List|!! NOTES 3431 Calera|,  MAP  HOL|,  MAP BPD|, 11 x 17|, 8½ x 11  |..bonus|.53|.bmo|.boa|.cap1|.cha|.chabus|.citi|.hsbc|.hw|.mf call back|.mf|.pig|.pnc|.pp|.reg|.sal.bw|.sal.j&b|.sam|.ssa|.strust|.sunc|.tdcc|.tdck|.wf|_Aldi|_DollarGenMrkt|_Publix|_Save A Lot|_Sprouts|_Walmart|_Walmart_Phone_App|_Winn Dixie|AHK Create SCRIPT|AHK Web Search|AMZ Music|AMZ Prime Video|AutoBackup • Files|AutoBackup • Run|Bill of Sale  form|Bldg Code Res|Calculator|Calendar|Chrome Browser|CL   SEARCH   all|Date Calculator|Directv|Dish|Ebay|Ebay-Bidnapper|Email  Frontier|Email  USAWW|Email CLG|Email WCG|Emails to File DB|Envelope Printer|Excel • exe|File Compare Online|Find Company|Forum • AHK|Forum • Android|Forum • DesignCAD|Forum • MS|Forum • NPP|Forum • OL Slipstick|Frontier|Garmin Express|Gas Buddy $|Gas Buddy Chart|Gas Predictor|Gift Card HD|Gift Card HDvsLW|GMail|Google Block List|Google Express|Google Maps|Google Play|Google|GPS fm Addr|GPS Tracking|Health - Notes|Icon jpg to ico|IExplorer Browser|Job • Diary|Job • Inspections|Job • Permits|Label Keyboard|Labels 8066  File Folder|Labels 8066 1 Line|Labels 8066 2 Lines|Labels 8066 3 Lines|Labels 8066 4 Lines|Labels Folder (Avery)|Letterhead HOL|Library Hillsborough JW|Library NPR BW|Library NPR JW|Library Pasco BW|Library Pasco JW|Library Pinellas BW|Library Pinellas JW|MagicJack  Call Forwarding|MagicJack Call Blocking|MagicJack DL Call Log|MagicJack Login|MagicJack Open Call Log xls|MagicJack View Call Log|Medical • Notes|Movie List|Music_CD to MP3|NextDoor Free|PDF Acrobat|Phone  Contacts Google|Phone  Type LL,Cell|Phone Lookup 411.com|Phone Lookup Whitepages|Phone My List|Photoshop|RealEstate_Realtor.com|RealEstate_Trulia|RealEstate_Zillow|Rebate  Dir|Rebate  GivingAssitant|Rebate  Rakuten (Ebates)|Rebate Comparison 1|Rebate Comparison 2|Rebate Comparison 3|Rebate Comparison 4|Sams Club HOL|Scan Receipts|Scan_Ctrl Center|Scanner Dir|Search SuperPages|Search YellowPages|Search_TaxOff Addr|Search_TaxOff Hernando|Search_TaxOff PASCO|Search_TaxOff PIN|Ship - Pirate Ship|Slick Deals HF|Spectrum.com|Steeplechase Envera|Text Message|Tides NOAA|Tides4Fishing|TracFone|Tractor Supply|UnitedHealthCare|VB Dir|w 1  6 Days Hourly HOL|w 2  Radar |w 2  Radar Future|w 2  Radar Future|w 2  Radar|w 3  14 Days HOL|w 4  Temp Now HOL|W10_Notes|W10_SendTo|Word Online|x_Email|x_Excel exe|x_IExplorer|x_Msgs|x_Notepad|x_PDF|x_WExplorer|x_Word exe"

mstrarr := [], mxrw := 33, clw := 140, rwh := 20, lvh := mxrw * (rwh + 1)

gui, -dpiscale
gui, margin, 0, 0
gui, -caption +border
gui, font, s11, arial narrow
for x,y in strsplit(data,"|")
	{
	cnt := (x-1)//mxrw + 1
	(cnt > pcnt) && (arr%cnt% := [], mstrarr.push(arr%cnt%), pcnt := cnt)
	arr%cnt%.push(y)
	}
for a,b in mstrarr
	{
	gui, add, listview, x+0 w%clw% r%mxrw% -hdr AltSubmit Backgroundfff8dc -E0x200 vLV%a% gMyLV,$item$
	LV_SetImageList( DllCall( "ImageList_Create", Int,2, Int,rwh, Int,0x18, Int,1, Int,1 ), 1 )     ;skan
	for c,d in b
		LV_add("",d)
	}
gui, show
OnMessage( 0x200, "WM_MOUSEMOVE9" ) 															; so gui can be moved by mouse
return

WM_MOUSEMOVE9( wparam, lparam, msg, hwnd )
	{
	if wparam = 1 																				; so Left Mouse Buttom can Drag Window
		PostMessage, 0xA1, 2,,, A 																; WM_NCLBUTTONDOWN
	gosub clean
	}

MyLV:
GuiControlGet, LV#, focusV
If(A_GuiEvent = "Normal")
	{
	;~ msgbox,,,% a_eventinfo,1
	Gui, ListView, %LV#%
	LV_GetText(text, A_EventInfo)
	if (text != "$item$")
		msgbox,,, % text "`n" LV# "`n" A_EventInfo "`n" ((substr(LV#,-0) - 1) * mxrw) + A_EventInfo, 1
	gosub clean
	}
return

clean:
loop, % mstrarr.maxindex()
	{
	Gui, ListView, % "LV" a_index
	LV_Modify("",(a_index != substr(LV#,-0)) ? "-select" : "-focus")
	}
return

guiescape:
ExitApp
20220925_075811.jpg
20220925_075811.jpg (79.13 KiB) Viewed 1487 times
Edit : also revised the "clean" and "MyLV" labels. It is better to call the LV headers something else than item . I changed it to $item$ (row 17 and 40)
14.3 & 1.3.7

jwinfl
Posts: 89
Joined: 16 Aug 2017, 12:37

SOLVED...GUI that shows multiple columns of multiple clickable items  Topic is solved

Post by jwinfl » 29 Sep 2022, 07:58

SOLVED...

Thanks to everyone, unfortunately all of the proposals had limitations, eg., minimum label and or text heights, etc.

I found garry's 2013 post... https://www.autohotkey.com/board/topic/89000-color-the-text-of-a-gui-button-color-the-button/ at the bottom.
His post put me on the right track.

This is what my gui looks like...
image.png
image.png (95.96 KiB) Viewed 1424 times
This is what it looks like on my screen...
image.png
image.png (737.64 KiB) Viewed 1424 times
The gui looks quite small above but on my screen it is easily readable. My screen is 50" diagonal and it's a_screenwidth = 4096 and it's a_screenheight = 2160. I tried to make everything adjustable so it will, with some modifications to the variables, work on any size screen.

Below is my code...

Code: Select all

#NoEnv  ; best ahk compatibility
SendMode Input  ; sendinput
#SingleInstance force  ; only 1 instance of script running

GuiTitle := "MY ASSISTANT'S SELECTIONS" ; gui wTitle
SetTimer, ExitWhenGuiClosed, 1000 ; checks every second if guiTitle closed > exitapp
; revised...220929

; https://www.autohotkey.com/board/topic/89000-color-the-text-of-a-gui-button-color-the-button/

SetTitleMatchMode, 2 ; anywhere

arr1 := []
loop,read,D:\BACKUP\AUTO HOT KEYS\Data Files\MyAssitantData.txt
{
	if (substr(a_loopreadline,1,1) != ";") ; skip commented lines
	{
		cnt++
		arr1[cnt] .= a_loopreadline
	}
}
; add items to end of arr1
arr1[arr1.maxindex() + 1] := "OPEN  My Assistant Script|activate|D:\BACKUP\AUTO HOT KEYS\My Scripts\MY ASSISTANT.ahk"  ; adds edit this script
arr1[arr1.maxindex() + 1] := "EDIT    My Assistant List|activate|D:\BACKUP\AUTO HOT KEYS\Data Files\MyAssitantData.txt"  ; adds edit this list
label := [], action := [], task := [], parm := []
loop % arr1.maxindex()
{
	txt := arr1[a_index]
	arr2 := strsplit(txt,"|")
	label[a_index] := arr2[1]
	if strlen(label[a_index]) > max_chrs
		max_chrs := strlen(label[a_index])
	action[a_index] := arr2[2]
	task[a_index] := arr2[3]
	parm[a_index] := substr(arr2[4],1,-1)
}
clms := 6, rows := ceil(arr1.maxindex()/clms), txt_w := max_chrs*5.37, txt_h := 12, xx := 0, yy := -txt_h
Gui,MA: Color, Yellow ; gui background color
Gui,MA: Font,s8 bold cBlack,Segoe UI
gui,MA:add,text,section x1 y1 w0 h0
loop,% label.maxindex()
{
	if ((a_index-1)/rows = (a_index-1)//rows) and (a_index >1)
	{
		yy := -txt_h
		xx += txt_w
	}
	yy += txt_h
	Gui,MA:Add,Progress,xp x%xx% y%yy% w%txt_w% h%txt_h% Disabled BackgroundYellow
	Gui,MA:Add,Text,xp yp wp hp cBlack BackgroundTrans left 0x200 v%a_index% gStart,% label[a_index]
}
gui_w := clms*txt_w, gui_h := (rows-2)*txt_h+5
Gui,MA: Show, xcenter y600 w%gui_w% h%gui_h%, %GuiTitle%
OnMessage( 0x200, "WM_MOUSEMOVE2" ) ; so gui can be moved by mouse
Gui,MA: -Caption +border ;  +AlwaysOnTop
return

WM_MOUSEMOVE2( wparam, lparam, msg, hwnd ) ; so gui can be moved on screen by mouse
	{
		if wparam = 1 ; so Left Mouse Buttom can Drag Window
			PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
		return
	}

start:
switch action[a_guicontrol]
{
	case "run":
		if instr(fileexist(task[a_guicontrol]),"D") ; directory, may have more than D
			run, % "c:\windows\explorer.exe " task[a_guicontrol]
		else
		{
			file := chr(34) task[a_guicontrol] " " chr(34), parameter := parm[a_guicontrol]
			run %file% %parameter%
		}
		return
	case "activate":activate(task[a_guicontrol])
	case "chrome":
		{
			run chrome.exe
			winwait New Tab - Google Chrome,,5
			sendraw % task[a_guicontrol] "`n"
			return
		}
	case "hk":
	{
		sendlevel 1
		sendinput % task[a_guicontrol]  ; in My Hotkeys
		sendlevel 0
		return
	}
}
return
; Gui,MA: -dpiscale

Activate(FilePath) ;;;; File.  Activates or Opens File, RET wHandle
{
	fileext := substr(filepath,instr(filepath,".",,0))
	switch fileext
	{
		case ".ahk":
			if winexist(substr(filepath,instr(filepath,"\",,0)+1) " - Notepad++ [Administrator]") or winexist("*" substr(filepath,instr(filepath,"\",,0)+1) " - Notepad++ [Administrator]")
				winactivate
			else
			{
				run C:\Program Files\Notepad++\notepad++.exe "%filepath%"
				winwait % substr(filepath,instr(filepath,"\",,0)+1) " - Notepad++ [Administrator]",,5
				Sendinput {F5} ; opens run window
				clipboard := FilePath
				Sendinput ^v{Esc} ; file path to run from CB & close run window
			}
			return
		case ".docx":
			if winexist(substr(filepath,instr(filepath,"\",,0)+1) ".docx - Word")
				winactivate
			else
				run "%filepath%"
			return
		case ".xlsx":
			if winexist(substr(filepath,instr(filepath,"\",,0)+1) " - Excel")
				winactivate
			else
				run "%filepath%"
			return
		case ".txt":
			if winexist(substr(filepath,instr(filepath,"\",,0)+1) " - Notepad++ [Administrator]")
				winactivate
			else
				run C:\Program Files\Notepad++\notepad++.exe "%filepath%"
			return
		default:
			msgbox, 4096,, ERROR...           ActivateOrOpen1    Function`n`nFuntion is NOT setup for this file extension`n`n`t>>> %fileext% <<<`n`nMsgbox will auto close in 5 seconds`n`n,5
			return
	}
	return
}

; exitapp ; comment this if qui needs to stay open, if not gui will close when script does
return
ExitWhenGuiClosed: ; closes script if titled gui is closed
	if !WinExist(guiTitle) and guiTitle != ""
		exitapp
	return
For the code to work a text file is needed; the format required is...Label|Action|Task|Parm`n
Example... Walmart|run|https://www.walmart.com
Example... Chrome open Cookies|chrome|chrome://settings/siteData
Note, lines with ";" (first character only) are ignored (considered a comment), anywhere else ";" are not considered comments.

The text file is plain text, double quote marks " herein are for clarity only. Separators are all "|" and each line ends with `n (return). First 3 items are required, Parm[] is optional.

Label[] is the on screen text label (use && for &). The number of characters of the longest Label[] currently determines the txt_w variable, adjust it as needed to work on your screen.

Action[] texts are presently; run, activate, chrome and hk.
"run" will run or open most Task[]s including directories
"activate" will either activate the Task[]'s window, if present, or run the Task[] for these file extensions (.ahk, .docx, .xlsx and .txt)
"chrome" will open chrome settings, etc., eg., "chrome://settings/siteData" opens Chrome's Cookie Settings
"hk" will activate the hotkey specified, eg., "#F12" , ".Text." etc.

Task[] is the path (script, program, exe, etc.), website address, directory location, etc.

Param[] is optional, it passes the parameter text(s) to the program or script specified in the Task[]

The GUI is moveable but only if you hold down the left mouse btn in a NON text area. If the Labels[] fill the whole GUI the only space that will presently work is at the very bottom of the window which is why the GUI's height is txt_h+5 so there will be a 5 pixel clickable area for moving it. The GUI is presently set to NOT be always on top, note, if any part is visible, you can right click it anywhere to see the whole GUI or left click it in a NON text area as left clicking a text area will execute that label's action[].

You can change the label's and/or window's text, size, color, border, background, etc. I have the background for text and the window the same color; yellow.

Hopefully this will help others.

Post Reply

Return to “Ask for Help (v1)”