Jump to content

Scroll UDF. Much easier than the _GUIScrollBars UDF.


Kip
 Share

Recommended Posts

4th UDF this week, 2nd one today ;)

Scrollbars always have been a pain in the ass.

Not anymore. ;)

I created these four functions that does it all. Even the more advanced stuff.

Scrollbar_Create($hWnd, $iBar, $iMax)
Scrollbar_Scroll($hWnd, $iBar, $iPos)
Scrollbar_GetPos($hWnd, $iBar)
Scrollbar_Step($iStep, $hWnd=0, $iBar=0)

Ok, so... an example to show how easy it is:

#include<WindowsConstants.au3>
#include<GuiconstantsEx.au3>
#Include <GUIScroll.au3>

$GUI = GUICreate("Test",400,300); The visible part of the window is 300 pixels high
    
    Scrollbar_Create($GUI, $SB_VERT, 700); But the actual window is 700 pixels high
    
    Scrollbar_Step(20, $GUI, $SB_VERT); Scrolls per 20 pixels. If not set the default is 1 (smooth scrolling)
    
    GUICtrlCreateButton("hello",50,200,120,23)
    
GUISetState()



While 1
    
    $iScrollPos = Scrollbar_GetPos($GUI, $SB_VERT)
    
 ; MaxScrollPos = ActualWindowHeight - VisibleWindowHeight
    
 ; So in this case that would be:
 ; MaxScrollPos = 700 - 300
    
 ; $iScrollPos can only be a value between 0 and 400 (this is just in this script)
    
    ConsoleWrite($iScrollPos&@CRLF)
    
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd

Dont freak out. Just read the comments and you'll be all fine.

I made a nice drawing to make it more clear:

Posted Image

The dark grey part is ofcourse not visible part.

Enjoy. :D

GUIScroll.au3

Edited by Kip
Link to comment
Share on other sites

Hmm.. Don't stop now :D

There's an issue with this style, the button jumps when you resize ;)

;http://www.autoitscript.com/forum/index.php?showtopic=79684

#include<WindowsConstants.au3>
#include<GuiconstantsEx.au3>
#Include <GUIScroll.au3>

$GUI = GUICreate("Test",400,300, -1, -1, _
BitOR($WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW), _
$WS_EX_ACCEPTFILES); The visible part of the window is 300 pixels high
    
    Scrollbar_Create($GUI, $SB_VERT, 700); But the actual window is 700 pixels high
    
    Scrollbar_Step(20, $GUI, $SB_VERT); Scrolls per 20 pixels. If not set the default is 1 (smooth scrolling)
    
    GUICtrlCreateButton("hello",50,200,120,23)
    
GUISetState()



While 1
    
    $iScrollPos = Scrollbar_GetPos($GUI, $SB_VERT)
    
; MaxScrollPos = ActualWindowHeight - VisibleWindowHeight
    
; So in this case that would be:
; MaxScrollPos = 700 - 300
    
; $iScrollPos can only be a value between 0 and 400 (this is just in this script)
    
    ConsoleWrite($iScrollPos&@CRLF)
    
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd
Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
Link to comment
Share on other sites

Hmm.. Don't stop now :D

There's an issue with this style, the button jumps when you resize ;)

TRY:

$GUI = GUICreate("Test",400,300, -1, -1, _

BitOR($WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_CLIPCHILDREN), _

$WS_EX_ACCEPTFILES); The visible part of the window is 300 pixels high

Link to comment
Share on other sites

mrRevoked's bug is still there even with $WS_CLIPCHILDREN. Try his script, then scroll down, then resize the window. The button jumps position.

Oh, I see now.

I thought originally mrRevoked was referring to the jitter/flicker on resizing.

Guess we'll have to wait for Kip to look at it.

Link to comment
Share on other sites

Add this to your gui:

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

And this to the end of your script:

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
Link to comment
Share on other sites

  • 10 months later...

#include<WindowsConstants.au3>
#include<GuiconstantsEx.au3>
#include <WinAPI.au3>
#include "GUIScroll.au3"

If Not IsDeclared('WM_MOUSEWHEEL') Then $WM_MOUSEWHEEL = 0x020A
Global Const $iStep = 20

$GUI = GUICreate("Test",400,300); The visible part of the window is 300 pixels high
    
    
For $i = 1 To 20
    For $j = 1 To 20
        GUICtrlCreateButton(($i-1)*20+$j, 10+85*($i-1), 10+30*($j-1), 75, 25)
    Next
Next

Scrollbar_Create($GUI, $SB_HORZ, 85*19+75)
Scrollbar_Step($iStep, $GUI, $SB_HORZ)
Scrollbar_Create($GUI, $SB_VERT, 30*19+25)
Scrollbar_Step($iStep, $GUI, $SB_VERT)

GUISetState()
GUIRegisterMsg($WM_MOUSEWHEEL, 'WM_MOUSEWHEEL')



While 1
    
    $iScrollPos = Scrollbar_GetPos($GUI, $SB_VERT)
    
 ; MaxScrollPos = ActualWindowHeight - VisibleWindowHeight
    
 ; So in this case that would be:
 ; MaxScrollPos = 700 - 300
    
 ; $iScrollPos can only be a value between 0 and 400 (this is just in this script)
    
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd

Func WM_MOUSEWHEEL($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iDelta = BitShift($iwParam, 16)

    If $iDelta > 0 Then
        _SendMessage($GUI, $WM_VSCROLL, $SB_LINEUP)
    Else
        _SendMessage($GUI, $WM_VSCROLL, $SB_LINEDOWN)
    EndIf
    
    Return 'GUI_RUNDEFMSG'
EndFunc

Link to comment
Share on other sites

  • 5 months later...
  • 8 months later...
  • 7 months later...

Add this to your gui:

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

And this to the end of your script:

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

Kip,

Have you got a fix for a problem with your solution. When the parent gui is resized the size of the scrollbar thumbs do not grow or shrink and scrolling can go beyond the correct range.

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

Kip,

Have you got a fix for a problem with your solution. When the parent gui is resized the size of the scrollbar thumbs do not grow or shrink and scrolling can go beyond the correct range.

I see your problem, but a simple fix can't be written.

I'd probably have to rewrite the whole UDF.

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