Sign in to follow this  
Followers 0
Angel

Best way to change the text on a GUI control?

7 posts in this topic

Hi,

I have an AutoIt3 script which creates a simple GUI in which there is an editbox and a button. When I click the button I would like to change the text in the editbox.

I know that this is a really simple scenario and that probably the answer is straightforward, but, is there a better way than using ControlSetText()?

The reason I ask is that using ControlSetText seems to be "out of place" among all the other calls to the GUICTrlXXXX functions, since you must give the name and the text in the window where you want to change the text as if you were changing the text on a window on an external program.

Currently I am simply calling ControlSetText with empty strings for the window name and text, but I feel this is not very same since I believe that doing that will look for the control on the current active window, which may not necesarily be the window in which the button that generated the event is placed.

So, is there some better way to handle this sort of situation?

Thanks a lot for your suggestions,

Amadawn

Share this post


Link to post
Share on other sites



_GUICtrlEdit_SetText

Here try this example it should explain all. I'm still learning this new forum set up and couldn't get the textbox so will just attach the file. Aw well.

changeedit.au3

Share this post


Link to post
Share on other sites

As I understand it

GuiCtrlsetdata if you want to append text to existing data in edit box

_GUICtrlEdit_SetText if you want to replace text in edit box.

Share this post


Link to post
Share on other sites

_GUICtrlEdit_SetText

Here try this example it should explain all. I'm still learning this new forum set up and couldn't get the textbox so will just attach the file. Aw well.

Thanks a lot. I somehow had missed that function when I looked for it on the help, even though I was expecting finding a function with a similar name.

But I would like to still continue with the question. What I would like to know is whether there is a more "generic" way to change the text on a control on one of your own GUIs. Preferably, I'd like to find a method that does not require you including the include corresponding to each of the types of GUI controls that you may use on your GUI.

For instance, is it valid to pass @GUI_WinHandle to the window name of the ControlSetText() function? I tried it and it worked, but is it safe to use? That is, is ControlSetText (and the other ControlSet functions) supposed to be able to accept a window handle in stead of the regular window name parameter?

Thanks,

Angel

Share this post


Link to post
Share on other sites

As I understand it

GuiCtrlsetdata if you want to append text to existing data in edit box

_GUICtrlEdit_SetText if you want to replace text in edit box.

No, this is replace text by default. But if for some reason you don't trust this function, you still can do this with native implementation:

GUICtrlSendMsg($EditCtrl , $WM_SETTEXT, 0, "Your Text")

For instance, is it valid to pass @GUI_WinHandle to the window name of the ControlSetText() function? I tried it and it worked, but is it safe to use? That is, is ControlSetText (and the other ControlSet functions) supposed to be able to accept a window handle in stead of the regular window name parameter?

Yes, Control* functions accept window title or handle as name, and ControlID, control handle or ControlNN string as control name.

Share this post


Link to post
Share on other sites

Thanks a lot Lazycat!

You are definitelly not a lazy cat at all! :-)

Angel

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