Holy cow, I wrote a book!
A customer observed some strange behavior with window styles:
We ran some weird behavior:
SetWindowText function causes
a change in window styles.
SetWindowText results in the
and sometimes the result is that the
WS_TABSTOP style is removed.
Is this a bug?
What would cause this?
The SetWindowText message
sends the WM_SETTEXT message to the control,
at which point anything that happens is the window's own
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
I also verified that there is no call into my code
during the call to the
the SetWindowText function.
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_SETTEXT 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_SETTEXT 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"
"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."
The WM_SETTEXT 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.
The SysLink control remembers whether it was
originally created with the WS_TABSTOP,
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
If the text has no hyperlinks, then the control removes the
WS_TABSTOP style because it is no longer
something you can tab to.