Jump to content

Add mousewheel-scroll to scrollbar


 Share

Recommended Posts

Hello! Thanks everyone for making this scripting language what it is!

After stalking this awesome forum for some years i've come to ask for help! :)

I'm trying to make my childgui be more easy to navigate by adding scrollwheel-functionality to it by this code. 

#include <WindowsConstants.au3>
#include <GuiScrollBars.au3>
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>


$gp = GUICreate("parent")
$gc = GUICreate("child",293,175,13,32,BitOr($WS_CHILD, $WS_VSCROLL),-1,$gp)
$b1 = GUICtrlCreateButton("1",30,30)
$b2 = GUICtrlCreateButton("2",50,330)
GUISetBkColor(0x606060,$gc)
GUISwitch($gp)

GUISetState(@SW_SHOW,$gp)
GUISetState(@SW_SHOW,$gc)

GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")

_GUIScrollBars_Init($gc)
_GUIScrollBars_ShowScrollBar($gc,$SB_HORZ ,False)


while 1
 $gm =    GUIGetMsg()
    switch $gm
        case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam, $lParam
    Local $iScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $iIndex = -1, $iCharY, $iPosY
    Local $iMin, $iMax, $iPage, $iPos, $iTrackPos

    For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
        If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
            $iIndex = $x
            $iCharY = $__g_aSB_WindowInfo[$iIndex][3]
            ExitLoop
        EndIf
    Next
    If $iIndex = -1 Then Return 0

    ; Get all the vertial scroll bar information
    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
    $iMin = DllStructGetData($tSCROLLINFO, "nMin")
    $iMax = DllStructGetData($tSCROLLINFO, "nMax")
    $iPage = DllStructGetData($tSCROLLINFO, "nPage")
    ; Save the position for comparison later on
    $iPosY = DllStructGetData($tSCROLLINFO, "nPos")
    $iPos = $iPosY
    $iTrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")

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

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

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

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

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

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

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

        case  $MOUSE_WHEEL_UP; me trying to use mousewheel
            DllStructSetData($tSCROLLINFO, "nPos", $iPos - 1)

            ConsoleWrite("success?")
        case  $MOUSE_WHEEL_DOWN; me trying to use mousewheel
            DllStructSetData($tSCROLLINFO, "nPos", $iPos + 1)

            ConsoleWrite("success?")
        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
    $iPos = DllStructGetData($tSCROLLINFO, "nPos")

    If ($iPos <> $iPosY) Then
        _GUIScrollBars_ScrollWindow($hWnd, 0, $iCharY * ($iPosY - $iPos))
        $iPosY = $iPos
    EndIf

EndFunc   ;==>WM_VSCROLL

I've  tried making it work by adding ..

 

case  $MOUSE_WHEEL_UP; me trying to use mousewheel
            DllStructSetData($tSCROLLINFO, "nPos", $iPos - 1)

            ConsoleWrite("success?")
        case  $MOUSE_WHEEL_DOWN; me trying to use mousewheel
            DllStructSetData($tSCROLLINFO, "nPos", $iPos + 1)

            ConsoleWrite("success?")

..to the wm, but some how im not geting it to do anything, and either are the "standard"  WM_VSCROLL($SB_TOP,$SB_BOTTOM,$SB_LINEUP,$SB_LINEDOWN) actions.

Do someone have an idea what im doing wrong?

Thanks for possible assistance!

 

 

 

 

Link to comment
Share on other sites

So I'm not really sure if I'm not just making everything very messy, but i found this "RegisterRawInputDevices" script in the helpfiles which i'm not sure i follow compleatly to be frank, but it seams to at least generate a activation on scrolling which could possibly be used perhaps with a dummy, not shure how though..

But It does make the scroll work nasty as it is.. ^^

 

If anyone have an Idea of doing this in a better way or maybe a better way of using the wm_input together with wm_vscroll, i would deeply appreciate it

#include <WindowsConstants.au3>
#include <GuiScrollBars.au3>
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>

#include <WinAPISys.au3>

Global $gp = GUICreate("parent")
global $gc = GUICreate("child",293,175,13,32,BitOr($WS_CHILD, $WS_VSCROLL),-1,$gp)
$b1 = GUICtrlCreateButton("1",30,30)
$b2 = GUICtrlCreateButton("2",50,330)
GUISetBkColor(0x606060,$gc)
GUISwitch($gp)

$scrollwheelDummy=GUICtrlCreateDummy ()

GUISetState(@SW_SHOW,$gp)
GUISetState(@SW_SHOW,$gc)

GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")

GUIRegisterMsg($WM_INPUT, 'WM_INPUT')

Local $tRID = DllStructCreate($tagRAWINPUTDEVICE)
DllStructSetData($tRID, 'UsagePage', 0x01) ; Generic Desktop Controls
DllStructSetData($tRID, 'Usage', 0x02) ; Mouse
DllStructSetData($tRID, 'hTarget', $gc)
_WinAPI_RegisterRawInputDevices($tRID)

_GUIScrollBars_Init($gc)
_GUIScrollBars_ShowScrollBar($gc,$SB_HORZ ,False)


while 1
 $gm = GUIGetMsg()
    switch $gm
        case $GUI_EVENT_CLOSE
            Exit




    EndSwitch
WEnd





Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam, $lParam
    Local $iScrollCode = BitAND($wParam, 0x0000FFFF)
    Local  $iIndex = -1, $iCharY, $iPosY
    local $iMin, $iMax, $iPage, $iTrackPos
    local  $iPos


    For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
        If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
            $iIndex = $x
            $iCharY = $__g_aSB_WindowInfo[$iIndex][3]
            ExitLoop
        EndIf
    Next
    If $iIndex = -1 Then Return 0

    ; Get all the vertial scroll bar information
    local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
    $iMin = DllStructGetData($tSCROLLINFO, "nMin")
    $iMax = DllStructGetData($tSCROLLINFO, "nMax")
    $iPage = DllStructGetData($tSCROLLINFO, "nPage")
    ; Save the position for comparison later on
    $iPosY = DllStructGetData($tSCROLLINFO, "nPos")
    $iPos = $iPosY
    $iTrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")



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

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

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

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

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

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


    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
    $iPos = DllStructGetData($tSCROLLINFO, "nPos")

    If ($iPos <> $iPosY) Then
        _GUIScrollBars_ScrollWindow($hWnd, 0, $iCharY * ($iPosY - $iPos))
        $iPosY = $iPos
    EndIf

EndFunc   ;==>WM_VSCROLL


Func WM_INPUT($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam
    
    Local  $iIndex = -1, $iCharY, $iPosY,$iPos

    For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
        If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
            $iIndex = $x
            $iCharY = $__g_aSB_WindowInfo[$iIndex][3]
            ExitLoop
        EndIf
    Next

    ; Get all the vertial scroll bar information
    local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
    ; Save the position for comparison later on
    $iPosY = DllStructGetData($tSCROLLINFO, "nPos")
    $iPos = $iPosY

    Switch $hWnd
        Case $gc
            Local $tRIM = DllStructCreate($tagRAWINPUTMOUSE)
            If _WinAPI_GetRawInputData($lParam, $tRIM, DllStructGetSize($tRIM), $RID_INPUT) Then

                $iFlags = DllStructGetData($tRIM, 'ButtonFlags')

                If BitAND($iFlags, $RI_MOUSE_WHEEL) Then


                    $aData = _WinAPI_WordToShort(DllStructGetData($tRIM, 'ButtonData'));here i get some activation from the

                    If $aData>0 Then
                    DllStructSetData($tSCROLLINFO, "nPos", $iPos - 1)
                    ElseIf $aData<0 Then
                    DllStructSetData($tSCROLLINFO, "nPos", $iPos + 1)
                    EndIf


                Else
                $aData = ''
                EndIf

            EndIf
    EndSwitch

    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    ;// If the position has changed, scroll the window and update it
    $iPos = DllStructGetData($tSCROLLINFO, "nPos")
    If ($iPos <> $iPosY) Then
        _GUIScrollBars_ScrollWindow($hWnd, 0, $iCharY * ($iPosY - $iPos))
        $iPosY = $iPos
    EndIf


EndFunc   ;==>WM_INPUT

 

Edited by eken134
Link to comment
Share on other sites

  • Moderators

eken134,

My  GUIScrollbar_Ex UDF (the link is in my sig) allows for easy scrollbar creation - and it also honours the mousewheel (in both senses). Why not take a look?

If you want to do it yourself, then you need to register WM_MOUSEWHEEL and WM_MOUSEHWHEEL messages - the code in the handlers within UDF shows you how to do it.

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

  • Moderators

eken134,

Glad I could help, and have helped, you.

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