Jump to content

Scrollbars problem


Tukata
 Share

Recommended Posts

Hi

I created a GUI window inside a GUI window and then "GUICtrlCreatePic" in which I display images. Since some images are too big, I added scrollbars to the second GUI window and decreased it. I thought I will be able to scroll the big images (which now I can see only part of them) but I was wrong.

Here is the part of my script that does not work as I want.

I hope someone will give me an idea how to do it.

G=GUICreate("text", 400, 300, 100, 100, $WS_BORDER+$WS_EX_TOPMOST+ $WS_HSCROLL+$WS_VSCROLL)
$Pic = GUICtrlCreatePic($a, 0, 0, 400, 300)
GUICtrlSetImage($G, $hImage)
WinMove ($G, "text", 100, 100, 200, 200)
; at this stage I can see the top-left corner of the images (100x100) and the scrollbars, which had no effect.

Thank you

tukata

Edited by Tukata
Link to comment
Share on other sites

  • Moderators

Tukata,

This is modified from the _GUIScrollBars_Init example in the Help file. It works for me when I set $hImage to a valid filename.

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>

Opt("MustDeclareVars", 1)

Global $hImage = "Your_Image"

_Main()

Func _Main()
    Local $nFileMenu, $nExititem, $GUIMsg, $hGUI, $hPic

    $hGUI = GUICreate("ScrollBar Example", 300, 300)
    GUISetBkColor(0x88AABB)

    $hPic = GUICtrlCreatePic("", 0, 0, 400, 400)
    GUICtrlSetImage($hPic, $hImage)

    GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
    GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")

    GUISetState()

    _GUIScrollBars_Init($hGUI)

    While 1
        $GUIMsg = GUIGetMsg()

        Switch $GUIMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    Exit
EndFunc   ;==>_Main

Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)

    Local $index = -1, $xChar, $xPos
    Local $Min, $Max, $Page, $Pos, $TrackPos

    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $index = $x
            $xChar = $aSB_WindowInfo[$index][2]
            ExitLoop
        EndIf
    Next
    If $index = -1 Then Return 0

;~  ; Get all the horizontal scroll bar information
    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
    $Min = DllStructGetData($tSCROLLINFO, "nMin")
    $Max = DllStructGetData($tSCROLLINFO, "nMax")
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    ; Save the position for comparison later on
    $xPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $xPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
    #forceref $Min, $Max
    Switch $nScrollCode

        Case $SB_LINELEFT ; user clicked left arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)

        Case $SB_LINERIGHT ; user clicked right arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)

        Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)

        Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of 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_HORZ, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
    ;// If the position has changed, scroll the window and update it
    $Pos = DllStructGetData($tSCROLLINFO, "nPos")
    If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_HSCROLL

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

I hope it does what you want. :D

On a separate note, you are setting the styles for your GUI incorrectly.

GUICreate("text", 400, 300, 100, 100, $WS_BORDER+$WS_EX_TOPMOST+ $WS_HSCROLL+$WS_VSCROLL)

1. You are mixing up normal styles ($WS_BORDER, $WS_HSCROLL, $WS_VSCROLL) with an extended style ($WS_EX_TOPMOST). As the Help file states, you need normal and extended styles as separate parameters:

GUICreate ( "title" [, width [, height [, left [, top [, style [, exStyle [, parent]]]]]]] )

If you put a Style/exStyle in the wrong parameter you are very unlikely to get what you want and quite likely to get something you did not!

2. When you combine styles, it is always advisable to use BitOR rather than just adding the styles together. So use

BitOR($WS_BORDER, $WS_HSCROLL, $WS_VSCROLL)

and not

$WS_BORDER+$WS_HSCROLL+$WS_VSCROLL

The reason is that most styles are set using the individual bits of the total style value - by using normal addition you can inadvertantly set/unset one of these bits and so affect the overall result. Using BitOR ensures that only the correct bits are set and you get what you asked for!

Please ask if any of that is unclear. :huggles:

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

Melba23

Thank you for your kind reply.

Your example works perfect. I added image to it:

$hPic = GUICtrlCreatePic("", 0, 0, 2560, 1920)

and there is one peoblems: The image is not fully displayed. I assume a change has to be made to the way the scrollbars works, but I don't know how to make it that it will fit to any size of image.

I am very thankful to you for your explanation about the way how to use the different Styles.

Many thanks

tukata

Edited by Tukata
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...