{"id":98825,"date":"2018-05-24T07:00:00","date_gmt":"2018-05-24T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=98825"},"modified":"2019-03-13T00:44:21","modified_gmt":"2019-03-13T07:44:21","slug":"20180524-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20180524-00\/?p=98825","title":{"rendered":"How do I create a disabled checkbox for a listview item?"},"content":{"rendered":"<p>A customer was using the <code>LVS_<\/code><code>EX_<\/code><code>CHECK&shy;BOXES<\/code> extended listview style to get checkboxes for the listview items. However, they also wanted some items to have a disabled checkbox, which is not a feature that <code>LVS_<\/code><code>EX_<\/code><code>CHECK&shy;BOXES<\/code> supports. <\/p>\n<p>They solved the problem by turning off the <code>LVS_<\/code><code>EX_<\/code><code>CHECK&shy;BOXES<\/code> extended style and replicating and extending the functionality of <code>LVS_<\/code><code>EX_<\/code><code>CHECK&shy;BOXES<\/code> by creating a <a HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20171201-00\/?p=97505\">custom state imagelist consisting of enabled and disabled and checked and unchecked check boxes<\/a> and setting that as the state imagelist for the listview. They also handled the mouse and keyboard notifications so that clicking on the state image or pressing the space bar toggled the check\/unchecked state of the item. <\/p>\n<p>So far so good. <\/p>\n<p>However, there is still the issue of accessibility: Accessibility tools understand that the <code>LVS_<\/code><code>EX_<\/code><code>CHECK&shy;BOXES<\/code> extended style means that the state images are check boxes, but since they aren&#8217;t using that style, that leaves accessibility tools in the dark. <\/p>\n<p>How do they get accessibility tools the information they need? <\/p>\n<p>One way is to subclass the listview control and customize the <code>WM_<\/code><code>GET&shy;OBJECT<\/code> message handler by wrapping the standard accessible object for the listview, and then override the <code>get_<\/code><code>accState<\/code> method to report the state for each item. <\/p>\n<p>Alternatively, they can use <a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms697262.aspx\">Dynamic Annotation<\/a> to report the state for the item. Direct Annotation is a push model, where the control pushes the current state each time it changes. Server Annotation is a pull model, where the control registers a server that produces the state of each item upon request. (Here&#8217;s <a HREF=\"http:\/\/web.archive.org\/web\/20090129095433\/http:\/\/msdn.microsoft.com\/en-us\/accessibility\/cc307286.aspx\">an example for a custom control<\/a>.) <\/p>\n<p>The customer chose to go with Dynamic Annotation and reported that it solved their problem. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>A little state image magic.<\/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-98825","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A little state image magic.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/98825","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=98825"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/98825\/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=98825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=98825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=98825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}