Faalamva Posted November 21, 2015 Posted November 21, 2015 (edited) 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 :Click on the first series (the spacing is incorrect : the space between image 1 and image 2 is too thin)Click again on the first series (the spacing is now correct)Click on the second series (the spacing is incorrect : the space between image 1 and image 2 is too large)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 November 21, 2015 by Faalamva
mikell Posted November 21, 2015 Posted November 21, 2015 Your script works nice for me with no bug ...For the horizontal scrollbar you might try this_GUIScrollBars_ShowScrollBar($RightChildGUI, $SB_HORZ, False)
Faalamva Posted November 21, 2015 Author Posted November 21, 2015 (edited) 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 November 21, 2015 by Faalamva
Faalamva Posted November 22, 2015 Author Posted November 22, 2015 I have added 4 screenshots in the ZIP file, corresponding to each click as described in my original post.You can now easily see what my display looks like after each click.
mikell Posted November 22, 2015 Posted November 22, 2015 (edited) 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 tryI'm 1920x1080 too but I'm running XP, so maybe it has something to do with the way Windows deals with scrollbarsI 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 November 22, 2015 by mikell
Faalamva Posted November 22, 2015 Author Posted November 22, 2015 Thank you for these new hints, I'll take a look eventually. I have tested your first fix in my main program and checked with a large set of series and clicking : everything's working as expected.
Moderators Melba23 Posted November 22, 2015 Moderators Posted November 22, 2015 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 EndIfand 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Moderators Melba23 Posted November 24, 2015 Moderators Posted November 24, 2015 Faalamva,Here is the script rewritten to use _GUIScrollBars_Size:expandcollapse popup#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_VSCROLLPlease ask if you have any questions.M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now