Sign in to follow this  
Followers 0
Pimmetje

Dynamic GUI

3 posts in this topic

gui.au3

I made a gui

; include needed data
#include <ScrollBarConstants.au3>
#include <GUIScrollBars.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

; No auto pause when click autoit tray icon
AutoItSetOption("TrayAutoPause", 0)
; Remove exit and pause from the tray menu
Opt("TrayMenuMode",1)
; Disable exit on ESC
AutoItSetOption("GUICloseOnESC", 0)

; Make a menu for the tray icon
global $trayitemlogdir = TrayCreateItem("Logdir")
global $trayitemlog = TrayCreateItem("Log")
global $trayaboutitem = TrayCreateItem("About")
TrayCreateItem("")
global $trayexititem = TrayCreateItem("Exit")
TraySetState()

Global $_GUI = True
dim $scroll = False
dim $right = 10 ; Right space
dim $rowh = 20 ; Row height
; Get num elements
dim $size = 10
dim $width = 505
dim $totheight = $size * (($rowh - 1) + 1) + 20
dim $maxheight = @DesktopHeight - 100
dim $windowheight
dim $diff = -1
if($totheight > $maxheight) Then
    $windowheight = @DesktopHeight - 100
    $scroll = true
    $diff = (($totheight - $maxheight))
Else
    $windowheight = $totheight
EndIf
dim $hGUI = GuiCreate("Gui window", $width, $windowheight, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX))
GUICtrlSetResizing($hGUI, $GUI_DOCKMENUBAR)
; Menu
$filemenu = GUICtrlCreateMenu("File")
Global $menuinstall = GUICtrlCreateMenuItem("Installeren", $filemenu)
Global $menuexit = GUICtrlCreateMenuItem("Exit", $filemenu)
$editmenu = GUICtrlCreateMenu("Edit")
Global $editsall = GUICtrlCreateMenuItem("Select all", $editmenu)
Global $editsnone = GUICtrlCreateMenuItem("Select none", $editmenu)
Global $editsinv = GUICtrlCreateMenuItem("Inverse select", $editmenu)
$helpmenu = GUICtrlCreateMenu("?")
Global $aboutmenuitem = GUICtrlCreateMenuItem("About", $helpmenu)
; Make a rightclick menu on the gui
$trackmenu = GuiCtrlCreateContextMenu ()
Global $aboutrightclickitem = GuiCtrlCreateMenuitem ("About",$trackmenu)

Global $checkbox[($size + 1)]
$checkbox[0] = $size
;_ArrayDisplay($array)
;GUISetStyle (-1, $WS_VSCROLL)
FOR $i = 1 TO $size ; Look touch all the software things
    $checkbox[$i] = GuiCtrlCreateCheckbox($i, $right, (($rowh * $i) - $rowh))
    GUICtrlSetResizing( -1, 2 + 32 + 256 + 512)
    GuiCtrlSetState(-1, $GUI_UNCHECKED)
NEXT

GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
_GUIScrollBars_Init($hGUI)
;_GUIScrollBars_ShowScrollBar($hGUI, $SB_HORZ, false)
_GUIScrollBars_ShowScrollBar($hGUI, $SB_VERT, true)

GUISetState(@SW_SHOW)
While 1
    if(checkevents(10)) Then
        ExitLoop
    EndIf
WEnd
Exit 0


func setselectstate($cb, $type="inv")
        dim $size = $cb[0]
        for $i = 1 To $size
            switch $type
                case "none"
                    GuiCtrlSetState($cb[$i], $GUI_UNCHECKED)
                case "all"
                    GuiCtrlSetState($cb[$i], $GUI_CHECKED)
                case Else
                    switch GUICtrlRead($cb[$i])
                        case $GUI_CHECKED
                            GuiCtrlSetState($cb[$i], $GUI_UNCHECKED)
                        Case $GUI_UNCHECKED
                            GuiCtrlSetState($cb[$i], $GUI_CHECKED)
                    EndSwitch
            EndSwitch
        Next
EndFunc

func checkevents($wait = 10) 
    dim $bool = false
    dim $i = 1
    while ($i < $wait)
        dim $msg = GuiGetMsg()
        dim $tray = TrayGetMsg()
        Select 
            case $tray = $trayexititem or ($_GUI and ($msg = $GUI_EVENT_CLOSE or $msg = $menuexit))
                exit 
            case $tray = $trayaboutitem or ($_GUI and ($msg = $aboutmenuitem or $msg = $aboutrightclickitem))
                about()
            case $_GUI and $msg = $menuinstall
                return true
            case $_GUI and $msg = $editsall
                setselectstate($checkbox, "all")
            case $_GUI and $msg = $editsnone
                setselectstate($checkbox, "none")
            case $_GUI and $msg = $editsinv
                setselectstate($checkbox, "inv")
        EndSelect
        $i = $i + 1
    WEnd
    return $bool
EndFunc

func about()
    MsgBox(0, "GUI", "Myinstaller v "& @CRLF &"Created by Pimmetje" & @CRLF & "Please report bugs you may find." & @CRLF & "Known bugs," & @CRLF & "* GUI scrollbar gets to big (atm better then non)")
EndFunc

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

Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg, $wParam
    Local $index = -1, $yChar, $xChar, $xClientMax, $xClient, $yClient, $ivMax
    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $index = $x
            $xClientMax = $aSB_WindowInfo[$index][1]
            $xChar = $aSB_WindowInfo[$index][2]
            $yChar = $aSB_WindowInfo[$index][3]
            $ivMax = $aSB_WindowInfo[$index][7]
            ExitLoop
        EndIf
    Next
    If $index = -1 Then Return 0

    Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)
    
    ; Retrieve the dimensions of the client area.
    $xClient = BitAND($lParam, 0x0000FFFF)
    $yClient = BitShift($lParam, 16)
    $aSB_WindowInfo[$index][4] = $xClient
    $aSB_WindowInfo[$index][5] = $yClient
    
    ; Set the vertical scrolling range and page size
    DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
    DllStructSetData($tSCROLLINFO, "nMin", 0)
    DllStructSetData($tSCROLLINFO, "nMax", $ivMax)
    DllStructSetData($tSCROLLINFO, "nPage", $yClient / $yChar)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    
    ; Set the horizontal scrolling range and page size
    DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
    DllStructSetData($tSCROLLINFO, "nMin", 0)
    DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar)
    DllStructSetData($tSCROLLINFO, "nPage", $xClient / $xChar)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

The data can be dynamic so i wont know how many there will be. When the current screen res is too small it has to create a scrollbar so the user can reach to the rest of them. It works but i can scroll too far.

I tried a lot but i just don't get the idea of the way scrollbars are used in autoscript

Thanks for reading (hope you can help me :) )

Pimmetje

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I made a gui

The data can be dynamic so i wont know how many there will be. When the current screen res is too small it has to create a scrollbar so the user can reach to the rest of them. It works but i can scroll too far.

I tried a lot but i just don't get the idea of the way scrollbars are used in autoscript

Thanks for reading (hope you can help me :) )

Pimmetje

Personnally I find it awkward that the units used for scroll bars tend to be in character heights and not pixels and I think that has been part of your problem. I prefer to use pixels because It seems much easier. The size of the scroll bar needs to be set using _GUIScrollBars_SetScrollInfoMax to represent the whole of the window height (or width) that has to be shown, and the thumb button should be set with _GUIScrollBars_SetScrollInfoPage to represent the height of the window you can see, ie the client height. The page size therefore has to be adjusted as the window is resized, but the max value doesn't change unless you add more components extending the area used.

I modified your code to get the vertical scroll working, see what you think.

; include needed data
 #include <ScrollBarConstants.au3>
 #include <GUIScrollBars.au3>
 #include <GuiConstantsEx.au3>
 #include <WindowsConstants.au3>
 #include <Array.au3>
 
 Global Const $WM_ENTERSIZEMOVE = 0x231, $WM_EXITSIZEMOVE = 0x232
 
; No auto pause when click autoit tray icon
 AutoItSetOption("TrayAutoPause", 0)
; Remove exit and pause from the tray menu
 Opt("TrayMenuMode",1)
; Disable exit on ESC
 AutoItSetOption("GUICloseOnESC", 0)
 
; Make a menu for the tray icon
 global $trayitemlogdir = TrayCreateItem("Logdir")
 global $trayitemlog = TrayCreateItem("Log")
 global $trayaboutitem = TrayCreateItem("About")
 TrayCreateItem("")
 global $trayexititem = TrayCreateItem("Exit")
 TraySetState()
 
 Global $_GUI = True
 dim $scroll = False
 dim $right = 10; Right space
 dim $rowh = 20; Row height
; Get num elements
 dim $size = 10
 dim $width = 505
 dim $totheight = $size * (($rowh - 1) + 1) + 20
 dim $maxheight = @DesktopHeight - 100
 dim $windowheight
 dim $diff = -1
 if($totheight > $maxheight) Then
     $windowheight = @DesktopHeight - 100
     $scroll = true
     $diff = (($totheight - $maxheight))
 Else
     $windowheight = $totheight
 EndIf
 dim $hGUI = GuiCreate("Gui window", $width, $windowheight, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX));
 GUICtrlSetResizing($hGUI, $GUI_DOCKMENUBAR)
; Menu
 $filemenu = GUICtrlCreateMenu("File")
 Global $menuinstall = GUICtrlCreateMenuItem("Installeren", $filemenu)
 Global $menuexit = GUICtrlCreateMenuItem("Exit", $filemenu)
 $editmenu = GUICtrlCreateMenu("Edit")
 Global $editsall = GUICtrlCreateMenuItem("Select all", $editmenu)
 Global $editsnone = GUICtrlCreateMenuItem("Select none", $editmenu)
 Global $editsinv = GUICtrlCreateMenuItem("Inverse select", $editmenu)
 $helpmenu = GUICtrlCreateMenu("?")
 Global $aboutmenuitem = GUICtrlCreateMenuItem("About", $helpmenu)
; Make a rightclick menu on the gui
 $trackmenu = GuiCtrlCreateContextMenu ()
 Global $aboutrightclickitem = GuiCtrlCreateMenuitem ("About",$trackmenu)
 
 Global $checkbox[($size + 1)]
 $checkbox[0] = $size
;_ArrayDisplay($array)
;GUISetStyle (-1, $WS_VSCROLL)
 FOR $i = 1 TO $size; Look touch all the software things
     $checkbox[$i] = GuiCtrlCreateCheckbox($i, $right, (($rowh * $i) - $rowh))
     GUICtrlSetResizing( -1, 2 + 32 + 256 + 512)
     GuiCtrlSetState(-1, $GUI_UNCHECKED)
 NEXT
 
 GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
 GUIRegisterMsg($WM_SIZE, "WM_SIZE")
 GUIRegisterMsg($WM_ENTERSIZEMOVE, "EnterSizeMove")
 _GUIScrollBars_Init($hGUI)
;_GUIScrollBars_ShowScrollBar($hGUI, $SB_HORZ, false)
 _GUIScrollBars_ShowScrollBar($hGUI, $SB_VERT, true)
;_GUIScrollBars_SetScrollInfoMin($hGUI, $SB_VERT, 10)
     _GUIScrollBars_SetScrollInfoMax($hGUI, $SB_VERT, $windowheight)
     _GUIScrollBars_SetScrollInfoPage($hGUI, $SB_VERT, $windowheight)
 GUISetState(@SW_SHOW)
 While 1
     if(checkevents(10)) Then
         ExitLoop
     EndIf
 WEnd
 Exit 0
 
 
 func setselectstate($cb, $type="inv")
         dim $size = $cb[0]
         for $i = 1 To $size
             switch $type
                 case "none"
                     GuiCtrlSetState($cb[$i], $GUI_UNCHECKED)
                 case "all"
                     GuiCtrlSetState($cb[$i], $GUI_CHECKED)
                 case Else
                     switch GUICtrlRead($cb[$i])
                         case $GUI_CHECKED
                             GuiCtrlSetState($cb[$i], $GUI_UNCHECKED)
                         Case $GUI_UNCHECKED
                             GuiCtrlSetState($cb[$i], $GUI_CHECKED)
                     EndSwitch
             EndSwitch
         Next
 EndFunc
 
 func checkevents($wait = 10)
     dim $bool = false
     dim $i = 1
     while ($i < $wait)
         dim $msg = GuiGetMsg()
         dim $tray = TrayGetMsg()
         Select
             case $tray = $trayexititem or ($_GUI and ($msg = $GUI_EVENT_CLOSE or $msg = $menuexit))
                 exit
             case $tray = $trayaboutitem or ($_GUI and ($msg = $aboutmenuitem or $msg = $aboutrightclickitem))
                 about()
             case $_GUI and $msg = $menuinstall
                 return true
             case $_GUI and $msg = $editsall
                 setselectstate($checkbox, "all")
             case $_GUI and $msg = $editsnone
                 setselectstate($checkbox, "none")
             case $_GUI and $msg = $editsinv
                 setselectstate($checkbox, "inv")
         EndSelect
         $i = $i + 1
     WEnd
     return $bool
 EndFunc
 
 func about()
     MsgBox(0, "GUI", "Myinstaller v "& @CRLF &"Created by Pimmetje" & @CRLF & "Please report bugs you may find." & @CRLF & "Known bugs," & @CRLF & "* GUI scrollbar gets to big (atm better then non)")
 EndFunc
 
 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
 $ychar = 1; I want to use pixels
 
   ; 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
 
 Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
      Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)
      _GUIScrollBars_GetScrollInfo($hGUI, $SB_HORZ, $tSCROLLINFO)
      
    ;get the client height
      Local $iH = BitAnd($lParam,0xFFFF0000)/0x10000
   ;set the thumb size
     _GUIScrollBars_SetScrollInfoPage($hGUI, $SB_VERT,$ih)
     
       return $GUI_RUNDEFMSG
     
 EndFunc ;==>WM_SIZE
 
 Func EnterSizeMove()
     Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)
      _GUIScrollBars_GetScrollInfo($hGUI, $SB_VERT, $tSCROLLINFO)
      dllstructsetdata($tSCROLLINFO, "nPos",0)
      DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
     _GUIScrollBars_SetScrollInfo($hGUI, $SB_VERT,$tSCROLLINFO)
     return $GUI_RUNDEFMSG
 EndFunc

EDit:spelling

mgrefscrollbars

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.

Share this post


Link to post
Share on other sites

I don't have time check it today but it seems to work so ill think i can figure it out.

Thank you for the replay.

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