Jump to content

How to create ScrollBox?


hunt
 Share

Recommended Posts

If it is necessary for someone, here a good example.

This is a ready code for ScrollBox.

Thanks Authenticity for his next post.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
Opt("GUIResizeMode",$GUI_DOCKALL) 
$buffer = False
$bit=1
_Main()


Func _Main()  
    Global $Form1 = GUICreate("Form1", 318, 220,-1,-1,-1, -1)
    $a_pos=WinGetPos ($Form1)
    $Tab1 = GUICtrlCreateTab(5,5, 289, 193) 
    $TabSheet1 = GUICtrlCreateTabItem("TabSheet1")  
    $TabSheet2 = GUICtrlCreateTabItem("TabSheet2")  
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW,$Form1)
    
    Global $hGUI = GUICreate("Child GUI", 287, 169,$a_pos[0]+9,$a_pos[1]+51,$WS_POPUP,-1, $Form1)   
    GUISetBkColor(0xFFFFFF)
    $Button1=GUICtrlCreateButton("a button", 60, 70, 90, 20)    
        
    _GUIScrollBars_Init($hGUI)
    _GUIScrollBars_ShowScrollBar($hGUI,$SB_HORZ,False)
    GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
    GUIRegisterMsg($WM_MOVE, "WM_MOVE")
    
    While 1
    $nMsg = GUIGetMsg()
        Select
            Case $nMsg = $GUI_EVENT_CLOSE
                Exit
            Case $nMsg=$Button1                 
                    $bit=BitXOR($bit,1)                 
                    If $bit=1 Then 
                        _GUIScrollBars_ShowScrollBar($hGUI,$SB_VERT,True)
                    Else
                        _GUIScrollBars_ShowScrollBar($hGUI,$SB_VERT,False)
                    EndIf
            Case GUICtrlRead($Tab1, 1) = $TabSheet2
                If Not $buffer Then
                    $buffer = True
                    GUISetState(@SW_SHOW, $hGUI)                    
                    ControlFocus($Form1,"",$Tab1)                   
                EndIf
            Case GUICtrlRead($Tab1, 1) = $TabSheet1
                If $buffer Then
                    $buffer = False
                    GUISetState(@SW_HIDE, $hGUI)                    
                    ControlFocus($Form1,"",$Tab1)                   
                EndIf                   
        EndSelect
    WEnd
    Exit
EndFunc

Func WM_VSCROLL($hWnd, $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

    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
    $Min = DllStructGetData($tSCROLLINFO, "nMin")
    $Max = DllStructGetData($tSCROLLINFO, "nMax")
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    $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

    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)

    $Pos = DllStructGetData($tSCROLLINFO, "nPos")

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

    Return $GUI_RUNDEFMSG

EndFunc

Func WM_MOVE($hWndGUI, $MsgID, $WParam, $LParam) 
    If $hWndGUI = $Form1 Then 
        $a_pos = WinGetPos($Form1) 
        WinMove($hGUI, "", $a_pos[0]+9,$a_pos[1]+51)
    Else 
    EndIf 
EndFunc
Edited by hunt
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...