pixelsearch Posted April 8 Posted April 8 Hello everybody Could you please run the following script, then report if the line immediately visible at the top is line 2 or line 1 ? expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration Example() Func Example() Local $hGui, $hRichEdit, $idButton, $iCounter = 0 $hGui = GUICreate("1st line hidden when...", 300, 286) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 200, 266, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $idButton = GUICtrlCreateButton("Button", 225, 10, 60, 30) While True $iCounter +=1 _GUICtrlRichEdit_AppendText($hRichEdit, ($iCounter > 1 ? @crlf : "") & "Line " & $iCounter) If _GUICtrlRichEdit_GetNumberOfFirstVisibleLine($hRichEdit) > 1 Then ExitLoop ; richedit became scrollable WEnd _GUICtrlRichEdit_SetScrollPos($hRichEdit, 0, 0) ; bad behavior when placed before GUISetState (in case total lines = total visible + 1) GUISetState(@SW_SHOW) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) GUIDelete() Exit Case $idButton ConsoleWrite("1st visible line (1-based) is : " & _GUICtrlRichEdit_GetNumberOfFirstVisibleLine($hRichEdit) & @crlf) EndSwitch WEnd EndFunc ;==>Example On my computer, the line visible at the top is line 2 (left part of the pic) with this code... _GUICtrlRichEdit_SetScrollPos($hRichEdit, 0, 0) ; bad behavior when placed before GUISetState (in case total lines = total visible + 1) GUISetState(@SW_SHOW) ...but it becomes line 1 (right part of the pic) with that code : GUISetState(@SW_SHOW) _GUICtrlRichEdit_SetScrollPos($hRichEdit, 0, 0) ; good behavior when placed after GUISetState (in case total lines = total visible + 1) Is it the same for you ? Thanks "I think you are searching a bug where there is no bug... don't listen to bad advice."
argumentum Posted April 8 Posted April 8 yes, same here. pixelsearch 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
BigDaddyO Posted April 8 Posted April 8 Same, it doesn't seem to work before displaying the UI. It doesn't set @error either. pixelsearch 1
pixelsearch Posted April 8 Author Posted April 8 (edited) What a great forum with people answering so quickly, thank you guys I found this annoyance yesterday while testing thoroughly my script here, then confirmed with Nine's script found there (example 3) . As both of our scripts don't use (on purpose) a $WS_VSCROLL style while creating the richedit control, then I started the actual thread with a richedit control that uses a $WS_VSCROLL style (as it should be) and here we are... If not mistaken, this annoyance happens only when the number of total lines = number total visible lines + 1 . We can confirm it like this, using the script above : 1) Let's keep these 2 lines of code untouched, ordered like this : _GUICtrlRichEdit_SetScrollPos($hRichEdit, 0, 0) ; bad behavior when placed before GUISetState (in case total lines = total visible + 1) GUISetState(@SW_SHOW) 2) Now we increase the value in this line... If _GUICtrlRichEdit_GetNumberOfFirstVisibleLine($hRichEdit) > 1 Then ExitLoop ... by changing its "> 1" to bigger values (like > 2 , > 3 etc...) How is the display ? Well it's always correct starting from > 2 ("correct" means line 1 is visible at top) , the only value that brings a bad display is "> 1" (bad display means line 2 is visible at top) So in the end, where should be placed the following line, before or after GUISetState() ? _GUICtrlRichEdit_SetScrollPos($hRichEdit, 0, 0) My advice is it should always be placed after, because even with 10.000 lines in the richedit control, the display is immediate (not in "2 times", tested) and who knows (it may happen one day) in case the richedit control got exactly a total number of lines = total visible lines + 1 , then its display will always be correct (e.g. line 1 appearing at the top) Edited April 8 by pixelsearch typo argumentum 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
Solution KaFu Posted April 8 Solution Posted April 8 Try _GUICtrlRichEdit_SetSel($hRichEdit, 0, 0). pixelsearch 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
pixelsearch Posted April 8 Author Posted April 8 (edited) 1 hour ago, KaFu said: Try _GUICtrlRichEdit_SetSel($hRichEdit, 0, 0) Nice catch. I just tried it (instead of _GUICtrlRichEdit_SetScrollPos) and it forces line 1 to display at the top in all cases Edit: now my test script becomes a bit longer but well... I have to remember all this : ; _GUICtrlRichEdit_SetScrollPos($hRichEdit, 0, 0) ; bad behavior when placed before GUISetState (in case total lines = total visible + 1) ; better is : _GUICtrlRichEdit_SetSel($hRichEdit, 0, 0) ; Kafu's solution 100% ( https://www.autoitscript.com/forum/topic/212823-richedit-issue/ ) GUISetState(@SW_SHOW) ; _GUICtrlRichEdit_SetScrollPos($hRichEdit, 0, 0) ; good behavior when placed after GUISetState (in case total lines = total visible + 1) Edited April 8 by pixelsearch "I think you are searching a bug where there is no bug... don't listen to bad advice."
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