Adding a scrollbar to my gui. Can't get Class_ScrollGUI to work. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AshleyM0101
Posts: 14
Joined: 24 Feb 2020, 21:43

Adding a scrollbar to my gui. Can't get Class_ScrollGUI to work.

17 Nov 2020, 21:30

Any ideas how to add a scrollbar to this gui created by AfterLemon? (Source: https://autohotkey.com/board/topic/93997-list-all-ahk-scripts-in-directory-in-gui/)
I'm trying to use Class_Scrollgui to add the scrollbar, it is working great when I tested the example but I'm having no luck trying to add it to the gui I want. Source for Class_ScrollGUI (https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6316)
I'm open to any suggestion anyone might have it doesn't have to be Class_SCrollGUI. Any help would be greatly appreciated.

Here is the modified code of my current gui that I would like to add a scrollbar to:

Code: Select all

#SingleInstance force
#Persistent
SetBatchLines -1
SysGet, Size, MonitorWorkArea
GuiRight := SizeRight - 147
Button_Right := SizeRight - 147
Button_Bottom := SizeBottom - 31
Gui, 1: Color, cFFFFFF
Loop, *
{
   If (A_LoopFileName <> "AfterLemonScriptLauncher.ahk")
   {
      A_IndexCount := A_Index
      If A_IndexCountMinus
         A_IndexCount -= A_IndexCountMinus
      YPos := A_IndexCount * 25 - 20
      StringTrimRight, FileName%A_IndexCount%, A_LoopFileName, 4
      RunPath%A_IndexCount% := A_LoopFileFullPath
      Gui, 1: Add, Button, w110 h20 x5 y%YPos% gRun, % FileName%A_IndexCount%
      Gui, 1: Add, Button, w20 h20 x120 Disabled y%YPos% vFileName2%A_IndexCount%, K
      YPos%A_IndexCount% := YPos . "," . FileName%A_IndexCount%
   }
   else
   {
      A_IndexCountMinus++
      continue
   }
}
YPos += 50
GuiBottom := SizeBottom - YPos - 1
TitlePos := YPos - 21
ButtonPos := YPos - 25
Gui, 1: Font, w700 c000000
Gui, 1: Add, Text, w90 h20 x30 y%TitlePos% Center gDrag, Utilities
Gui, 1: Font, c000000
Gui, 1: Add, Button, w20 h20 x5 y%ButtonPos%, &-
Gui, 1: Add, Button, w20 h20 x120 y%ButtonPos%, &X
Gui, 1: +AlwaysOnTop +E0x08000000 -Caption +ToolWindow +Border
Gui, 1: Show, NoActivate w145 h%YPos% x%GuiRight% y%GuiBottom%, Main Window
return

Drag:
   PostMessage, 0xA1, 2,,, A
return

Run:
   Loop
   {
   If (A_GuiControl = FileName%A_Index%)
   {
      RunPath := RunPath%A_Index%
      Run, "%RunPath%",,, ProgRun%A_Index%
      ProcessRun := A_Index
      break
   }
   }
   GuiControl, Enable, FileName2%ProcessRun%
   Gui, 1: Show, NoActivate w145 h%YPos% x%GuiRight% y%GuiBottom%, Main Window
return

ButtonK:
   StringTrimLeft, RunningName, A_GuiControl,9
   FileNameKill := ProgRun%RunningName%
   Process, Close, % FileNameKill
   GuiControl, Disable, FileName2%RunningName%
return

Button-:
   Gui, 1: Cancel
   Gui, 2: Color, cFFFFFF
   Gui, 2: Font, w700 c000000
   Gui, 2: Add, Text, w90 h20 x30 y9 Center gDrag, Utilities
   Gui, 2: Font, c000000
   Gui, 2: Add, Button, w20 h20 x5 y5, &+
   Gui, 2: Add, Button, w20 h20 x120 y5, &X
   Gui, 2: -Caption +AlwaysOnTop +E0x08000000 +Border
   Gui, 2: Show, NoActivate w145 h30 x%Button_Right% y%Button_Bottom%, Minimized
return

2Button+:
   Gui, 2: Destroy
   Gui, 1: Show, NoActivate w145 h%YPos% x%GuiRight% y%GuiBottom%, Main Window
return

ButtonX:
2ButtonX:
ExitApp
Additional info about the AfterLemon script:
Description from AfterLemon: Place this small script into a directory with other .ahk scripts and it will enumerate a list with links to run, and killswitches.
I love this script because I can drop it in any folder containing ahk's and it automatically collects all ahk's in the folder. Super useful for whenever I create new ahk scripts without having to manually create a button for each one and I don't have to remember a bunch of hotkeys assigned to launch different scripts. I also modified the script to not take focus away from any active window so that each button can be clicked to run a script to act on the active window if desired (NoActivate parameter). I'm not sure if that functionality can remain intact with the scrollbar added.
AfterLemon's script adds more buttons automatically starting from the bottom the more ahk files it finds in a directory. The problem I have is I have created too many ahk scripts to fit nicely within the gui and the buttons overflow over the top of the screen and are inaccessible, see example below.
image.png
image.png (85.48 KiB) Viewed 477 times
This is what I have so far and having no luck:

Code: Select all

#NoEnv
#SingleInstance force
#Persistent
#Include Class_ScrollGUI.ahk
SetBatchLines, -1
; ----------------------------------------------------------------------------------------------------------------------
; ChildGUI 1
Gui, new, +hwndHGUI +Resize
SetBatchLines -1
SysGet, Size, MonitorWorkArea
GuiRight := SizeRight - 147
Button_Right := SizeRight - 147
Button_Bottom := SizeBottom - 31
Gui, 1: Color, cFFFFFF
Loop, *
{
   If (A_LoopFileName <> "AfterLemonScriptLauncher.ahk")
   {
      A_IndexCount := A_Index
      If A_IndexCountMinus
         A_IndexCount -= A_IndexCountMinus
      YPos := A_IndexCount * 25 - 20
      StringTrimRight, FileName%A_IndexCount%, A_LoopFileName, 4
      RunPath%A_IndexCount% := A_LoopFileFullPath
      Gui, 1: Add, Button, w110 h20 x5 y%YPos% gRun, % FileName%A_IndexCount%
      Gui, 1: Add, Button, w20 h20 x120 Disabled y%YPos% vFileName2%A_IndexCount%, K
      YPos%A_IndexCount% := YPos . "," . FileName%A_IndexCount%
   }
   else
   {
      A_IndexCountMinus++
      continue
   }
}
YPos += 50
GuiBottom := SizeBottom - YPos - 1
TitlePos := YPos - 21
ButtonPos := YPos - 25
Gui, 1: Font, w700 c000000
Gui, 1: Add, Text, w90 h20 x30 y%TitlePos% Center gDrag, Utilities
Gui, 1: Font, c000000
Gui, 1: Add, Button, w20 h20 x5 y%ButtonPos%, &-
Gui, 1: Add, Button, w20 h20 x120 y%ButtonPos%, &X
Gui, 1: +AlwaysOnTop +E0x08000000 -Caption +ToolWindow +Border
Gui, 1: Show, NoActivate w145 h%YPos% x%GuiRight% y%GuiBottom%, Main Window
return

Drag:
   PostMessage, 0xA1, 2,,, A
return

Run:
   Loop
   {
   If (A_GuiControl = FileName%A_Index%)
   {
      RunPath := RunPath%A_Index%
      Run, "%RunPath%",,, ProgRun%A_Index%
      ProcessRun := A_Index
      break
   }
   }
   GuiControl, Enable, FileName2%ProcessRun%
   Gui, 1: Show, NoActivate w145 h%YPos% x%GuiRight% y%GuiBottom%, Main Window
return

ButtonK:
   StringTrimLeft, RunningName, A_GuiControl,9
   FileNameKill := ProgRun%RunningName%
   Process, Close, % FileNameKill
   GuiControl, Disable, FileName2%RunningName%
return

Button-:
   Gui, 1: Cancel
   Gui, 2: Color, cFFFFFF
   Gui, 2: Font, w700 c000000
   Gui, 2: Add, Text, w90 h20 x30 y9 Center gDrag, Utilities
   Gui, 2: Font, c000000
   Gui, 2: Add, Button, w20 h20 x5 y5, &+
   Gui, 2: Add, Button, w20 h20 x120 y5, &X
   Gui, 2: -Caption +AlwaysOnTop +E0x08000000 +Border
   Gui, 2: Show, NoActivate w145 h30 x%Button_Right% y%Button_Bottom%, Minimized
return

2Button+:
   Gui, 2: Destroy
   Gui, 1: Show, NoActivate w145 h%YPos% x%GuiRight% y%GuiBottom%, Main Window
return

ButtonX:
2ButtonX:
ExitApp
; Create ScrollGUI1 with both horizontal and vertical scrollbars and scrolling by mouse wheel
Global SG1 := New ScrollGUI(HGUI, 400, 400, "+Resize +LabelGui1", 3, 4)
; Show ScrollGUI1
SG1.Show("ScrollGUI1", "y0 xcenter")
; ----------------------------------------------------------------------------------------------------------------------
; ChildGUI 2
Gui, New, +hwndHGUI2
Gui, Margin, 20, 20
Gui, Font, s32
Gui, Add, Text, xm Border Hidden vTX1, Test
Gui, Add, Text, x+m yp w460 h300 Center 0x200 Border Section, GUI number 2
Gui, Font
Gui, Add, Button, xs wp gShowHide, Show/Hide additional controls.
Gui, Font, s32
Gui, Add, Text, ys wp h300 Center 0x200 Border Hidden vTX2, Hidden Text 1
Gui, Add, Text, xs wp h300 Center 0x200 Border Hidden vTX3, Hidden Text 2
Gui, Add, Text, xs wp h300 Center 0x200 Border Hidden vTX4, Hidden Text 3
; Create ScrollGUI2 with both horizontal and vertical scrollbars
SG2 := New ScrollGUI(HGUI2, 600, 200, "+Resize +LabelGui2")
; Show ScrollGUI2
SG2.Show("ScrollGUI2", "x0 yCenter")
Return
; ----------------------------------------------------------------------------------------------------------------------
ShowHide:
   GuiControlGet, V, %HGUI2%:Visible, TX1
   GuiControl, %HGUI2%:Hide%V%, TX1
   GuiControl, %HGUI2%:Hide%V%, TX2
   GuiControl, %HGUI2%:Hide%V%, TX3
   GuiControl, %HGUI2%:Hide%V%, TX4
   SG2.AdjustToChild()
Return
; ----------------------------------------------------------------------------------------------------------------------
Gui1Close:
Gui1Escape:
ExitApp
; ----------------------------------------------------------------------------------------------------------------------
Gui1Size:
Return
Gui2Size:
Return
; ----------------------------------------------------------------------------------------------------------------------
Gui2Close:
Gui2Escape:
   SG2 := ""
Return
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: Adding a scrollbar to my gui. Can't get Class_ScrollGUI to work.

17 Nov 2020, 21:38

This might not be what you want, but a listview might be well suited for this sort of thing. You can add and remove items easily. You can execute based on clicks or double-clicks. The scrollbar is built in. You can focus or not focus on the items or the GUI. I use a listview like this to manage lots of clips and launcher items. You can have a listview with a single column, or add columns with other kinds of functionality or content.
just me
Posts: 9457
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Adding a scrollbar to my gui. Can't get Class_ScrollGUI to work.  Topic is solved

18 Nov 2020, 04:00

Maybe:

Code: Select all

#SingleInstance force
#Persistent
SetBatchLines -1
SysGet, Size, MonitorWorkArea
GuiRight := SizeRight - 147
Button_Right := SizeRight - 147
Button_Bottom := SizeBottom - 31
Gui, 1: Color, cFFFFFF
Loop, *
{
   If (A_LoopFileName <> "AfterLemonScriptLauncher.ahk")
   {
      A_IndexCount := A_Index
      If A_IndexCountMinus
         A_IndexCount -= A_IndexCountMinus
      YPos := A_IndexCount * 25 - 20
      StringTrimRight, FileName%A_IndexCount%, A_LoopFileName, 4
      RunPath%A_IndexCount% := A_LoopFileFullPath
      Gui, 1: Add, Button, w110 h20 x5 y%YPos% gRun, % FileName%A_IndexCount%
      Gui, 1: Add, Button, w20 h20 x120 Disabled y%YPos% vFileName2%A_IndexCount%, K
      YPos%A_IndexCount% := YPos . "," . FileName%A_IndexCount%
   }
   else
   {
      A_IndexCountMinus++
      continue
   }
}
YPos += 50
GuiBottom := SizeBottom - YPos - 1
TitlePos := YPos - 21
ButtonPos := YPos - 25
Gui, 1: Font, w700 c000000
Gui, 1: Add, Text, w90 h20 x30 y%TitlePos% Center gDrag, Utilities
Gui, 1: Font, c000000
Gui, 1: Add, Button, w20 h20 x5 y%ButtonPos%, &-
Gui, 1: Add, Button, w20 h20 x120 y%ButtonPos%, &X
Gui, 1: +AlwaysOnTop +E0x08000000 -Caption +ToolWindow +Border
; Gui, 1: Show, NoActivate w145 h%YPos% x%GuiRight% y%GuiBottom%, Main Window                ; <<<<<
Gui, 1: +HwndHGUI1                                                                           ; <<<<<
SizeHeight := SizeBottom - SizeTop                                                           ; <<<<<
If (YPos > SizeHeight)                                                                       ; <<<<<
{                                                                                            ; <<<<<
   Y := 0                                                                                    ; <<<<<
   H := SizeHeight                                                                           ; <<<<<
}                                                                                            ; <<<<<
Else                                                                                         ; <<<<<
{                                                                                            ; <<<<<
   Y := SizeBottom - YPos                                                                    ; <<<<<
   H := YPos                                                                                 ; <<<<<
}                                                                                            ; <<<<<
SG1 := New ScrollGui(HGUI1, 0, H, "+AlwaysOnTop +E0x08000000 -Caption +ToolWindow +Border", 2, 2)  ; <<<<<
SG1.Show("Main Window", "x" . GuiRight . " y" . Y . "NoActivate")                            ; <<<<<
return

Drag:
   ; PostMessage, 0xA1, 2,,, A                                                               ; <<<<<
   PostMessage, 0xA1, 2,,, % "ahk_id " . SG1.HWND                                            ; <<<<<
return

Run:
   Loop
   {
   If (A_GuiControl = FileName%A_Index%)
   {
      RunPath := RunPath%A_Index%
      Run, "%RunPath%",,, ProgRun%A_Index%
      ProcessRun := A_Index
      break
   }
   }
   GuiControl, Enable, FileName2%ProcessRun%
   ; Gui, 1: Show, NoActivate w145 h%YPos% x%GuiRight% y%GuiBottom%, Main Window             ; <<<<<
return

ButtonK:
   StringTrimLeft, RunningName, A_GuiControl,9
   FileNameKill := ProgRun%RunningName%
   Process, Close, % FileNameKill
   GuiControl, Disable, FileName2%RunningName%
return

Button-:
   ; Gui, 1: Cancel                                                                          ; <<<<<
   Gui, % SG1.HWND . ": Cancel"                                                              ; <<<<<
   Gui, 2: Color, cFFFFFF
   Gui, 2: Font, w700 c000000
   Gui, 2: Add, Text, w90 h20 x30 y9 Center gDrag, Utilities
   Gui, 2: Font, c000000
   Gui, 2: Add, Button, w20 h20 x5 y5, &+
   Gui, 2: Add, Button, w20 h20 x120 y5, &X
   Gui, 2: -Caption +AlwaysOnTop +E0x08000000 +Border
   Gui, 2: Show, NoActivate w145 h30 x%Button_Right% y%Button_Bottom%, Minimized
return

2Button+:
   Gui, 2: Destroy
   ; Gui, 1: Show, NoActivate w145 h%YPos% x%GuiRight% y%GuiBottom%, Main Window             ; <<<<<
   SG1.Show("", "NoActivate")                                                                ; <<<<<
return

ButtonX:
2ButtonX:
ExitApp

#Include *Class_ScrollGUI.ahk                                                                 ; <<<<<
Changes are marked with ; <<<<<
AshleyM0101
Posts: 14
Joined: 24 Feb 2020, 21:43

Re: Adding a scrollbar to my gui. Can't get Class_ScrollGUI to work.

18 Nov 2020, 12:57

@just me
So cool it works!
The script seems to work well with changing this for the last line:
#Include Class_ScrollGUI.ahk
This is something I've been wanting to integrate for months. First topic I created, so nice to hear from the author himself, thanks so much Just me! I love this community.

@mikeyww
Thanks for pointing me towards listview, it looks like a really powerful tool for this. I will be making a similar listview version of the script too. :D

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jaka1, mikeyww, ReyAHK, Rohwedder and 311 guests