Sign in to follow this  
Followers 0
GreenCan

scroll bar input question

4 posts in this topic

#1 ·  Posted (edited)

I have a variable amount of columns for which I need to set some parameters.

Most of the parameters are selectable with a check box (via a GuiCtrlCreateTreeView), other require an input field.

As far as I am aware there are no existing functions for this kind of input. So I used the udf WM_VSCROLL (for which several examples can be found on this forum) to emulate GuiCtrlCreateTreeView alike input.

To keep it simple, the attached example only treats two parameters (Average and column width) but my final project requires several of these scrollbar Treeviews things.

I am pretty happy with the result until now but I am wondering if this is in fact a good approach. Maybe there are much more simple solutions but I couldn't find any on this forum.

What's not so good in my opinion?

1. Complex script. I believe the code creates unnecessary overhead for something that in theory should be reasonably simple to do.

2. Font issue. The default fonts used in the main Gui and in the GuiCtrl are different. In order to have the same look and feel,

I needed to define the font as well for the GUI as for the GuiCtrl (in the example, the font is Tahoma.

If I don't do this, the font will be different in the left treeview and the right GUI. Try it by removing the font name in line 25.

3. The border of the right $_GUI2 scrollbox($WS_BORDER) is black resulting in a non standard look and feel.

I replaced the straightforward $WS_BORDER by a series of coloured labels (lines 47-56)

Your opinion, ideas and alternatives will be highly appreciated

Thanks

Greencan

Updated code

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         GreenCan

 Script Function:
    Example of TreeView and scrollbar input 

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
#include <Array.au3>
#include <TreeViewConstants.au3>

Opt("MustDeclareVars", 1)

_GUI_example()

Func _GUI_example()
    Local $Msg, $_GUI1, $_GUI2, $m, $font = "Tahoma", $OKButton, $Checked, $Number_Rows = 15
    DIM $Columns[$Number_Rows+1][2]
    ; put some stuff in the cells   
    $Columns[4][0] = True
    $Columns[6][0] = True
    $Columns[13][0] = True  
    $Columns[4][1] = 20
    $Columns[5][1] = 53
    $Columns[6][1] = 120

    GUISetFont (-1,-1,-1,$font)
    $_GUI1 = GUICreate("ScrollBar TreeView check box and Input", 320, 270, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX))
    $OKButton = GUICtrlCreateButton("OK ", 135, 240, 50, 20)
    
    ; TreeView CALCULATE AVERAGE
    GUICtrlCreateGroup("Calculate Average", 20, 10, 120, 205)   
    Local $TreeAvg = GuiCtrlCreateTreeView(25, 30, 110, 180, $TVS_CHECKBOXES, $WS_EX_STATICEDGE)
    GUICtrlSetColor(-1, 0x00008B)
    GUICtrlSetBkColor(-1, 0xEAFFE8)     
    GUICtrlSetTip(-1, "Check the column for which an average should be calculated") 
    For $i = 0 To UBound($Columns)-1
        If $Columns[$i][0] = True Then 
            ; checked
            $Columns[$i][0] = GuiCtrlCreateTreeViewItem("Column " & $i + 1, $TreeAvg)
            GuiCtrlSetState(-1, $GUI_CHECKED)           
        Else
            ; unchecked
            $Columns[$i][0] = GuiCtrlCreateTreeViewItem("Column " & $i + 1, $TreeAvg)
        EndIf
    Next

    ; column width
    GUICtrlCreateGroup("Column Width", 170, 10, 120, 205, -1,$WS_EX_TRANSPARENT)    
    $_GUI2 = GUICreate("ChildGUI", 108, 178, 175, 30, $WS_CHILD, $WS_EX_CONTROLPARENT+$WS_EX_STATICEDGE, $_GUI1)

    GUICtrlSetDefColor(0x00008B)    
    GUISetBkColor(0xEAFFE8)     
    

    For $i = 0 To UBound($Columns)-1
        GUISetFont (8.5,400,-1,$font)
        GUICtrlCreateLabel("Column " & $i + 1, 5, 1 + 2 + $i * 16, 65, 14)
        GUISetFont (8.1,-1,-1,$font)
        $Columns[$i][1] = GUICtrlCreateInput($Columns[$i][1], 70, 2 + $i * 16, 35, 14)
        GUICtrlSetTip(-1, "The column width is calculated in characters")   
    Next
    _GUIScrollBars_Init($_GUI2)
    _GUIScrollBars_ShowScrollBar($_GUI2, $SB_HORZ, False)
    _GUIScrollBars_SetScrollInfoMax($_GUI2, $SB_VERT, (UBound($Columns)-    2))   
    
    GUISetState()
    GUICtrlSetResizing($_GUI2, $GUI_DOCKALL)

    GUISwitch($_GUI1)
    GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
    
    GUISetState()

    Do
        $Msg = GUIGetMsg()

        Select 
        Case $msg = $GUI_EVENT_CLOSE Or $Msg = $OKButton
            For $i = 0 To UBound($Columns)-1
                If BitAnd(GUICtrlRead($Columns[$i][0]),$GUI_CHECKED) Then 
                    $Columns[$i][0] = True
                Else
                    $Columns[$i][0] = ""
                EndIf
                $Columns[$i][1] = GUICtrlRead($Columns[$i][1])              
            Next
            ; GUIDelete($_GUI2) ; not sure if this is required
            GUIDelete($_GUI1)
            ExitLoop
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE   
    
    _ArrayDisplay($Columns)

    Exit
EndFunc  ;==>_GUI_example
#FUNCTION# ==============================================================
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 vertical 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
#FUNCTION# ==============================================================
Edited by GreenCan

Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Share this post


Link to post
Share on other sites



Maybe I should put this in Example Scripts so I could have some reactions... :)

Greencan


Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Share this post


Link to post
Share on other sites

looks good, but you don't need the border replacement. this is enough:

$_GUI2 = GUICreate("ChildGUI", 108, 178, 175, 30, $WS_CHILD, $WS_EX_CONTROLPARENT+$WS_EX_STATICEDGE, $_GUI1)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

looks good, but you don't need the border replacement. this is enough:

$_GUI2 = GUICreate("ChildGUI", 108, 178, 175, 30, $WS_CHILD, $WS_EX_CONTROLPARENT+$WS_EX_STATICEDGE, $_GUI1)
Hi ProgAndy,

That is indeed a bit simpler. I am not a maniac of perfectionism :P but the style is just a bit different from the first border though.

I got it right by changing line 41 to:

Local $TreeAvg = GuiCtrlCreateTreeView(25, 30, 110, 180, $TVS_CHECKBOXES, $WS_EX_STATICEDGE)

Thanks for your help and feedback

Greencan


Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0