A customer observed some strange behavior with window styles:
We ran some weird behavior: Calling the
SetWindowTextfunction causes a change in window styles. Specifically, calling
SetWindowTextresults in the
WM_messages, and sometimes the result is that the
WS_style is removed. Is this a bug? What would cause this?
SetWindowText message sends the
WM_ message to the control, at which point anything that happens is the window's own responsibility. If it wants to change styles based on the text you sent, then that's what happens. The window manager doesn't do anything special to force it to happen or to prevent it.
That's weird, because I'm not even listening for
WM_messages. I also verified that there is no call into my code during the call to the the
I'm assuming that the window belongs to the same process as the caller. If the window belongs to another process, then the rules are different.
I'm changing the text of a window created by the same thread.
Okay, so let's see what we have so far. The customer is calling the
SetWindowText function to change the text of a window created on the same thread. There is no handler for the
WM_ message, and yet the window style is changing. At this point, you might start looking for more obscure sources for the problem, like say a global hook of some sort. While I considered the possibilities, the customer added,
It may be worth noting that I'm using the
Okay, now things are starting to make sense, and it didn't help that the customer provided misleading information in the description of the problem. For example, when the customer wrote, "There is no handler for the
WM_ message," the customer was not referring to the window whose window text is changing but to some other unrelated window.
It's like responding to the statement "A confirmation letter should have been sent to the account holder" with "I never got the confirmation letter," and then the person spends another day trying to figure out why the confirmation letter was never sent before you casually mention, "Oh, I'm not the account holder."
WM_ message is sent to the window you passed to
SetWindowText; in this case, it's the
SysLink window. It is therefore the window procedure of the
SysLink window that is relevant here.
SysLink control remembers whether it was originally created with the
WS_, and if the markup it is given has no tab stops, then it removes the style; if the markup has tab stops, then it re-adds the style.
How do I add a tab stop to a string? I couldn't find any reference to it and all my guesses failed.
The tab stops in question are the hyperlinks you added when you used the
<A>...</A> notation. If the text has no hyperlinks, then the control removes the
WS_ style because it is no longer something you can tab to.