{"id":97465,"date":"2017-11-27T07:00:00","date_gmt":"2017-11-27T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=97465"},"modified":"2019-03-13T01:20:35","modified_gmt":"2019-03-13T08:20:35","slug":"20171127-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20171127-00\/?p=97465","title":{"rendered":"The TVS_CHECKBOXES style is quirky, which is a polite way of saying that it is crazy"},"content":{"rendered":"<p>A customer was having trouble with tree view checkboxes. <\/p>\n<blockquote CLASS=\"m\">\n<p>We have a tree view control in a dialog box. It is defined like this: <\/p>\n<pre>\nCONTROL \"\", IDC_TREEVIEW, WC_TREEVIEW,\n    TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT |\n    TVS_DISABLEDRAGDROP | TBS_SHOWSELALWAYS |\n    TVS_CHECKBOXES | WS_BORDER | WS_HSCROLL | WS_TABSTOP,\n    65, 22, 259, 182\n<\/pre>\n<p>As you can see, the <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code> style is set in the dialog template. When the dialog is created, but before it is shown, we have code that populates the tree. At that time, we want to set the checked state of some of the nodes by using the <code>Tree&shy;View_<\/code><code>Set&shy;Check&shy;State<\/code> macro. If we call <code>Tree&shy;View_<\/code><code>Get&shy;Check&shy;State<\/code> immediately after setting the checked state, it reports the checked state correctly. However, once the tree view finishes rendering, all of the check boxes are cleared. <\/p>\n<p>Curiously, if we hide the dialog box, then set the check boxes, and then show the dialog box, then the check boxes are not reset. <\/p>\n<p>Why can&#8217;t we check the tree view items immediately upon adding them, but before the dialog is shown for the first time? And more importantly, is there a workaround? <\/p>\n<\/blockquote>\n<p>The tree view control&#8217;s handling of the <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code> style is quirky. <\/p>\n<p>&#8220;Quirky&#8221; is a polite word for &#8220;crazy&#8221;. <\/p>\n<p><a HREF=\"https:\/\/msdn.microsoft.com\/library\/bb760013(VS.85).aspx\">The documentation for the <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code> style<\/a> says <\/p>\n<blockquote CLASS=\"q\"><p>If you want to use this style, you must set the TVS_<\/code><code>CHECK&shy;BOXES<\/code> style with <b>Set&shy;Window&shy;Long<\/b> after you create the treeview control, and before you populate the tree. Otherwise, the checkboxes might appear unchecked, depending on timing issues. <\/p><\/blockquote>\n<p>Sorry. <\/p>\n<p>Tree view check boxes were poorly-designed. But we&#8217;re stuck with them. <\/p>\n<p>The customer confirmed that removing the <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code> style from the dialog template and instead applying the style at run time fixes the problem. <\/p>\n<p>The <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code> style is quirky because it was bolted on rather than designed in. We&#8217;ll spend the next several days exploring its quirks and trying to come up with a set of best practices for its use. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>You have to set it at just the right time.<\/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-97465","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You have to set it at just the right time.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97465","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=97465"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97465\/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=97465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=97465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=97465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}