Jump to content

scrolling inputfields


Richard
 Share

Recommended Posts

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
global $fields=25
Global $Input[$fields+1] = [$fields] ; Table with number of input fields+1 (here: 9), first element set to the number of input fields (here: 9)
global $lab[$fields+1]
; name labels
for $i=1 to $fields
    $lab[$i]="label "&$i&":"
next
$inpwidth=250
local $x,$y
$x=8
$y=11
$Form1_1 = GUICreate("Input Form", $inpwidth+100,$input[0] * 27, 311, 86)
for $i=1 to $input[0]
    GUICtrlCreateLabel($lab[$i], $x, $y+($i*22), 55, 17)
    $Input[$i] = GUICtrlCreateInput("", $x+70, ($y-3)+($i*22), $inpwidth, 21)
next
$Button1 = GUICtrlCreateButton("Process Input", $x+70, $i*23, 89, 25, $WS_GROUP)
; process and empty inputs
$Button3 = GUICtrlCreateButton("Exit", $x+200, $i*23, 89, 25, $WS_GROUP)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    For $Count = 1 To $Input[0]
                if StringLen(GUICtrlRead($Input[$Count])) > 0 then
                    DisplayValue($Count, GUICtrlRead($Input[$Count]))
                endif
    Next
    EndSwitch
WEnd

Func DisplayValue($Number, $Value)
    MsgBox(0, "", "Value for Field " & $Number & " is '" & $Value & "'")
EndFunc ;==>DisplayValue

----------------------------------------------

Above code is displaying 25 labels together with 25 inputfields.

The window is calculated according the number of needed lines.

Is it possible in Autoit to have a vertically scrolling window when the number of lines is bigger then the screen?

Or simply define a fixed window, and scroll it when the number o lines (inputs/labels) exceeds

the windowheight?

Richard

Link to comment
Share on other sites

Since I get no reply, I presume that my question is not clear.

I have a window 200 pixels high.

I have 20 labels with associated inputcontols (on same line).

They will not fit in the window.

I want the thing to scroll when the initially visible inputs are filled.

Link to comment
Share on other sites

  • Moderators

Richard,

Is it possible in Autoit to have a vertically scrolling window when the number of lines is bigger then the screen?

Yes, but you are not going to like how complicated it looks - sorry. :D

You have to create scroll bars for the GUI using the GUIScrollBars UDF and then trap the messages the scroll bars send so you can move the inner area of the GUI. The final result looks like this:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>

Global $fields = 15
Global $Input[$fields + 1] = [$fields] ; Table with number of input fields+1 (here: 9), first element set to the number of input fields (here: 9)
Global $lab[$fields + 1]
Global $iGUI_Ht = 300

; name labels
For $i = 1 To $fields
    $lab[$i] = "label " & $i & ":"
Next

$inpwidth = 250
Local $x, $y ; In the main script , all variables are Global
$x = 8
$y = 11

$Form1_1 = GUICreate("Input Form", $inpwidth + 100, $iGUI_Ht, 311, 86)

For $i = 1 To $Input[0]
    GUICtrlCreateLabel($lab[$i], $x, $y + ($i * 22), 55, 17)
    $Input[$i] = GUICtrlCreateInput("", $x + 70, ($y - 3) + ($i * 22), $inpwidth, 21)
Next

; Y pos changed to make independent of no of inputs
$Button1 = GUICtrlCreateButton("Process Input", $x + 70, $y + ($i * 22) + 20, 89, 25) ; This is a Koda waste of space >>>>, $WS_GROUP)
; process and empty inputs
$Button3 = GUICtrlCreateButton("Exit", $x + 200, $y + ($i * 22) + 20, 89, 25); , $WS_GROUP)

GUISetState(@SW_SHOW)

; You need to intercept the scrollbar messages
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")

; Initialise the scroll bars
_GUIScrollBars_Init($Form1_1)
; Hide the horizontal one
_GUIScrollBars_ShowScrollBar($Form1_1, $SB_HORZ, False)
; Set scroll range so all inputs visible
$iInput_Ht = $y + ($i * 22) + 25 + 10 ; Top margin + inputs + button + bottom margin
_GUIScrollBars_SetScrollRange($Form1_1, $SB_VERT, 1, Ceiling($iInput_Ht / 16))

While 1
    ;$nMsg = GUIGetMsg()
    Switch GUIGetMsg() ; $nMsg  Saves a line!!!
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            For $Count = 1 To $Input[0]
                If StringLen(GUICtrlRead($Input[$Count])) > 0 Then
                    DisplayValue($Count, GUICtrlRead($Input[$Count]))
                EndIf
            Next
    EndSwitch
WEnd

Func DisplayValue($Number, $Value)
    MsgBox(0, "", "Value for Field " & $Number & " is '" & $Value & "'")
EndFunc   ;==>DisplayValue

Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg, $wParam, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $index = -1, $yChar, $yPos
    Local $Min, $Max, $Page, $Pos, $TrackPos

    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $index = $x
            $yChar = $aSB_WindowInfo[$index][3]
            ExitLoop
        EndIf
    Next
    If $index = -1 Then Return 0

    ; Get all the vertial scroll bar information
    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
    $Min = DllStructGetData($tSCROLLINFO, "nMin")
    $Max = DllStructGetData($tSCROLLINFO, "nMax")
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    ; Save the position for comparison later on
    $yPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $yPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")

    Switch $nScrollCode
        Case $SB_TOP ; user clicked the HOME keyboard key
            DllStructSetData($tSCROLLINFO, "nPos", $Min)

        Case $SB_BOTTOM ; user clicked the END keyboard key
            DllStructSetData($tSCROLLINFO, "nPos", $Max)

        Case $SB_LINEUP ; user clicked the top arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)

        Case $SB_LINEDOWN ; user clicked the bottom arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)

        Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)

        Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)

        Case $SB_THUMBTRACK ; user dragged the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch

;~    // Set the position and then retrieve it.  Due to adjustments
;~    //   by Windows it may not be the same as the value set.

    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    ;// If the position has changed, scroll the window and update it
    $Pos = DllStructGetData($tSCROLLINFO, "nPos")

    If ($Pos <> $yPos) Then
        _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
        $yPos = $Pos
    EndIf

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_VSCROLL

I told you that you would not like it! :D

A couple of points to calm you down now you have seen the script - :D

1. Actually creating the bars (and hiding the horizontal one) is easy, as you can see.

2. You need not worry about how to intercept the scroll bar messages because the GUIRegisterMsg command and the WM_VSCROLL function does all the hard work for you. (Say thanks to Gary Frost who coded it for us all :huggles: ) If you want to know more about what GUIRegisterMsg does, just look here.

3. The only bit you have to worry about as a coder is setting the ScrollRange so that all the inputs come into view as you move the scroll bar - and here you can thank me for the calculation Range = Ceiling($iInput_Ht / 16). It will work for any internal window height and any chosen external GUI height as long as you keep the default GUI font. Try changing the values of $fields and $iGUI_Ht - you should find the button come into view as the scroll bar hits the bottom.

I hope everything else is clear enough - please ask if not. :)

M23

Edit: Do not be so impatient. : Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually - as I just have.

And it is normally considered rude to bump your own post within 24 hours - just so you know in the future! :D

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Richard,

It is the GUI default font that defines the Page size - the number of lines displayed on each "page" of the internal window and so the factor which determines the number of "pages" you have to scroll. So merely changing the font size in a control will have no effect on the SetRange calculation. :D Of course you will have to modify the the $iInput_Ht calculation which determines the overall height of the internal window so you get the correct value to use in the SetRange calculation.

I tried increasing the label font here (using a variable $iLabel_Ht to set the height of the inputs and labels, and calculate the overall height) and you can see that the SetRange calculation is still valid: :huggles:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>

Global $fields = 150
Global $Input[$fields + 1] = [$fields] ; Table with number of input fields+1 (here: 9), first element set to the number of input fields (here: 9)
Global $lab[$fields + 1]
Global $iGUI_Ht = 200
Global $iLabel_Ht = 25

; name labels
For $i = 1 To $fields
    $lab[$i] = "label " & $i & ":"
Next

$inpwidth = 200
Local $x, $y ; In the main script , all variables are Global
$x = 8
$y = 11

$Form1_1 = GUICreate("Input Form", $inpwidth + 130, $iGUI_Ht, 311, 86)

For $i = 1 To $Input[0]
    GUICtrlCreateLabel($lab[$i], $x, $y + ($i * ($iLabel_Ht+ 5)), 100, $iLabel_Ht)
    GUICtrlSetFont(-1, 16)
    $Input[$i] = GUICtrlCreateInput("", $x + 110, ($y - 3) + ($i * ($iLabel_Ht + 5)), $inpwidth, $iLabel_Ht)
Next

; Y pos changed to make independent of no of inputs
$Button1 = GUICtrlCreateButton("Process Input", $x + 70, $y + ($i * ($iLabel_Ht + 5)) + 20, 89, 25) ; This is a Koda waste of space >>>>, $WS_GROUP)
; process and empty inputs
$Button3 = GUICtrlCreateButton("Exit", $x + 200, $y + ($i * ($iLabel_Ht + 5)) + 20, 89, 25); , $WS_GROUP)

GUISetState(@SW_SHOW)

; You need to intercept the scrollbar messages
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")

; Initialise the scroll bars
_GUIScrollBars_Init($Form1_1)
; Hide the horizontal one
_GUIScrollBars_ShowScrollBar($Form1_1, $SB_HORZ, False)
; Set scroll range so all inputs visible
$iInput_Ht = $y + ($i * ($iLabel_Ht + 5)) + 25 + 10 ; Top margin + inputs + button + bottom margin
_GUIScrollBars_SetScrollRange($Form1_1, $SB_VERT, 1, Ceiling($iInput_Ht / 16))

While 1
    ;$nMsg = GUIGetMsg()
    Switch GUIGetMsg() ; $nMsg  Saves a line!!!
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            For $Count = 1 To $Input[0]
                If StringLen(GUICtrlRead($Input[$Count])) > 0 Then
                    DisplayValue($Count, GUICtrlRead($Input[$Count]))
                EndIf
            Next
    EndSwitch
WEnd

Func DisplayValue($Number, $Value)
    MsgBox(0, "", "Value for Field " & $Number & " is '" & $Value & "'")
EndFunc   ;==>DisplayValue

Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg, $wParam, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $index = -1, $yChar, $yPos
    Local $Min, $Max, $Page, $Pos, $TrackPos

    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $index = $x
            $yChar = $aSB_WindowInfo[$index][3]
            ExitLoop
        EndIf
    Next
    If $index = -1 Then Return 0

    ; Get all the vertial scroll bar information
    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
    $Min = DllStructGetData($tSCROLLINFO, "nMin")
    $Max = DllStructGetData($tSCROLLINFO, "nMax")
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    ; Save the position for comparison later on
    $yPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $yPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")

    Switch $nScrollCode
        Case $SB_TOP ; user clicked the HOME keyboard key
            DllStructSetData($tSCROLLINFO, "nPos", $Min)

        Case $SB_BOTTOM ; user clicked the END keyboard key
            DllStructSetData($tSCROLLINFO, "nPos", $Max)

        Case $SB_LINEUP ; user clicked the top arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)

        Case $SB_LINEDOWN ; user clicked the bottom arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)

        Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)

        Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)

        Case $SB_THUMBTRACK ; user dragged the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch

;~    // Set the position and then retrieve it.  Due to adjustments
;~    //   by Windows it may not be the same as the value set.

    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    ;// If the position has changed, scroll the window and update it
    $Pos = DllStructGetData($tSCROLLINFO, "nPos")

    If ($Pos <> $yPos) Then
        _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
        $yPos = $Pos
    EndIf

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_VSCROLL

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...