Jump to content

Scrolling in GUI


danielmohr91
 Share

Recommended Posts

Ok, so I've got a long list of input boxes as part of my GUI. I'm using Koda to design it. When run, my GUI only shows the top fraction of my controls. I checked the help file and found the $WS_VSCROLL option. I added it to my code, and the scroll bar shows up, but doesn't do anything. What else do I need to do?

Ideally I would just have a separate tab, or "frame" with the list of input boxes within it. This separate frame could be scrolled within the main GUI. Is this possible from within Koda? I just started AutoIt a few weeks ago, so sorry for such a basic question.

Here's what I got so far

; GUI variables
$title = "Title"
$bold = 800
$__Group_Font_size = 10
$__Tab_Font_size = 10
$__Input_Font_size = 12

$temp = @OSVersion
If $temp = "WIN_XP" Then
    $font = "Times New Roman"
Else
    $font = "Segoe Print"
EndIf


#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate($title, 289, 621, 656, 31, $WS_VSCROLL BitOR $WS_THICKFRAME)
GUISetFont(10, 400, 0, $font)
$Group1 = GUICtrlCreateGroup("Align", 16, 272, 257, 193)
GUICtrlSetFont(-1, $__Group_Font_size, $bold, 0, $font)
$x = GUICtrlCreateInput("0", 40, 304, 81, 36)
GUICtrlSetFont(-1, 12, 800, 0, $font)
$Updown1 = GUICtrlCreateUpdown($x)
$y = GUICtrlCreateInput("0", 168, 304, 81, 36)
GUICtrlSetFont(-1, 12, 800, 0, $font)
$Updown2 = GUICtrlCreateUpdown($y)
$Button1 = GUICtrlCreateButton("Show Position", 40, 352, 209, 33, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Hover your mouse over the top", 40, 384, 208, 27)
$Label2 = GUICtrlCreateLabel("checkbox in the list and press", 40, 408, 202, 27)
$Label3 = GUICtrlCreateLabel("HOME on your keyboard.", 40, 432, 171, 27)
$Input25 = GUICtrlCreateInput("Input25", 64, 288, 1, 31)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Lable here", 16, 472, 257, 873)
GUICtrlSetFont(-1, $__Group_Font_size, $bold, 0, $font)
$Input1 = GUICtrlCreateInput("Input1", 35, 616, 209, 31)
$Input2 = GUICtrlCreateInput("Input2", 35, 648, 209, 31)
$Input3 = GUICtrlCreateInput("Input3", 35, 680, 209, 31)
$Input4 = GUICtrlCreateInput("Input1", 35, 712, 209, 31)
$Input5 = GUICtrlCreateInput("Input2", 35, 744, 209, 31)
$Input7 = GUICtrlCreateInput("Input1", 35, 808, 209, 31)
$Input6 = GUICtrlCreateInput("Input3", 35, 776, 209, 31)
$Input8 = GUICtrlCreateInput("Input2", 35, 840, 209, 31)
$Input9 = GUICtrlCreateInput("Input3", 35, 872, 209, 31)
$Input10 = GUICtrlCreateInput("Input1", 35, 904, 209, 31)
$Input11 = GUICtrlCreateInput("Input2", 35, 936, 209, 31)
$Input12 = GUICtrlCreateInput("Input3", 35, 968, 209, 31)
$Input13 = GUICtrlCreateInput("Input1", 35, 1000, 209, 31)
$Input14 = GUICtrlCreateInput("Input2", 35, 1032, 209, 31)
$Input15 = GUICtrlCreateInput("Input3", 35, 1064, 209, 31)
$Input16 = GUICtrlCreateInput("Input1", 35, 1096, 209, 31)
$Input17 = GUICtrlCreateInput("Input2", 35, 1128, 209, 31)
$Input19 = GUICtrlCreateInput("Input3", 35, 1352, 209, 31)
$Input18 = GUICtrlCreateInput("Input3", 35, 1160, 209, 31)
$Input20 = GUICtrlCreateInput("Input2", 35, 1320, 209, 31)
$Input24 = GUICtrlCreateInput("Input1", 35, 1192, 209, 31)
$Input23 = GUICtrlCreateInput("Input2", 35, 1224, 209, 31)
$Input22 = GUICtrlCreateInput("Input3", 35, 1256, 209, 31)
$Input21 = GUICtrlCreateInput("Input1", 35, 1288, 209, 31)
$Label4 = GUICtrlCreateLabel("Fill in these boxes with the names", 24, 507, 229, 27)
$Label5 = GUICtrlCreateLabel("of the ...", 24, 531, 227, 27)
$Label6 = GUICtrlCreateLabel("...", 24, 555, 209, 27)
$Label7 = GUICtrlCreateLabel("...", 24, 576, 207, 27)
;GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Start", 16, 48, 257, 201)
GUICtrlSetFont(-1, $__Group_Font_size, $bold, 0, $font)
$Slider1 = GUICtrlCreateSlider(32, 80, 225, 33)
$Button2 = GUICtrlCreateButton("Start", 32, 184, 225, 49, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, $font)
$Label8 = GUICtrlCreateLabel("Fast", 40, 112, 27, 23)
GUICtrlSetFont(-1, 8, 400, 0, $font)
$Label9 = GUICtrlCreateLabel("Slow", 224, 112, 30, 23)
GUICtrlSetFont(-1, 8, 400, 0, $font)
$Button3 = GUICtrlCreateButton("...", 32, 144, 225, 33, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label10 = GUICtrlCreateLabel("...", 72, 8, 132, 32)
GUICtrlSetFont(-1, 12, 800, 0, $font)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Edited by danielmohr91
Link to comment
Share on other sites

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Also little note:

instead of

$Form1 = GUICreate($title, 289, 621, 656, 31, $WS_VSCROLL BitOR $WS_THICKFRAME)

try

$Form1 = GUICreate($title, 289, 621, 656, 31, BitOR ($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME, $WS_VSCROLL))

Cool, that fixed that problem.

I studied the example from the link, but got pretty confused. I'm just starting off at programming and I got pretty lost in there. I've never seen dll before. It looks like the main idea is to make a child gui with the scrolling part in, and dock that to my main gui. Am I correct?

Here's what I have so far for the child gui

;my failed attempt at dimensioning the array:
;global $array[24]
;For $x = 1 To 24
;    ;  $array[$x] = $x
;Next

Global $array[24]
$array[0] = "input"
$array[1] = "input"
$array[2] = "input"
$array[3] = "input"
$array[4] = "input"
$array[5] = "input"
$array[6] = "input"
$array[7] = "input"
$array[8] = "input"
$array[9] = "input"
$array[10] = "input"
$array[11] = "input"
$array[12] = "input"
$array[13] = "input"
$array[14] = "input"
$array[15] = "input"
$array[16] = "input"
$array[17] = "input"
$array[18] = "input"
$array[19] = "input"
$array[20] = "input"
$array[21] = "input"
$array[22] = "input"
$array[23] = "input"


#include <GuiScrollBars.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 237, 782, 284, 176)
GUISetFont(10, 400, 0, "Segoe Print")
$Input1 = GUICtrlCreateInput($array[0], 11, 8, 209, 31)
$Input2 = GUICtrlCreateInput($array[1], 11, 40, 209, 31)
$Input3 = GUICtrlCreateInput($array[2], 11, 72, 209, 31)
$Input4 = GUICtrlCreateInput($array[3], 11, 104, 209, 31)
$Input5 = GUICtrlCreateInput($array[4], 11, 136, 209, 31)
$Input7 = GUICtrlCreateInput($array[5], 11, 200, 209, 31)
$Input6 = GUICtrlCreateInput($array[6], 11, 168, 209, 31)
$Input8 = GUICtrlCreateInput($array[7], 11, 232, 209, 31)
$Input9 = GUICtrlCreateInput($array[8], 11, 264, 209, 31)
$Input10 = GUICtrlCreateInput($array[9], 11, 296, 209, 31)
$Input11 = GUICtrlCreateInput($array[10], 11, 328, 209, 31)
$Input12 = GUICtrlCreateInput($array[11], 11, 360, 209, 31)
$Input13 = GUICtrlCreateInput($array[12], 11, 392, 209, 31)
$Input14 = GUICtrlCreateInput($array[13], 11, 424, 209, 31)
$Input15 = GUICtrlCreateInput($array[14], 11, 456, 209, 31)
$Input16 = GUICtrlCreateInput($array[15], 11, 488, 209, 31)
$Input17 = GUICtrlCreateInput($array[16], 11, 520, 209, 31)
$Input18 = GUICtrlCreateInput($array[17], 11, 584, 209, 31)
$Input19 = GUICtrlCreateInput($array[18], 11, 552, 209, 31)
$Input20 = GUICtrlCreateInput($array[19], 11, 616, 209, 31)
$Input21 = GUICtrlCreateInput($array[20], 11, 648, 209, 31)
$Input22 = GUICtrlCreateInput($array[21], 11, 680, 209, 31)
$Input23 = GUICtrlCreateInput($array[22], 11, 712, 209, 31)
$Input24 = GUICtrlCreateInput($array[23], 11, 744, 209, 31)

_GUIScrollBars_Init($Form1)
;$SB_VERT = 1000
_GUIScrollBars_SetScrollInfo($Form1, $SB_VERT)

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

#cs
I'm thinking to dock it I should start off with this mode
AutoItSetOption("CaretCoordMode" = 0)

sorry about the bloated code at the beginning, I couldn't think of a way to get the array dimensioned like that...

So I got the scroll bars showing, but I'm missing the part on how to actually make them do something. I fooled around with _GUIScrollBars_SetScrollInfo. I think I need to change the _GUIScrollBars_SetScrollInfo command, but was unsure of how to set the second parameter.

I'm also struggling to clip this child gui to my main gui. Would I have to use AutoItSetOption("CaretCoordMode" = 0) for window coords, or is there an easier way?

So my two main questions

1. How do I get the scroll bars to work. Am I on the right track with _GUIScrollBars_SetScrollInfo? If so how do I set the second parameter in it?

2. How do attach this child gui to my main gui?

Edited by danielmohr91
Link to comment
Share on other sites

Your attempt for the array was close but I am puzzled that you correctly used array[0] to [23] later in the script but didn't see what was wrong with [1] to [24] at the start.

global $array[24]
For $x = 0 To 23
    $array[$x] = 'input'
Next


#include <GuiScrollBars.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 237, 782, 284, 176)
GUISetFont(10, 400, 0, "Segoe Print")

Dim $input[24]
For $x = 0 to 23
 $Input[$x] = GUICtrlCreateInput($array[0], 11, 8 + 32*$x, 209, 31)
Next

_GUIScrollBars_Init($Form1)
;$SB_VERT = 1000
_GUIScrollBars_SetScrollInfo($Form1, $SB_VERT)

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

As far as getting the scroll bars to work, have you have looked at the example I gave a link for in post #2 or the information Zedna gave in his posts? Or look at the examples in the help such as _GuiScrollbars_Init?

There is no need to create a child window for your example. The basic idea is that when an event occurs with a scrollbar, a message is sent to the window and your code has to have some way of dealing with the message.

It is worth looking at Kip's UDF for scrollbars because it makes dealing with them much simpler IMO.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Wow! That UDF is great! Made things so much easier. And thanks so much for helping me with the array. That's the first real array I've ever done, the only arrays I've ever used were ones automatically created from commands, ie WinGetPos

I've got my main window scrolling, and working great. I also wrote a sample script and got a scrolling frame within another scrolling gui. Cool stuff. Thanks so much for your help. One last question if you don't mind -- I used the array like you suggested, to build my list of input boxes, and set the text within them.

Dim $array[24]
Dim $input[24]
For $x = 0 To 23
    $input[$x] = GUICtrlCreateInput($array[0], 35, 625 + 32 * $x, 209, 31)
    GUICtrlSetFont(-1, $__Input_Font_size, $bold, 0, $font)
    GUICtrlSetData($input[$x], "Name " & $x + 1)
Next

...but when I try and read them using $input1 $input2 etc... in my loop

While 1
    $iScrollPos = Scrollbar_GetPos($GUI, $SB_VERT)
    ConsoleWrite($iScrollPos & @CRLF)

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $input1
            GUICtrlSetData($input1,"")
    EndSwitch
WEnd

It says variable used before declaration. I understand the error message, but any idea's what I'm doing wrong?

Link to comment
Share on other sites

I'm glad you made some good progress. ;)

The array for the inputs creates a set of variables $input[0], $input[1] etc and not $input1, $input2.

Here is one way to check which control is causing the event and responding to it

While 1
    $iScrollPos = Scrollbar_GetPos($GUI, $SB_VERT)
    ConsoleWrite($iScrollPos & @CRLF)

    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $input[0] To $inpuit[UBound($input) - 1]

    ;one way of dealing With it, because we know that the control has the ID $nMsg
    GUICtrlSetData($nMsg, "")

    ;another way is to find which control like this
    Local $IPNum
    For $n = 0 To UBound($input) - 1
    If $nMsg = $input[$n] Then
    $IPNum = $n
    ExitLoop
    EndIf
    Next
    GUICtrlSetData($input[$IPNum], "")

    EndSwitch
WEnd
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I'm glad you made some good progress. ;)

The array for the inputs creates a set of variables $input[0], $input[1] etc and not $input1, $input2.

Here is one way to check which control is causing the event and responding to it

While 1
    $iScrollPos = Scrollbar_GetPos($GUI, $SB_VERT)
    ConsoleWrite($iScrollPos & @CRLF)

    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $input[0] To $inpuit[UBound($input) - 1]

    ;one way of dealing With it, because we know that the control has the ID $nMsg
    GUICtrlSetData($nMsg, "")

    ;another way is to find which control like this
    Local $IPNum
    For $n = 0 To UBound($input) - 1
    If $nMsg = $input[$n] Then
    $IPNum = $n
    ExitLoop
    EndIf
    Next
    GUICtrlSetData($input[$IPNum], "")

    EndSwitch
WEnd

Wow! You're great at this! I squealed with delight as I read your code. Simply brilliant! Thank you SO much for your help!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...