Jump to content

Recommended Posts

Posted (edited)

My code.

Does not work

;~ [optional] Control styles:
;~     $ES_AUTOHSCROLL - Automatically scrolls text to the right by 10 characters when the user types a character at the end of the line.
;~     $ES_AUTOVSCROLL - Automatically scrolls text up one page when the user presses the ENTER key on the last line.

    Local $hEditNewText = _GUICtrlEdit_Create($hGUI, "This is a test" & @CRLF & "Another Line", 8, 500, 715, 100)
    Local $iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($hEditNewText), $GWL_STYLE) ; get style
    Local $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($hEditNewText), $GWL_EXSTYLE) ; get extended style
    ;GUICtrlSetStyle($hEditNewText, BitXOR($iStyle, $ES_AUTOHSCROLL)) ; remove hscroll left to right (force wrap)
    GUICtrlSetStyle($hEditNewText, BitAND($iStyle, BitNOT($ES_AUTOHSCROLL)))

https://www.autoitscript.com/wiki/Setting_Styles

Also tried this

;~ https://www.autoitscript.com/forum/topic/113598-solved-scrolling-read-only-text-display-using-edit-not-input-control/
    Local $hEditNewText = GUICtrlCreateEdit("This is a test" & @CRLF & "Another Line", 8, 500, 715, 100)
    Local $iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($hEditNewText), $GWL_STYLE) ; get style
    Local $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($hEditNewText), $GWL_EXSTYLE) ; get extended style
    GUICtrlSetStyle($hEditNewText, BitAND($iStyle, BitNOT($ES_AUTOHSCROLL)))

 

However, this works:

Local $hEditNewText = GUICtrlCreateEdit("This is a test" & @CRLF & "Another Line", 8, 500, 715, 100, $ES_WANTRETURN + $WS_VSCROLL + $ES_AUTOVSCROLL + $ES_MULTILINE + $WS_TABSTOP)

My question stands. How to change the STYLE of an EDIT control?

Skysnake

Edited by Skysnake

Skysnake

Why is the snake in the sky?

  • Moderators
Posted

Skysnake,

You need to remove the $WS_HSCROLL style from the control styles - the $ES_AUTOHSCROLL merely allows the control to automatically scroll as you type. This is why the final snippet works and the others do not, as you only remove the correct style in that final one - in the first 2 the edit control is created with the $WS_HSCROLL as a default style as explained in the Help file.

This works for me:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

; Create edit without the $WS_HSCROLL style
$cEdit = GUICtrlCreateEdit("", 10, 10, 200, 200, Bitor($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

  Reveal hidden contents

 

  • 4 years later...
Posted (edited)

@Melba23 Thanks for yours example, I wanted to use them and then I found that GUICtrlSetStyle() behaves in a strage way.

Here is my repro script:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

_Example(True)
_Example(False)

Func _Example($b_Presetting_at_start)
    GUICreate("Test", 500, 500)
    Local $sText = _
            ' first line ............................................ ....... ...... xyz' & @CRLF & _
            '' & @CRLF & _
            ''
    Local $i_Edit_Style = 0
    $i_Edit_Style = BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL)

    If $b_Presetting_at_start Then $i_Edit_Style = BitOR($i_Edit_Style, $WS_HSCROLL, $ES_AUTOHSCROLL)

    Local $cEdit = GUICtrlCreateEdit($sText, 10, 10, 200, 200, $i_Edit_Style)

    If Not $b_Presetting_at_start Then
        $i_Edit_Style = BitOR($i_Edit_Style, $WS_HSCROLL, $ES_AUTOHSCROLL)
        GUICtrlSetStyle($cEdit, $i_Edit_Style)
    EndIf

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Return
        EndSwitch
    WEnd
EndFunc   ;==>_Example


The strange for me is the fact that when I use $b_Presetting_at_start = false then the line is wrapped, is there a way to disable wrapping when I use $b_Presetting_at_start = false ?

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Hah.... I found solution....

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

_Example(True)
_Example(False)

Func _Example($b_Presetting_at_start)
    GUICreate("Test", 500, 500)
    Local $sText = _
            ' first line ............................................ ....... ...... xyz' & @CRLF & _
            '' & @CRLF & _
            ''
    Local $i_Edit_Style = $WS_HSCROLL, $ES_AUTOHSCROLL
    $i_Edit_Style = BitOR($i_Edit_Style, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL)

    If $b_Presetting_at_start Then $i_Edit_Style = BitOR($i_Edit_Style, $WS_HSCROLL, $ES_AUTOHSCROLL)

    Local $cEdit = GUICtrlCreateEdit($sText, 10, 10, 200, 200, $i_Edit_Style)

    If Not $b_Presetting_at_start Then
        $i_Edit_Style = BitAND($i_Edit_Style, BitNOT($WS_HSCROLL), BitNOT($ES_AUTOHSCROLL))
        GUICtrlSetStyle($cEdit, $i_Edit_Style)
    EndIf

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Return
        EndSwitch
    WEnd
EndFunc   ;==>_Example

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
×
×
  • Create New...