{"id":994,"date":"2009-07-30T14:04:05","date_gmt":"2009-07-30T12:04:05","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=994"},"modified":"2009-08-29T16:09:53","modified_gmt":"2009-08-29T14:09:53","slug":"combo-box-selection-wm_setredraw-and-cb_setcursel","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/994","title":{"rendered":"Combo Box selection, WM_SETREDRAW and CB_SETCURSEL"},"content":{"rendered":"<p>Given the combo box initialization code:<\/p>\n<pre>m_ComboBox<span style=\"color: #808030;\">.<\/span>SetRedraw<span style=\"color: #808030;\">(<\/span>FALSE<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nm_ComboBox<span style=\"color: #808030;\">.<\/span>ResetContent<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #800000; font-weight: bold;\">for<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #603000;\">INT<\/span> nIndex <span style=\"color: #808030;\">=<\/span> <span style=\"color: #008c00;\">0<\/span><span style=\"color: #800080;\">;<\/span> nIndex <span style=\"color: #808030;\">&lt;<\/span> <span style=\"color: #008c00;\">3<\/span><span style=\"color: #800080;\">;<\/span> nIndex<span style=\"color: #808030;\">+<\/span><span style=\"color: #808030;\">+<\/span><span style=\"color: #808030;\">)<\/span>\r\n    m_ComboBox<span style=\"color: #808030;\">.<\/span>AddString<span style=\"color: #808030;\">(<\/span>AtlFormatString<span style=\"color: #808030;\">(<\/span>_T<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">Item <\/span><span style=\"color: #0f69ff;\">%d<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> nIndex <span style=\"color: #808030;\">+<\/span> <span style=\"color: #008c00;\">1<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nm_ComboBox<span style=\"color: #808030;\">.<\/span>SetCurSel<span style=\"color: #808030;\">(<\/span><span style=\"color: #008c00;\">1<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nm_ComboBox<span style=\"color: #808030;\">.<\/span>SetRedraw<span style=\"color: #808030;\">(<\/span>TRUE<span style=\"color: #808030;\">)<\/span><\/pre>\n<p>How the combo box is going to look like?<\/p>\n<p><!--more-->Here it goes:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-995 alignnone\" title=\"ComboBoxSample01 #1\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2009\/07\/image001.png\" alt=\"ComboBoxSample01 #1\" width=\"300\" height=\"129\" \/><\/p>\n<p>Combo box won&#8217;t repaint window on SetRedraw(TRUE) AKA <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd145219%28VS.85%29.aspx\">WM_SETREDRAW<\/a>. But once you move a mouse pointer over the control, or tab to focus it, the correct selection will be painted, &#8220;Item 2&#8221;:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-996\" title=\"ComboBoxSample01 #2\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2009\/07\/image002.png\" alt=\"ComboBoxSample01 #2\" width=\"300\" height=\"129\" \/><\/p>\n<p>The control ignores the invalidation caused by <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb775899%28VS.85%29.aspx\">CB_SETCURSEL<\/a> message while processing final SetRedraw message. To avoid GUI glitches, for example, a m_ComboBox.Invalidate() or <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd145002%28VS.85%29.aspx\">InvalidateRect<\/a> might be called after SetRedraw(TRUE).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Given the combo box initialization code: m_ComboBox.SetRedraw(FALSE); m_ComboBox.ResetContent(); for(INT nIndex = 0; nIndex &lt; 3; nIndex++) m_ComboBox.AddString(AtlFormatString(_T(&#8220;Item %d&#8221;), nIndex + 1)); m_ComboBox.SetCurSel(1); m_ComboBox.SetRedraw(TRUE) How the combo box is going to look like?<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[81,229,226,227,99,150,228],"class_list":["post-994","post","type-post","status-publish","format-standard","hentry","category-wtl","tag-api","tag-cb_setcursel","tag-combo-box","tag-control","tag-gui","tag-windows","tag-wm_setredraw"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=994"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/994\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}