How to force a textbox to update its text

323 views Asked by At

So I've looked through maybe five to ten questions on stackoverflow about setting text into a textbox using a range of commands. I've tried SetWindowText, SendMessage with EM_SETSEL and EM_REPLACESEL, and a few others that I can't think of off the top of my head. For the most part I have been successful, except for one strange occurrence.

When I set the text of this specific text box, nothing appears, nothing changes. At first I thought I was not setting the data correctly. However, when I use Spy++ or Winspector to see the text of a textbox, the correct data with my changes are in there, but not displayed on the actual textbox. Even stranger, when I click back into the form with the textbox I "edited", spy++ and Winspector's data changes to what the textbox is displaying.

I spoke with a friend of mine and he mentioned it might be a race condition. I'm trying to edit this box and the textbox is being edited by some other thread as well.

If anyone has any suggestions I would really appreciate it.

Edit: Alright so I did some more digging into what is causing the problem with the text changing back. I opened up Winspector and had it watch the textbox. From there I was able to identify the messages sent to the window between the final time the text data is correct, to the first time it changes. I also exported the results to an xml document with the parameters, but it is about 680 lines long.

Heres the list of messages: https://i.stack.imgur.com/qW09t.png

1

There are 1 answers

1
Simon Whitehead On

The control may just need to re-paint itself.

You can try two API's to do that: