{"id":43423,"date":"2014-12-11T07:00:00","date_gmt":"2014-12-11T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/12\/11\/what-states-are-possible-in-a-drawitemstruct-structure\/"},"modified":"2014-12-11T07:00:00","modified_gmt":"2014-12-11T07:00:00","slug":"what-states-are-possible-in-a-drawitemstruct-structure","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20141211-00\/?p=43423","title":{"rendered":"What states are possible in a DRAWITEMSTRUCT structure?"},"content":{"rendered":"<p>The <code>DRAW&shy;ITEM&shy;STRUCT<\/code> structure has an <code>item&shy;State<\/code> member which contains a number of bits describing the state of the item being drawn. How do those states map to the underlying control?\n Most of the states are rather obvious. For a list box item to be <i>selected<\/i>, it means that the item is part of the selection. But what does <i>selected<\/i> mean for a button?\n Since people like tables, I&#8217;ll put the answer in a table:<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"3\" style=\"border-collapse: collapse;margin-bottom: 1em\">\n<tr>\n<th><\/th>\n<th>Menu<\/th>\n<th>Listbox<\/th>\n<th>Combobox<\/th>\n<th>Button<\/th>\n<\/tr>\n<tr>\n<td><code>CtlType<\/code><\/td>\n<td><code>ODT_MENU<\/code><\/td>\n<td><code>ODT_LISTBOX<\/code><\/td>\n<td><code>ODT_COMBOBOX<\/code><\/td>\n<td><code>ODT_BUTTON<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>itemID<\/code><\/td>\n<td>menu item ID<\/td>\n<td>item index or &minus;1<\/td>\n<td>item index or &minus;1<\/td>\n<td><\/td>\n<\/tr>\n<tr> <\/tr>\n<td><code>ODS_SELECTED<\/code><\/td>\n<td>Selected<\/td>\n<td>Selected<\/td>\n<td>Selected<\/td>\n<p><!-- aka Focus -->     <\/p>\n<td>Pushed<\/td>\n<tr>\n<td><code>ODS_GRAYED<\/code><\/td>\n<td>Grayed<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_DISABLED<\/code><\/td>\n<td>Disabled<\/td>\n<td>Disabled<\/td>\n<td>Disabled<\/td>\n<td>Disabled<\/td>\n<\/tr>\n<tr>\n<td><code>ODS_CHECKED<\/code><\/td>\n<td>Checked<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_FOCUS<\/code><\/td>\n<td><\/td>\n<td>Focus<\/td>\n<td>Focus<\/td>\n<td>Focus<\/td>\n<\/tr>\n<tr>\n<td><code>ODS_DEFAULT<\/code><\/td>\n<td>Default menu item<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_HOTLIGHT<\/code><\/td>\n<td>Hover<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_INACTIVE<\/code><\/td>\n<td>Inactive<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_NOACCEL<\/code><\/td>\n<td>HideAccel<\/td>\n<td>HideAccel<\/td>\n<td>HideAccel<\/td>\n<td>HideAccel<\/td>\n<\/tr>\n<tr>\n<td><code>ODS_NOFOCUSRECT<\/code><\/td>\n<td><\/td>\n<td>HideFocus<\/td>\n<td>HideFocus<\/td>\n<td>HideFocus<\/td>\n<\/tr>\n<tr>\n<td><code>ODS_COMBOBOXEDIT<\/code><\/td>\n<td><\/td>\n<td><\/td>\n<td>Is edit control<\/td>\n<td><\/td>\n<\/tr>\n<\/table>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"3\" style=\"border-collapse: collapse\">\n<tr>\n<th><\/th>\n<th>Static<\/th>\n<th>Header<\/th>\n<th>Tab<\/th>\n<th>Listview<\/th>\n<th>Status<\/th>\n<\/tr>\n<tr>\n<td><code>CtlType<\/code><\/td>\n<td><code>ODT_STATIC<\/code><\/td>\n<td><code>ODT_HEADER<\/code><\/td>\n<td><code>ODT_TAB<\/code><\/td>\n<td><code>ODT_LISTVIEW<\/code><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>itemID<\/code><\/td>\n<td><\/td>\n<td>item index<\/td>\n<td>item index<\/td>\n<td>item index<\/td>\n<td>part index<\/td>\n<\/tr>\n<tr>\n<td><code>ODS_SELECTED<\/code><\/td>\n<td><\/td>\n<td>Pushed<\/td>\n<td>Selected<\/td>\n<td>Selected<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_GRAYED<\/code><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_DISABLED<\/code><\/td>\n<td><font color=\"blue\">Oops<\/font><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_CHECKED<\/code><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td>AutoChecked<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_FOCUS<\/code><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td>Focus<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_DEFAULT<\/code><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_HOTLIGHT<\/code><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td>Hover<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_INACTIVE<\/code><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_NOACCEL<\/code><\/td>\n<td>HideAccel<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_NOFOCUSRECT<\/code><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>ODS_COMBOBOXEDIT<\/code><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/table>\n<p> Okay, now that it&#8217;s all in a table, how do I read the table?\n A box is blank if the corresponding flag is not currently used by the control type. (No guarantees about the future.) For example, as of this writing, button controls do not set an <code>itemID<\/code>, nor do they ever ask for <code>ODS_GRAYED<\/code>.\n You may have noticed that the box for <code>CtlType<\/code> is blank for status controls. That&#8217;s an oops. The status bar control forgot to set the <code>CtlType<\/code> when it sends the <code>WM_DRAW&shy;ITEM<\/code> message, so the value is uninitialized garbage. The way to detect a status bar control is to check the window handle. (This works in general. You can always detect a control by checking the window handle.)\n For list boxes and combo boxes, the <code>itemID<\/code> can have the special value <code>-1<\/code> to mean &#8220;I am drawing a list box\/combo box where no item is selected.&#8221; For list boxes, this happens when the list box is empty. For combo boxes, this happens when the user types text into the edit box that does not match any of the items in the list portion of the combo box.\n Most of the other box entries are self-explanatory. For the most part, the flag name matches the conditions under which the corresponding flag is set. For example, the <code>ODS_FOCUS<\/code> flag is set when the list box item being drawn is the selected item.\n Note that the <code>ODS_SELECTED<\/code> flag is used for button and header controls to indicate that the control should be drawn in the pushed state. For example, the user may have put focus on a button control and pressed the space bar and not yet released it, or the application may have manually set the <code>BST_PUSHED<\/code> state. Header controls can get into a <i>pushed<\/i> state if you enable the <code>HDS_BUTTONS<\/code> style.\n List view controls set the <code>ODS_CHECKED<\/code> flag if a check box should be drawn over the item. This happens if the <code>LVS_EX_AUTO&shy;CHECK&shy;SELECT<\/code> extended style is specified and the item is selected. (Normally, the check box is drawn to the side as a state image.)\n The <code>ODS_COMBO&shy;BOX&shy;EDIT<\/code> flag is used only by combo box controls. It is set if the item being drawn is the edit portion of a combo box control. If not set, then the item being drawn is in the list box portion of the combo box control.\n Finally, there is a box marked <font color=\"blue\">Oops<\/font>.\n The static control is supposed to set <code>ODS_DISABLED<\/code> if the static control is disabled. And that&#8217;s what happens if you are using the classic static control. However, there is a typo in the the fancy themed static control, and it sets the <code>ODS_DISBALED<\/code> flag incorrectly. If you are owner-drawing a themed static control, and you want to draw differently depending on whether the control is disabled, then you should ignore the <code>ODS_DISABLED<\/code> flag and instead draw the disabled state based on the result of calling <code>Is&shy;Window&shy;Enabled<\/code> function.<\/p>\n<p> The bug in the themed static control cannot be fixed for compatibility reasons. I can pretty much guarantee that there is some application which doesn&#8217;t draw correctly if the <code>ODS_DISABLED<\/code> flag is not set. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The DRAW&shy;ITEM&shy;STRUCT structure has an item&shy;State member which contains a number of bits describing the state of the item being drawn. How do those states map to the underlying control? Most of the states are rather obvious. For a list box item to be selected, it means that the item is part of the selection. [&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-43423","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The DRAW&shy;ITEM&shy;STRUCT structure has an item&shy;State member which contains a number of bits describing the state of the item being drawn. How do those states map to the underlying control? Most of the states are rather obvious. For a list box item to be selected, it means that the item is part of the selection. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43423","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=43423"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43423\/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=43423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=43423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=43423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}