Jump to content

Scroll not working


Kreatorul
 Share

Recommended Posts

Just a question (I could care less). If the $WS_VSCROLL is listed in the helpfile as a window style available, why isn't it supported?

search the help and you'll see what all it is used in.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Never finished code sample/snippet from June this year, maybe someone will find it usefull :lmao:

#include <GUIConstants.au3>

#cs
#define SB_HORZ             0
#define SB_VERT             1
#define SB_CTL              2
#define SB_BOTH             3

/*
 * Scroll Bar Commands
 */
#define SB_LINEUP           0
#define SB_LINELEFT         0
#define SB_LINEDOWN         1
#define SB_LINERIGHT        1
#define SB_PAGEUP           2
#define SB_PAGELEFT         2
#define SB_PAGEDOWN         3
#define SB_PAGERIGHT        3
#define SB_THUMBPOSITION    4
#define SB_THUMBTRACK       5
#define SB_TOP              6
#define SB_LEFT             6
#define SB_BOTTOM           7
#define SB_RIGHT            7
#define SB_ENDSCROLL        8
#ce

Global Const $WM_HSCROLL    = 0x0114
Global Const $WM_VSCROLL    = 0x0115

Dim $hWnd, $Msg, $wParam, $lParam, $x
Dim $yPos = 0

$hGUI       = GUICreate("My GUI", 400, 400, -1, -1, BitOr($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_VSCROLL))
GUISetBkColor(0x88AABB)
$nFileMenu  = GUICtrlCreateMenu("File")
$nExititem  = GUICtrlCreateMenuItem("Exit", $nFileMenu)
GUICtrlCreateLabel("Label", 10, 100, 200, 20)

$nInfoLbl   = GUICtrlCreateLabel("", 10, 10, 200, 20)
$nButton    = GUICtrlCreateButton("Check", 100, 50, 70, 20)

GUIRegisterMsg($WM_VSCROLL, "MY_WM_VSCROLL")

GUISetState()

While 1
    $GUIMsg = GUIGetMsg()
    
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE, $nExititem
            ExitLoop
    EndSwitch
WEnd

Exit

Func MY_WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
    $nScrollCode    = BitAnd($wParam, 0x0000FFFF)
    $nPos           = BitShift($wParam, 16)
    $hwndScrollBar  = $lParam
    
    GUICtrlSetData($nInfoLbl, $nScrollCode & ";" & $nPos & ";" & $hwndScrollBar & ";" & $yPos)
    
    $nDiff = 0
    Switch $nScrollCode
        Case 0
            $nDiff = 5
        Case 1
            $nDiff = -5
        Case 2
            $nDiff = 50
        Case 3
            $nDiff = -50
    EndSwitch

    $yPos = $yPos - $nDiff

    If $nScrollCode = 5 Then
        $yPos = $nPos
    EndIf
    
    DllCall("user32.dll", "int", "ScrollWindow", _
                            "hwnd", $hGUI, _
                            "int", 0, _
                            "int", $nDiff, _
                            "ptr", 0, _
                            "ptr", 0)
                            
    DllCall("user32.dll", "int", "SetScrollPos", _
                            "hwnd", $hGUI, _
                            "int", 1, _
                            "int", $yPos, _
                            "int", 1)
    
    #cs
    If (yInc = max(-yPos, min(yInc, yMax - yPos))) 
        { 
            yPos += yInc; 
            ScrollWindow(hwnd, 0, -yChar * yInc, 
                (CONST RECT *) NULL, (CONST RECT *) NULL, 
                (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE); 
            si.cbSize = sizeof(si); 
            si.fMask  = SIF_POS; 
            si.nPos   = YPos; 
            SetScrollInfo(hwnd, SB_VERT, &si, TRUE); 
            UpdateWindow (hwnd); 
        } 
    #ce
    return 0
        
EndFunc

Not much time at the moment to do more...

Greets

Holger

Link to comment
Share on other sites

@Holger - Works nicely! Just one small addition to scrolling function to limit the scrolling

Func MY_WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
    $nScrollCode    = BitAnd($wParam, 0x0000FFFF)
    $nPos        = BitShift($wParam, 16)
    $hwndScrollBar  = $lParam
   
    GUICtrlSetData($nInfoLbl, $nScrollCode & ";" & $nPos & ";" & $hwndScrollBar & ";" & $yPos)
   
    $nDiff = 0
    Switch $nScrollCode
        Case 0
            $nDiff = 5
        Case 1
            $nDiff = -5
        Case 2
            $nDiff = 50
        Case 3
            $nDiff = -50
    EndSwitch

    $yPos = $yPos - $nDiff
;#########added to limit scrolling
    if $yPos < 0 then 
        $yPos = 0
        $nDiff = 0
    EndIf
    
    if $ypos > 100 Then
        $yPos = 100
        $nDiff = 0
    EndIf
;######end of added to limit scrolling
    
    

    If $nScrollCode = 5 Then
        $yPos = $nPos
    EndIf
   
    DllCall("user32.dll", "int", "ScrollWindow", _
                            "hwnd", $hGUI, _
                            "int", 0, _
                            "int", $nDiff, _
                            "ptr", 0, _
                            "ptr", 0)
                           
    DllCall("user32.dll", "int", "SetScrollPos", _
                            "hwnd", $hGUI, _
                            "int", 1, _
                            "int", $yPos, _
                            "int", 1)
   
    #cs
    If (yInc = max(-yPos, min(yInc, yMax - yPos)))
        {
            yPos += yInc;
            ScrollWindow(hwnd, 0, -yChar * yInc,
                (CONST RECT *) NULL, (CONST RECT *) NULL,
                (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE);
            si.cbSize = sizeof(si);
            si.fMask  = SIF_POS;
            si.nPos   = YPos;
            SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
            UpdateWindow (hwnd);
        }
    #ce
    return 0
       
EndFunc
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

  • 1 year later...

I added WM_MOUSEWHEEL support:

#include <GUIConstants.au3>
#include <Misc.au3>

#cs
#define SB_HORZ             0
#define SB_VERT             1
#define SB_CTL              2
#define SB_BOTH             3

/*
 * Scroll Bar Commands
 */
#define SB_LINEUP           0
#define SB_LINELEFT         0
#define SB_LINEDOWN         1
#define SB_LINERIGHT        1
#define SB_PAGEUP           2
#define SB_PAGELEFT         2
#define SB_PAGEDOWN         3
#define SB_PAGERIGHT        3
#define SB_THUMBPOSITION    4
#define SB_THUMBTRACK       5
#define SB_TOP              6
#define SB_LEFT             6
#define SB_BOTTOM           7
#define SB_RIGHT            7
#define SB_ENDSCROLL        8
#ce

;~ Global Const $WM_HSCROLL    = 0x0114
;~ Global Const $WM_VSCROLL    = 0x0115
Const $WM_MOUSEWHEEL = 0x20A

Const $SB_LINEDOWN = 1
Const $SB_LINEUP = 0
Const $SB_NONE = 0x0

Dim $hWnd, $Msg, $wParam, $lParam, $x
Dim $yPos = 0

$hGUI      = GUICreate("My GUI", 400, 400, -1, -1, BitOr($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_VSCROLL))
GUISetBkColor(0x88AABB)
$nFileMenu  = GUICtrlCreateMenu("File")
$nExititem  = GUICtrlCreateMenuItem("Exit", $nFileMenu)
GUICtrlCreateLabel("Label", 10, 100, 200, 20)

$nInfoLbl   = GUICtrlCreateLabel("", 10, 10, 200, 20)
$nButton    = GUICtrlCreateButton("Check", 100, 50, 70, 20)

GUIRegisterMsg($WM_VSCROLL, "MY_WM_VSCROLL")
GUIRegisterMsg($WM_MOUSEWHEEL, "MY_WM_MOUSEWHEEL")

GUISetState()

While 1
    $GUIMsg = GUIGetMsg()
        Switch $GUIMsg
        Case $GUI_EVENT_CLOSE, $nExititem
            ExitLoop
    EndSwitch
WEnd

Exit

Func MY_WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
    $nScrollCode    = BitAnd($wParam, 0x0000FFFF)
    $nPos         = BitShift($wParam, 16)
    $hwndScrollBar  = $lParam
        GUICtrlSetData($nInfoLbl, $nScrollCode & ";" & $nPos & ";" & $hwndScrollBar & ";" & $yPos)
        $nDiff = 0
    Switch $nScrollCode
        Case 0
            $nDiff = 5
        Case 1
            $nDiff = -5
        Case 2
            $nDiff = 50
        Case 3
            $nDiff = -50
    EndSwitch

    $yPos = $yPos - $nDiff

;#########added to limit scrolling
    if $yPos < 0 then 
        $yPos = 0
        $nDiff = 0
    EndIf
        if $ypos > 100 Then
        $yPos = 100
        $nDiff = 0
    EndIf
;######end of added to limit scrolling

    If $nScrollCode = 5 Then
        $yPos = $nPos
    EndIf
        DllCall("user32.dll", "int", "ScrollWindow", _
                            "hwnd", $hGUI, _
                            "int", 0, _
                            "int", $nDiff, _
                            "ptr", 0, _
                            "ptr", 0)
                                DllCall("user32.dll", "int", "SetScrollPos", _
                            "hwnd", $hGUI, _
                            "int", 1, _
                            "int", $yPos, _
                            "int", 1)
        #cs
    If (yInc = max(-yPos, min(yInc, yMax - yPos))) 
        { 
            yPos += yInc; 
            ScrollWindow(hwnd, 0, -yChar * yInc, 
                (CONST RECT *) NULL, (CONST RECT *) NULL, 
                (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE); 
            si.cbSize = sizeof(si); 
            si.fMask  = SIF_POS; 
            si.nPos   = YPos; 
            SetScrollInfo(hwnd, SB_VERT, &si, TRUE); 
            UpdateWindow (hwnd); 
        } 
    #ce
    return 0
        EndFunc
 Func MY_WM_MOUSEWHEEL($hWnd, $Msg, $wParam, $lParam)
    $Keys           = BitAnd($wParam, 0x0000FFFF)
    $nDistance      = BitShift($wParam, 16)
;~     $XYPosition  = $lParam
        If $nDistance > 0 Then
        $sb_code = $SB_LINEUP
    Else
        $sb_code = $SB_LINEDOWN
    EndIf
            _SendMessage($hGUI, $WM_VSCROLL, $sb_code, 0)
EndFunc
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...