Kip Posted September 3, 2008 Posted September 3, 2008 (edited) 4th UDF this week, 2nd one today Scrollbars always have been a pain in the ass.Not anymore. I created these four functions that does it all. Even the more advanced stuff.Scrollbar_Create($hWnd, $iBar, $iMax) Scrollbar_Scroll($hWnd, $iBar, $iPos) Scrollbar_GetPos($hWnd, $iBar) Scrollbar_Step($iStep, $hWnd=0, $iBar=0)Ok, so... an example to show how easy it is:#include<WindowsConstants.au3> #include<GuiconstantsEx.au3> #Include <GUIScroll.au3> $GUI = GUICreate("Test",400,300); The visible part of the window is 300 pixels high Scrollbar_Create($GUI, $SB_VERT, 700); But the actual window is 700 pixels high Scrollbar_Step(20, $GUI, $SB_VERT); Scrolls per 20 pixels. If not set the default is 1 (smooth scrolling) GUICtrlCreateButton("hello",50,200,120,23) GUISetState() While 1 $iScrollPos = Scrollbar_GetPos($GUI, $SB_VERT) ; MaxScrollPos = ActualWindowHeight - VisibleWindowHeight ; So in this case that would be: ; MaxScrollPos = 700 - 300 ; $iScrollPos can only be a value between 0 and 400 (this is just in this script) ConsoleWrite($iScrollPos&@CRLF) If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit WEndDont freak out. Just read the comments and you'll be all fine.I made a nice drawing to make it more clear:The dark grey part is ofcourse not visible part.Enjoy. GUIScroll.au3 Edited September 3, 2008 by Kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
James Posted September 3, 2008 Posted September 3, 2008 Bit like Garys! Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
WeMartiansAreFriendly Posted September 3, 2008 Posted September 3, 2008 Hmm.. Don't stop now There's an issue with this style, the button jumps when you resize ;http://www.autoitscript.com/forum/index.php?showtopic=79684 #include<WindowsConstants.au3> #include<GuiconstantsEx.au3> #Include <GUIScroll.au3> $GUI = GUICreate("Test",400,300, -1, -1, _ BitOR($WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW), _ $WS_EX_ACCEPTFILES); The visible part of the window is 300 pixels high Scrollbar_Create($GUI, $SB_VERT, 700); But the actual window is 700 pixels high Scrollbar_Step(20, $GUI, $SB_VERT); Scrolls per 20 pixels. If not set the default is 1 (smooth scrolling) GUICtrlCreateButton("hello",50,200,120,23) GUISetState() While 1 $iScrollPos = Scrollbar_GetPos($GUI, $SB_VERT) ; MaxScrollPos = ActualWindowHeight - VisibleWindowHeight ; So in this case that would be: ; MaxScrollPos = 700 - 300 ; $iScrollPos can only be a value between 0 and 400 (this is just in this script) ConsoleWrite($iScrollPos&@CRLF) If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit WEnd Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
ResNullius Posted September 4, 2008 Posted September 4, 2008 Hmm.. Don't stop now There's an issue with this style, the button jumps when you resize TRY:$GUI = GUICreate("Test",400,300, -1, -1, _BitOR($WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_CLIPCHILDREN), _$WS_EX_ACCEPTFILES); The visible part of the window is 300 pixels high
Kip Posted September 4, 2008 Author Posted September 4, 2008 Hmm.. Don't stop nowStop what? MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
WeMartiansAreFriendly Posted September 4, 2008 Posted September 4, 2008 Stop what?Posting UDF's Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
Kip Posted September 4, 2008 Author Posted September 4, 2008 lol MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
wraithdu Posted September 4, 2008 Posted September 4, 2008 mrRevoked's bug is still there even with $WS_CLIPCHILDREN. Try his script, then scroll down, then resize the window. The button jumps position.
ResNullius Posted September 4, 2008 Posted September 4, 2008 mrRevoked's bug is still there even with $WS_CLIPCHILDREN. Try his script, then scroll down, then resize the window. The button jumps position.Oh, I see now. I thought originally mrRevoked was referring to the jitter/flicker on resizing.Guess we'll have to wait for Kip to look at it.
Kip Posted September 4, 2008 Author Posted September 4, 2008 Ah, I know whats going on. Just hang on. MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
Kip Posted September 4, 2008 Author Posted September 4, 2008 Add this to your gui: GUIRegisterMsg($WM_SIZE, "WM_SIZE") And this to the end of your script: expandcollapse popupFunc WM_SIZE($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $wParam Local $index = -1, $yChar, $xChar, $xClientMax, $xClient, $yClient, $ivMax For $x = 0 To UBound($aSB_WindowInfo) - 1 If $aSB_WindowInfo[$x][0] = $hWnd Then $index = $x $xClientMax = $aSB_WindowInfo[$index][1] $xChar = $aSB_WindowInfo[$index][2] $yChar = $aSB_WindowInfo[$index][3] $ivMax = $aSB_WindowInfo[$index][7] ExitLoop EndIf Next If $index = -1 Then Return 0 Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO) ; Retrieve the dimensions of the client area. $xClient = BitAND($lParam, 0x0000FFFF) $yClient = BitShift($lParam, 16) $aSB_WindowInfo[$index][4] = $xClient $aSB_WindowInfo[$index][5] = $yClient ; Set the vertical scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) DllStructSetData($tSCROLLINFO, "nMax", $ivMax) DllStructSetData($tSCROLLINFO, "nPage", $yClient / $yChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) ; Set the horizontal scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar) DllStructSetData($tSCROLLINFO, "nPage", $xClient / $xChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
WeMartiansAreFriendly Posted September 5, 2008 Posted September 5, 2008 That fixed it, thanks. Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
eson Posted July 23, 2009 Posted July 23, 2009 Kip, Is it possible to include scroll bar moviment with the mouse wheel? Thank you, eson.
Authenticity Posted July 24, 2009 Posted July 24, 2009 expandcollapse popup#include<WindowsConstants.au3> #include<GuiconstantsEx.au3> #include <WinAPI.au3> #include "GUIScroll.au3" If Not IsDeclared('WM_MOUSEWHEEL') Then $WM_MOUSEWHEEL = 0x020A Global Const $iStep = 20 $GUI = GUICreate("Test",400,300); The visible part of the window is 300 pixels high For $i = 1 To 20 For $j = 1 To 20 GUICtrlCreateButton(($i-1)*20+$j, 10+85*($i-1), 10+30*($j-1), 75, 25) Next Next Scrollbar_Create($GUI, $SB_HORZ, 85*19+75) Scrollbar_Step($iStep, $GUI, $SB_HORZ) Scrollbar_Create($GUI, $SB_VERT, 30*19+25) Scrollbar_Step($iStep, $GUI, $SB_VERT) GUISetState() GUIRegisterMsg($WM_MOUSEWHEEL, 'WM_MOUSEWHEEL') While 1 $iScrollPos = Scrollbar_GetPos($GUI, $SB_VERT) ; MaxScrollPos = ActualWindowHeight - VisibleWindowHeight ; So in this case that would be: ; MaxScrollPos = 700 - 300 ; $iScrollPos can only be a value between 0 and 400 (this is just in this script) If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit WEnd Func WM_MOUSEWHEEL($hWnd, $iMsg, $iwParam, $ilParam) Local $iDelta = BitShift($iwParam, 16) If $iDelta > 0 Then _SendMessage($GUI, $WM_VSCROLL, $SB_LINEUP) Else _SendMessage($GUI, $WM_VSCROLL, $SB_LINEDOWN) EndIf Return 'GUI_RUNDEFMSG' EndFunc
oo0oo Posted September 19, 2010 Posted September 19, 2010 Nice! Support mousewheel? and Scrollbar_Delete?
martin Posted April 29, 2011 Posted April 29, 2011 Add this to your gui: GUIRegisterMsg($WM_SIZE, "WM_SIZE") And this to the end of your script: expandcollapse popupFunc WM_SIZE($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $wParam Local $index = -1, $yChar, $xChar, $xClientMax, $xClient, $yClient, $ivMax For $x = 0 To UBound($aSB_WindowInfo) - 1 If $aSB_WindowInfo[$x][0] = $hWnd Then $index = $x $xClientMax = $aSB_WindowInfo[$index][1] $xChar = $aSB_WindowInfo[$index][2] $yChar = $aSB_WindowInfo[$index][3] $ivMax = $aSB_WindowInfo[$index][7] ExitLoop EndIf Next If $index = -1 Then Return 0 Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO) ; Retrieve the dimensions of the client area. $xClient = BitAND($lParam, 0x0000FFFF) $yClient = BitShift($lParam, 16) $aSB_WindowInfo[$index][4] = $xClient $aSB_WindowInfo[$index][5] = $yClient ; Set the vertical scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) DllStructSetData($tSCROLLINFO, "nMax", $ivMax) DllStructSetData($tSCROLLINFO, "nPage", $yClient / $yChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) ; Set the horizontal scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar) DllStructSetData($tSCROLLINFO, "nPage", $xClient / $xChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE Kip, Have you got a fix for a problem with your solution. When the parent gui is resized the size of the scrollbar thumbs do not grow or shrink and scrolling can go beyond the correct range. 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.
Kip Posted April 29, 2011 Author Posted April 29, 2011 Kip,Have you got a fix for a problem with your solution. When the parent gui is resized the size of the scrollbar thumbs do not grow or shrink and scrolling can go beyond the correct range.I see your problem, but a simple fix can't be written.I'd probably have to rewrite the whole UDF. MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
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