tpdietz Posted July 1, 2015 Share Posted July 1, 2015 (edited) I have been at this for a long time. I have an edit box that is being updated every second or so to indicate the progress of several background processes. The problem is, every time I update the edit box, the scroll bars are re-initialized back to the top. I am aware of the function that can scroll the edit down to the end, or to a specific caret. But I don't have a caret, so that isn't readily useful. Below I have attached a short example of my problem. You will find, that scrolling the bars up and down will eventually cause the edit box to be rendered improperly. It almost appears as if the box is being duplicated. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <ScrollBarConstants.au3> #include <WinAPI.au3> #include <GuiScrollBars.au3> Global $hGUI = GUICreate ("Example", 380, 360) Global $hEdit = GUICtrlCreateEdit ("", 10, 140, 360, 170, BitOR($WS_HSCROLL, $WS_VSCROLL)) _GUIScrollBars_Init(GUICtrlGetHandle($hEdit)) GUISetState (@SW_SHOW) While 1 $nMsg = GUIGetMsg () Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch sleep(100) updateEdit() WEnd Func updateEdit() Local $text = "" For $i = 0 To 100 $text &= "HELLO! " & $i & @CRLF Next Local $scrollbarVertPos = _GUIScrollBars_GetScrollPos ( GUICtrlGetHandle($hEdit), $SB_VERT ) GUICtrlSetData ($hEdit, $text) _GUIScrollBars_SetScrollInfoPos (GUICtrlGetHandle($hEdit), $SB_VERT, $scrollbarVertPos) EndFuncAny help would be greatly appreciated. Thank you. Edited July 1, 2015 by tpdietz Link to comment Share on other sites More sharing options...
BrewManNH Posted July 1, 2015 Share Posted July 1, 2015 You could do something like this.#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ScrollBarConstants.au3> #include <WinAPI.au3> #include <GuiScrollBars.au3> Global $hGUI = GUICreate("Example", 380, 360) Global $hEdit = GUICtrlCreateEdit("", 10, 140, 360, 170, BitOR($WS_HSCROLL, $WS_VSCROLL)) _GUIScrollBars_Init(GUICtrlGetHandle($hEdit)) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Sleep(100) updateEdit() WEnd Func updateEdit() Local $text = "" For $i = 0 To 100 $text &= "HELLO! " & $i & @CRLF Next ;~ Local $scrollbarVertPos = _GUIScrollBars_GetScrollPos(GUICtrlGetHandle($hEdit), $SB_VERT) GUICtrlSetData($hEdit, $text) ControlSend($hGUI, "", GUICtrlGetHandle($hEdit), "^{END}") ;~ _GUIScrollBars_SetScrollInfoPos(GUICtrlGetHandle($hEdit), $SB_VERT, $scrollbarVertPos) EndFunc ;==>updateEdit If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
tpdietz Posted July 1, 2015 Author Share Posted July 1, 2015 Thank you for your reply, BrewManNH. Please correct me if I'm wrong, but that appears to keep scrolling to the bottom/end of the edit box. If a user is scrolling through the edit and is somewhere in the middle, I would like the scroll bar to remain where they are looking (instead of jumping to the beginning or end). Sorry if this was not clear in my description. Thanks again for your reply. Link to comment Share on other sites More sharing options...
BrewManNH Posted July 1, 2015 Share Posted July 1, 2015 How about something like this?expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ScrollBarConstants.au3> #include <WinAPI.au3> #include <GuiScrollBars.au3> #include <GuiEdit.au3> Global $hGUI = GUICreate("Example", 380, 360) Global $hEdit = GUICtrlCreateEdit("", 10, 140, 360, 170, BitOR($WS_HSCROLL, $WS_VSCROLL)) _GUIScrollBars_Init(GUICtrlGetHandle($hEdit)) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Sleep(100) updateEdit() WEnd Func updateEdit() Local $scrollbarVertPos = _GUIScrollBars_GetScrollPos(GUICtrlGetHandle($hEdit), $SB_VERT) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $scrollbarVertPos = ' & $scrollbarVertPos & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $text = "" For $i = 0 To 100 $text &= "HELLO! " & $i & @CRLF Next GUICtrlSetData($hEdit, $text) ;~ ControlSend($hGUI, "", GUICtrlGetHandle($hEdit), "^{END}") ;~ _GUIScrollBars_SetScrollInfoPos(GUICtrlGetHandle($hEdit), $SB_VERT, $scrollbarVertPos) _GUICtrlEdit_BeginUpdate($hEdit) ; <<<<<<< helps limit the flickering For $Loop = 1 To $scrollbarVertPos ; <<<<<<<<< scroll to the line that the scroll bar is set to _GUICtrlEdit_Scroll($hEdit, $SB_LINEDOWN) Next _GUICtrlEdit_EndUpdate($hEdit) EndFunc ;==>updateEdit If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
tpdietz Posted July 1, 2015 Author Share Posted July 1, 2015 Thank you! I did end up using _GUICtrlEdit_LineScroll(), but wouldn't have done so without your help. I found it while reading through the documentation for _GUICtrlEdit_Scroll(). Using _GUICtrlEdit_LineScroll() eliminates the flickering for the most part. It still flickers if the User's cursor is hovering over the edit box, but its much better than before. Link to comment Share on other sites More sharing options...
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