Jump to content

Display problem with <GUIScrollBars_Ex.au3>


Faalamva
 Share

Recommended Posts

Hi,

I'm having an annoying display bug, I think I've found it (it's related to the use of scrollbars), but I'm unable to understand and fix it properly, so I hope you guys will enlighten me ! ^_^

I have stripped my original program down to a minimal 80-lines version. It is available here for download : http://sagel.free.fr/BugTest.zip

(just change the value of $Folder in line 4).

The purpose of this program is very simple : select a series of stamp numbers in the list on the left, and their corresponding images will be displayed on the right.

Normally, all stamps should be properly displayed with a 15 pixel interval between them, however you will see that it's not always the case. The bug can be reproduced like this :

  1. Click on the first series (the spacing is incorrect : the space between image 1 and image 2 is too thin)
  2. Click again on the first series (the spacing is now correct)
  3. Click on the second series (the spacing is incorrect : the space between image 1 and image 2 is too large)
  4. Click again on the second series (the spacing is now correct)

If I comment the lines 74 and 75 (_GUIScrollBars instructions) then the spacing is correctly displayed, but of course I can't scroll the second series properly anymore...

What's more, I'd like to get rid of that annoying horizontal scrollbar. I don't need it, and I'm fairly sure this is the cause of my problem. I need only the vertical scrollbar, because as you can see, all the images (whatever their original size) are proportionally reduced to a 360-pixel width for display.

Thank you ! :)

Edited by Faalamva
Link to comment
Share on other sites

Yeah that's weird but I'm not totally surprised. My screen resolution is 1920x1080, is it the same for you ? I suspect that the behaviour might change if the resolution is different because I've had a correct behaviour when changing the GUI size (parent and child).

I'm 99% sure this problem comes from the horizontal scrollbar being triggered for whatever reason. But I'll try your suggestion and let you know.

EDIT :

Ok, with this suggestion, it works indeed (adding the third line in this portion of code) :

_GUIScrollBars_Init($RightChildGUI)
_GUIScrollBars_Generate($RightChildGUI, 0, $RightImageYPos[$NbReferenceImages] + $RightImageHeight[$NbReferenceImages])
_GUIScrollBars_ShowScrollBar($RightChildGUI, $SB_HORZ, False)

But I'm still surprised that I actually have to force the horizontal scrollbar to be hidden. What's more, the horizontal scrollbar only appears with the first series (click 1 and 2) but doesn't appear at all with the second series, although all images are supposed to be displayed with the same width. What I mean is that no horizontal scrollbar should ever be needed, so I don't understand what makes the library think it has to show it eventually.

Anyway, for now I can consider that this is a decent fix, thank you !

Edited by Faalamva
Link to comment
Share on other sites

As I said before, for me your script worked nice on the first try, meaning : no H scrollbar with both series, an empty V scrollbar with the first serie, a working V scrollbar with the 2nd one, and correct spacing between images on first try
I'm 1920x1080 too but I'm running XP, so maybe it has something to do with the way Windows deals with scrollbars
I suggest you have a look inside the GUIScrollbars_Ex.au3 file and read carefully the 'Remarks' field for _GUIScrollbars_Generate, so you (maybe...) could play with the returned correction factors and the $fBefore param or try GUICtrlResizing($GUI_DOCKALL) to fix the pics in place

Edited by mikell
Link to comment
Share on other sites

  • Moderators

Faalamva,

I am the author of the ScrollbarsEx UDF - if you use the UDF correctly, you will get no horizontal scrollbars.

Your problem is calling _GUIScrollBars_Init  (which shows both vertical and horizontal scrollbars) as well as _GUIScrollBars_Generate (which does all of the scrollbar generation for you). As you have set the $iH_Scroll parameter to 0 when calling _GUIScrollBars_Generate, you will not get a horizontal scrollbar - it is only you calling _GUIScrollBars_Init beforehand that produces it.

So all you need is this:

Next
    ; Create scrollbars
    _GUIScrollBars_Generate($RightChildGUI, 0, $RightImageYPos[$NbReferenceImages] + $RightImageHeight[$NbReferenceImages])
Else
    $NbReferenceImages = 0
EndIf

and your script works as you wish.

Although rather than regenerating the scrollbars each time. you should really be using the _GUIScrollbars_Size UDF in this case to adjust the scrollbars according to the size of the content. However, as the script works I would suggest leaving well alone.

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

Faalamva,

Here is the script rewritten to use _GUIScrollBars_Size:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <GUIScrollBars_Size.au3>

Global $Folder = @ScriptDir & "\"
Global $NbReferenceImages = 0
Global $RightImage[10]
Global $RightImageXPos[10]
Global $RightImageYPos[10]
Global $RightImageWidth[10]
Global $RightImageHeight[10]

_GDIPlus_Startup()

; Create ParentGUI

$ParentGUI = GUICreate("", 1000, 1000)
GUISetBkColor("0xBBBBBB", $ParentGUI)
GUISetState(@SW_SHOW, $ParentGUI)

; Create List
$List = GUICtrlCreateList("", 15, 15, 500, 100)
GUICtrlSetFont($List, 10)
GUICtrlSetData($List, "146+147")
GUICtrlSetData($List, "148+149+150+151+152+153+154+155")

$iRightChildWidth = 438
$iRightChildHeight = 935

; Create RightChildGUI

$RightChildGUI = GUICreate("", $iRightChildWidth, $iRightChildHeight, 542, 15, BitOr($WS_POPUP, $WS_BORDER), $WS_EX_MDICHILD, $ParentGUI)
GUISetBkColor("0xDDDDDD", $RightChildGUI)
GUISetState(@SW_SHOW, $RightChildGUI)

; initialise scrollbars - only show vert

_GUIScrollBars_Init($RightChildGUI)
_GUIScrollBars_ShowScrollBar($RightChildGUI, $SB_VERT, True)
_GUIScrollBars_ShowScrollBar($RightChildGUI, $SB_HORZ, False)
_GUIScrollBars_SetScrollInfoPage($RightChildGUI, $SB_VERT, $iRightChildHeight)
_GUIScrollBars_SetScrollInfoMax($RightChildGUI, $SB_VERT, $iRightChildHeight)

; Register Vscroll message
GUIRegisterMsg($WM_VSCROLL, "_Scrollbars_WM_VSCROLL")

;--------------------
; Main event listener
;--------------------
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            ; Shut down application
            _GDIPlus_Shutdown()
            Exit
        Case $List
            ; Display images of the selected list in RightChildGUI

            UpdateRightChildGUI()
    EndSwitch

WEnd



;----------------------------------------------------------------
; Update Right Child GUI to display images of the selected images
;----------------------------------------------------------------
Func UpdateRightChildGUI()
    GUISetState(@SW_LOCK, $RightChildGUI)

    ; Delete existing images in RightChildGUI

    For $i = 1 To $NbReferenceImages

        GUICtrlDelete($RightImage[$i])
    Next

    ; Display images of the selected series
    $SelectedResult = GUICtrlRead($List)
    If $SelectedResult <> "" Then
        $Tokens = StringSplit($SelectedResult, "+")
        $NbReferenceImages = $Tokens[0]
        For $i = 1 To $NbReferenceImages

            ; Get image size
            $CurrentImage = _GDIPlus_ImageLoadFromFile($Folder & $Tokens[$i] & ".jpg")
            $RightImageWidth[$i] = 360
            $RightImageHeight[$i] = _GDIPlus_ImageGetHeight($CurrentImage) * 360 / _GDIPlus_ImageGetWidth($CurrentImage)
            _GDIPlus_ImageDispose($CurrentImage)
            ; Resize and place image in right child GUI
            $RightImageXPos[$i] = 15
            $RightImageYPos[$i] = $RightImageYPos[$i - 1] + $RightImageHeight[$i - 1] + 15
            $RightImage[$i] = GUICtrlCreatePic($Folder & $Tokens[$i] & ".jpg", $RightImageXPos[$i], $RightImageYPos[$i], $RightImageWidth[$i], $RightImageHeight[$i])
        Next
        ; Get required size of scrollable area
        $iScrollheight = $RightImageYPos[$NbReferenceImages] + $RightImageHeight[$NbReferenceImages]
        ; Size scrollbars
        If $iScrollheight > $iRightChildHeight Then
            ; Show vert scrollbar
            _GUIScrollBars_ShowScrollBar($RightChildGUI, $SB_VERT, True)
            ; Set required parameters
            $aRet = _GUIScrollbars_Size(0, $iScrollheight, $iRightChildWidth, $iRightChildHeight)
            _GUIScrollBars_SetScrollInfoPage($RightChildGUI, $SB_VERT, $aRet[2])
            _GUIScrollBars_SetScrollInfoMax($RightChildGUI, $SB_VERT, $aRet[3])
        Else
            ; Hide very scrollbar
            _GUIScrollBars_ShowScrollBar($RightChildGUI, $SB_VERT, False)
        EndIf



    Else
        $NbReferenceImages = 0
    EndIf



    GUISetState(@SW_UNLOCK, $RightChildGUI)
EndFunc



Func _Scrollbars_WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)

    #forceref $Msg, $wParam, $lParam

    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $iIndex = -1, $yChar, $yPos

    Local $Min, $Max, $Page, $Pos, $TrackPos



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

        EndIf

    Next
    If $iIndex = -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
            DllStructSetData($tSCROLLINFO, "nPos", $Min)
        Case $SB_BOTTOM
            DllStructSetData($tSCROLLINFO, "nPos", $Max)
        Case $SB_LINEUP
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
        Case $SB_LINEDOWN
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
        Case $SB_PAGEUP
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
        Case $SB_PAGEDOWN
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
        Case $SB_THUMBTRACK
            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   ;==>_Scrollbars_WM_VSCROLL

Please ask if you have any questions.


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