{"id":8033,"date":"2012-03-22T07:00:00","date_gmt":"2012-03-22T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2012\/03\/22\/why-does-my-window-style-change-when-i-call-setwindowtext\/"},"modified":"2012-03-22T07:00:00","modified_gmt":"2012-03-22T07:00:00","slug":"why-does-my-window-style-change-when-i-call-setwindowtext","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20120322-00\/?p=8033","title":{"rendered":"Why does my window style change when I call SetWindowText?"},"content":{"rendered":"<p>A customer observed some strange behavior with window styles:<\/p>\n<blockquote class=\"q\"><p> We ran some weird behavior: Calling the <code>Set&shy;Window&shy;Text<\/code> function causes a change in window styles. Specifically, calling <code>Set&shy;Window&shy;Text<\/code> results in the <code>WM_STYLE&shy;CHANGING<\/code> and <code>WM_STYLE&shy;CHANGED<\/code> messages, and sometimes the result is that the <code>WS_TAB&shy;STOP<\/code> style is removed. Is this a bug? What would cause this? <\/p><\/blockquote>\n<p> The <code>Set&shy;Window&shy;Text<\/code> message sends the <code>WM_SET&shy;TEXT<\/code> message to the control, at which point anything that happens is the window&#8217;s own responsibility. If it wants to change styles based on the text you sent, then that&#8217;s what happens. The window manager doesn&#8217;t do anything special to force it to happen or to prevent it.<\/p>\n<blockquote class=\"q\"><p> That&#8217;s weird, because I&#8217;m not even listening for <code>WM_SET&shy;TEXT<\/code> messages. I also verified that there is no call into my code during the call to the the <code>Set&shy;Window&shy;Text<\/code> function. <\/p><\/blockquote>\n<p> I&#8217;m assuming that the window belongs to the same process as the caller. <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/08\/21\/54675.aspx\"> If the window belongs to another process, then the rules are different<\/a>.<\/p>\n<blockquote class=\"q\"><p> I&#8217;m changing the text of a window created by the same thread. <\/p><\/blockquote>\n<p> Okay, so let&#8217;s see what we have so far. The customer is calling the <code>Set&shy;Window&shy;Text<\/code> function to change the text of a window created on the same thread. There is no handler for the <code>WM_SET&shy;TEXT<\/code> 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,<\/p>\n<blockquote class=\"q\"><p> It may be worth noting that I&#8217;m using the <code>Sys&shy;Link<\/code>. <\/p><\/blockquote>\n<p> Okay, now things are starting to make sense, and it didn&#8217;t help that the customer provided misleading information in the description of the problem. For example, when the customer wrote, &#8220;There is no handler for the <code>WM_SET&shy;TEXT<\/code> message,&#8221; the customer was not referring to the window whose window text is changing but to some other unrelated window.\n It&#8217;s like responding to the statement &#8220;A confirmation letter should have been sent to the account holder&#8221; with &#8220;I never got the confirmation letter,&#8221; and then the person spends another day trying to figure out why the confirmation letter was never sent before you casually mention, &#8220;Oh, I&#8217;m not the account holder.&#8221;\n The <code>WM_SET&shy;TEXT<\/code> message is sent to the window you passed to <code>Set&shy;Window&shy;Text<\/code>; in this case, it&#8217;s the <code>Sys&shy;Link<\/code> window. It is therefore the window procedure of the <code>Sys&shy;Link<\/code> window that is relevant here.<\/p>\n<p> The <code>Sys&shy;Link<\/code> control remembers whether it was <a href=\"http:\/\/msdn.microsoft.com\/library\/bb760706(VS.85).aspx#syslink_creation\"> originally created with the <code>WS_TAB&shy;STOP<\/code><\/a>, 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. <\/p>\n<blockquote class=\"q\"><p> How do I add a tab stop to a string? I couldn&#8217;t find any reference to it and all my guesses failed. <\/p><\/blockquote>\n<p> The tab stops in question are the hyperlinks you added when you used the <code>&lt;A&gt;...&lt;\/A&gt;<\/code> notation. If the text has no hyperlinks, then the control removes the <code>WS_TAB&shy;STOP<\/code> style because it is no longer something you can tab to. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer observed some strange behavior with window styles: We ran some weird behavior: Calling the Set&shy;Window&shy;Text function causes a change in window styles. Specifically, calling Set&shy;Window&shy;Text results in the WM_STYLE&shy;CHANGING and WM_STYLE&shy;CHANGED messages, and sometimes the result is that the WS_TAB&shy;STOP style is removed. Is this a bug? What would cause this? The Set&shy;Window&shy;Text [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-8033","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer observed some strange behavior with window styles: We ran some weird behavior: Calling the Set&shy;Window&shy;Text function causes a change in window styles. Specifically, calling Set&shy;Window&shy;Text results in the WM_STYLE&shy;CHANGING and WM_STYLE&shy;CHANGED messages, and sometimes the result is that the WS_TAB&shy;STOP style is removed. Is this a bug? What would cause this? The Set&shy;Window&shy;Text [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/8033","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=8033"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/8033\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=8033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=8033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=8033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}