Jump to content

Recommended Posts

Posted

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 ?

#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

 

BeforeofafterGuiSetState.png.40ac4a5a0b9e845ff74cce5b34b09d7d.png

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

Posted (edited)

What a great forum with people answering so quickly, thank you guys :thumbsup:

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 by pixelsearch
typo

"I think you are searching a bug where there is no bug... don't listen to bad advice."

  • Solution
Posted (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 by pixelsearch

"I think you are searching a bug where there is no bug... don't listen to bad advice."

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...