Wanting to change windows control data

Started by
4 comments, last by d000hg 21 years, 5 months ago
I have a standard edit control, used for a floating point value. I can read it ok by capturing the message to the control''s parent dialog, but not all values are acceptable. So if a bad value is input I want to change the text to an acceptable value. However because all this is done in response to a message for the control, using SetDlgItemText() or SetWindowText() both cause another message to be sent to the control - hence an infinite loop occurs (well a stack overflow really) How can I fix this? I thought maybe send a message directly to change the text? Read about my game, project #1 NEW (9th September)diaries for week #5 Also I''m selling a few programming books very useful to games coders. Titles on my site. John 3:16
Advertisement
SendMessage( (hwnd of edit), WM_SETTEXT, 0, (WPARAM)"0.1" );

But if the other two are giving you recursion why won''t this? I believe that it boils down to what message you are trapping, and the logic you are using... Good luck
You only need to SetWindowText until the control is valid, right?
You may want to handle the EN_CHANGE or EN_UPDATE notification from the edit control. I don''t think SetWindowText will result in another update notification, but if it does, you can always set a global value specifying if you''re currently handling a text change message and, if so, cancel out of the infinite recursion.

More accurately what I do is:

respond to any WM_COMMAND message targeted for the edit box:
I check what the value is by calling GetDlgItemText() and atof() to get a float. Then I check if this value is OK - if not I want to change the value in the window.
I tried changing a different edit box to the one receiving the message and that works fine, so it diffinately is that changing the text sends another message. I''ll look into detecting what kind of message is being received.


Read about my game, project #1
NEW (9th September)diaries for week #5

Also I''m selling a few programming books very useful to games coders. Titles on my site.

John 3:16
How do I tell, when a control sends me a WM_COMMAND message, what it wants to tell me?

I guess its somewhere in LPARAM or WPARAM, but which bit of what - the id and handle to the control, and the actual message are also stored but I want the bit that says "Hi, I just updated the control" or whatever. And what values can it send me exactly?

This topic is closed to new replies.

Advertisement