Jump to content

GUICtrlCreateEdit + ReadOnly + Scrollbar?


DarkBoost
 Share

Recommended Posts

When adding the Style WS_VSCROLL it breaks the ES_READONLY - any suggestions?

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

Opt("MustDeclareVars", 1)

Dim $title = "gui"
Dim $width = 300
Dim $height = 300
Dim $msg, $edit

GUICreate($title, $width, $height)
$edit = GUICtrlCreateEdit("[START]" & @CRLF, 10, 10, $width-20, $height-20, $ES_AUTOVSCROLL + $ES_READONLY)
GUICtrlSetStyle($edit, $WS_VSCROLL)

For $x = 1 To 50
    GUICtrlSetData($edit, "add data..." & @CRLF, 1)
Next

GUICtrlSetData($edit, "[FINISH]", 1)

GUISetState()

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
Link to comment
Share on other sites

When adding the Style WS_VSCROLL it breaks the ES_READONLY - any suggestions?

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

Opt("MustDeclareVars", 1)

Dim $title = "gui"
Dim $width = 300
Dim $height = 300
Dim $msg, $edit

GUICreate($title, $width, $height)
$edit = GUICtrlCreateEdit("[START]" & @CRLF, 10, 10, $width-20, $height-20, $ES_AUTOVSCROLL + $ES_READONLY)
GUICtrlSetStyle($edit, $WS_VSCROLL)

For $x = 1 To 50
    GUICtrlSetData($edit, "add data..." & @CRLF, 1)
Next

GUICtrlSetData($edit, "[FINISH]", 1)

GUISetState()

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

You can make an edit readonly by sening a message to it

But in your case it is pointless if you want the user to be able to edit the control using the Enter key. The two styles $ES_AUTOVSCROLL and $ES_READONLY are not compatible and it will be the same as using $WS_VSCROLL since the user can still use the arrow keys to navigate. Even with $WS_VSCROLL the $WS_READONLY is ignored on creation so using the message was the only way I was able to make the edit readonly and have a verticle scroll bar.

It is saver BTW to BitOr styles rather thn add them which can have unexpected results.

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

Opt("MustDeclareVars", 1)

Dim $title = "gui"
Dim $width = 300
Dim $height = 300
Dim $msg, $edit

GUICreate($title, $width, $height)
$edit = GUICtrlCreateEdit("[START]" & @CRLF, 10, 10, $width-20, $height-20, $WS_VSCROLL)
GUICtrlSetStyle($edit, $WS_VSCROLL)

For $x = 1 To 50
    GUICtrlSetData($edit, "add data..." & @CRLF, 1)
Next

GUICtrlSetData($edit, "[FINISH]", 1)

GUISetState()

_sendmessage(ControlGetHandle("gui","",$edit),$EM_SETREADONLY,1)
;or 
;_GUICtrlEdit_SetReadOnly(ControlGetHandle("gui","",$edit),True)
Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
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.
Link to comment
Share on other sites

There is no need to use GUICtrlSetStyle and SendMessage. Just use BitOr and all is fine :)

$edit = GUICtrlCreateEdit("[START]" & @CRLF, 10, 10, $width-20, $height-20, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

There is no need to use GUICtrlSetStyle and SendMessage. Just use BitOr and all is fine :)

$edit = GUICtrlCreateEdit("[START]" & @CRLF, 10, 10, $width-20, $height-20, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))

Yes, although $ES_AUTOSCROLLL has no effect't work if $ES_READONLY is included. But the (only) advantage of sending a message is that you can change the readonly style after the edit has been created.
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.
Link to comment
Share on other sites

  • 2 months later...

Hi Martin and ProgAndy,

That's confusing me a little bit about BitOr() and "+" from this code. Isn't the final result the same ( BitOr() == "+"). :mellow:

$edit = GUICtrlCreateEdit("Texts", 10, 10, 700, 300, BitOr($WS_VSCROLL,  $ES_AUTOVSCROLL, $ES_READONLY))

and this code

$edit = GUICtrlCreateEdit("Texts", 10, 10, 700, 300, $WS_VSCROLL +  $ES_AUTOVSCROLL + $ES_READONLY)

and if i tested it, it scroll down too with "read-only" style, hmm doesn't see differents. Also read-only style works with the $ES_AUTOVSCROLL style. :(

I'm searching about tricks and technic's above with GUICtrlCreateEdit() and lead me to this topic and make me confusing about these things here.

That's because i'm using "GUICtrlCreateEdit()" in my project too and use it as output and have set the style like here but with some addition like append the text while the cursor was clicked and not at the end of the file. (that was solve)

I'm very appreciate and thank you, if someone or martin and progandy explain me again. :lol:

Edit: Does i hijacking this thread when i ask about this? If yes then i open my own.

basicz

Edited by Basicz

[right]Sorry for my poor english(dictionary beside)[/right][center]Search before ask will helping the community of AutoIt.[/center][center]...seeking in the search forum and help-file's, with all the most answer's that i need. Hope for you too.[/center]

Link to comment
Share on other sites

  • Moderators

Basicz,

Often using BitOR and simple addition will give you the same answer, but sometimes not. :lol:

Most of the styles are set using the individual bits of the style value - if you look at the Hex values of the various styles, it is pretty obvious. So using BitOR will ensure that only the correct bits are set. If you use simple addition and the particular bit is already set, you could well, depending on exactly how the addition works, unset that bit and set another. Then you end up without the style you want and with another style that is unwanted - and debugging that can take a while as I know from bitter personal exerience. :mellow:

So the advice is: Always use BitOR to combine styles - and, for exactly the same reason, use BitAND to see if a particular style is set!

I hope that clears it up. :(

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Basicz,

Often using BitOR and simple addition will give you the same answer, but sometimes not. :P

Most of the styles are set using the individual bits of the style value - if you look at the Hex values of the various styles, it is pretty obvious. So using BitOR will ensure that only the correct bits are set. If you use simple addition and the particular bit is already set, you could well, depending on exactly how the addition works, unset that bit and set another. Then you end up without the style you want and with another style that is unwanted - and debugging that can take a while as I know from bitter personal exerience. :mellow:

So the advice is: Always use BitOR to combine styles - and, for exactly the same reason, use BitAND to see if a particular style is set!

I hope that clears it up. :(

M23

Hi M23,

That's very clear about BitOr() and normal addition. For the future i'm will using only BitOr(). :lol:

Thank you very much, to explain this. I'm appreciate. :evil:

basicz

[right]Sorry for my poor english(dictionary beside)[/right][center]Search before ask will helping the community of AutoIt.[/center][center]...seeking in the search forum and help-file's, with all the most answer's that i need. Hope for you too.[/center]

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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