Sign in to follow this  
Followers 0

GUICtrlCreateEdit + ReadOnly + Scrollbar?

8 posts in this topic

Posted

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

Share this post


Link to post
Share on other sites



Posted

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

Share this post


Link to post
Share on other sites

Posted

That works perfectly... thank you!

Share this post


Link to post
Share on other sites

Posted

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))

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0