{"id":97525,"date":"2017-12-05T07:00:00","date_gmt":"2017-12-05T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=97525"},"modified":"2019-03-13T01:20:49","modified_gmt":"2019-03-13T08:20:49","slug":"20171205-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20171205-00\/?p=97525","title":{"rendered":"Tree view check boxes: The extended check box states"},"content":{"rendered":"<p>Version 6 of the common controls in Windows Vista introduced some new check-box-related extended styles for the tree view controls. Unfortunately, <a HREF=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb759981(v=vs.85).aspx\">the documentation for them<\/a> is kind of spare. <\/p>\n<blockquote CLASS=\"q\">\n<dl>\n<dt>    <code>TVS_<\/code><code>EX_<\/code><code>PARTIAL&shy;CHECK&shy;BOXES<\/code> <\/dt>\n<dd>    Include partial checkbox state if the control has the     <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code> style. <\/dd>\n<dt>    <code>TVS_<\/code><code>EX_<\/code><code>DIMMED&shy;CHECK&shy;BOXES<\/code> <\/dt>\n<dd>    Include dimmed checkbox state if the control has the     <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code> style. <\/dd>\n<dt>    <code>TVS_<\/code><code>EX_<\/code><code>EXCLUSION&shy;CHECK&shy;BOXES<\/code> <\/dt>\n<dd>    Include exclusion checkbox state if the control has the     <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code> style. <\/dd>\n<\/dl>\n<\/blockquote>\n<p>Yeah, that doesn&#8217;t really explain anything. <\/p>\n<p>Fortunately, more information about what these check box states are for can be found in <a HREF=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/dd378458(v=vs.85).aspx\">the documentation for the <code>NSTCSTYLE<\/code> enumeration<\/a>. <\/p>\n<blockquote CLASS=\"q\">\n<dl>\n<dt>    <code>NSTCS_<\/code><code>PARTIAL&shy;CHECK&shy;BOXES<\/code> <\/dt>\n<dd>    Adds a checkbox icon on the leftmost side of a given item     with a square in the center,     that indicates that the node is partially selected.     Maps to the     <code>TVS_<\/code><code>EX_<\/code><code>PARTIAL&shy;CHECK&shy;BOXES<\/code>     tree view control style. <\/dd>\n<dt>    <code>NSTCS_<\/code><code>DIMMED&shy;CHECK&shy;BOXES<\/code> <\/dt>\n<dd>    Adds a checkbox icon on the leftmost side of a given item     that contains an icon of a dimmed check mark,     that indicates that a node is selected because its parent     is selected.     Maps to the     <code>TVS_<\/code><code>EX_<\/code><code>DIMMED&shy;CHECK&shy;BOXES<\/code>     tree view control style. <\/dd>\n<dt>    <code>NSTCS_<\/code><code>EXCLUSION&shy;CHECK&shy;BOXES<\/code> <\/dt>\n<dd>    Adds a checkbox icon on the leftmost side of a given item     that contains a red <b>X<\/b>,     which indicates that the item is excluded from the current     selection.     Without this exclusion icon, selection of a parent item     includes selection of its child items.     Maps to the     <code>TVS_<\/code><code>EX_<\/code><code>EXCLUSION&shy;CHECK&shy;BOXES<\/code>     tree view control style. <\/dd>\n<\/dl>\n<\/blockquote>\n<p>Okay, so that explains what the intended purposes of these new styles are. <\/p>\n<p>Of course, when you use those state images, you can use them to mean whatever you like. Though for consistency with the rest of Windows, you probably want to use them to mean what Windows uses them to mean, just like you should probably use the checked state to mean, y&#8217;know, that the thing is selected. <\/p>\n<p>Don&#8217;t forget that these are tree view extended styles, not window manager extended styles, so you set them by using the <code>TVM_<\/code><code>SET&shy;EXTENDED&shy;STYLE<\/code> message or the corresponding <code>Tree&shy;View_<\/code><code>Set&shy;Extended&shy;Style<\/code> macro. <\/p>\n<p>The documentation for these extended styles says that they must be combined with <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code>, but that is not true; these extended styles imply <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code>; you don&#8217;t need to set <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code>. In fact, it&#8217;s worse than that. If you set <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code> first, and then set the extended styles second, you won&#8217;t get the extended styles at all. That&#8217;s because of the rules we spelled out last time: <\/p>\n<blockquote CLASS=\"q\">\n<ul>\n<li>    Turn on the check boxes,     either by setting the     <code>TVS_<\/code><code>CHECK&shy;BOXES<\/code> style     (if all you want is unchecked and checked)     or setting one or more of     the <code>TVS_<\/code><code>EX_<\/code><code>XXX&shy;CHECK&shy;BOXES<\/code>     styles     (if you want other states, too). <\/li>\n<li>    Do not touch any of the checkbox-related styles any more.     You get one chance, and that&#8217;s it. <\/li>\n<\/ul>\n<\/blockquote>\n<p>Okay, so that&#8217;s really a documentation error, not a quirk. <\/p>\n<p>Anyway, let&#8217;s take these new extended styles for a spin. Save the scratch program we&#8217;ve been using up until now, because we&#8217;re going to be reusing functions from it. Grab a new <a HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20030723-00\/?p=43073\">scratch program<\/a> and make these changes: <\/p>\n<pre>\n<font COLOR=\"blue\">#pragma comment(linker,\"\\\"\/manifestdependency:type='win32' \\\nname='Microsoft.Windows.Common-Controls' version='6.0.0.0' \\\nprocessorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\\\"\")<\/font>\n\nBOOL\nOnCreate(HWND hwnd, LPCREATESTRUCT lpcs)\n{\n  <font COLOR=\"darkgreen\">\/\/ Copy this from the old program.\n    g_hwndChild = CreateWindow(WC_TREEVIEW,\n    nullptr,\n    TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT |\n    WS_CHILD | WS_VISIBLE,\n    CW_USEDEFAULT, CW_USEDEFAULT,\n    CW_USEDEFAULT, CW_USEDEFAULT,\n    hwnd, nullptr, g_hinst, 0);<\/font>\n\n  <font COLOR=\"blue\">\/\/ New code\n  DWORD desiredStyles = TVS_EX_PARTIALCHECKBOXES |\n                        TVS_EX_DIMMEDCHECKBOXES  |\n                        TVS_EX_EXCLUSIONCHECKBOXES;\n\n  TreeView_SetExtendedStyle(g_hwndChild,\n        desiredStyles, desiredStyles);<\/font>\n\n  <font COLOR=\"darkgreen\">\/\/ Copy this from the old program\n  PopulateTreeView(g_hwndChild);<\/font>\n\n  return TRUE;\n}\n\nvoid\nOnDestroy(HWND hwnd)\n{\n  <font COLOR=\"darkgreen\">\/\/ Copy this from the old program\n  ImageList_Destroy(TreeView_SetImageList(\n    g_hwndChild, nullptr, TVSIL_STATE));<\/font>\n  PostQuitMessage(0);\n}\n<\/pre>\n<p>The new image list states are added in the order above: Partial, then dimmed, then exclusion. If you omit one of the states, then the others move up to close the gap. For example, if you ask for partial and exclusion (but not dimmed), then the images are unchecked (1), checked (2), partial (3), and exclusion (4). <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Partial, dimmed, and exclusion.<\/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-97525","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Partial, dimmed, and exclusion.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97525","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=97525"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97525\/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=97525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=97525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=97525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}