title: How to SetFocus to a CButton so that the border and focus dotted line are visible?
body: <p>I created a simple dialog-based application, and in the default CDialog added three buttons (by drag-and-dropping them) using the Visual Studio editor. </p>
  
  <p>The default OK and Cancel buttons are there too.</p>
  
  <p>I want to set the focus to button 1 when I click button 3.</p>
  
  <p>I set the property Flat to true in the properties for muy buttons.</p>
  
  <p>I coded this:</p>
  
  <pre><code>void CbuttonfocusDlg::OnBnClickedButton3()
  {
      // TODO: Add your control notification handler code here
      GetDlgItem(IDC_BUTTON1)-&gt;SetFocus();
  
      Invalidate();
  
  }
  </code></pre>
  
  <p>But the boder in button1 is never drawn. The caret (the dotted line indicating focus) is only drawn if I pressed TAB any time before clicking button 3. </p>
  
  <p>I want the button to look exactly as it looks after I click it. Showing the dotted line inside the button programatically, would be a plus.</p>
  
  <p>What I want:</p>
  
  <p><a href="https://i.stack.imgur.com/z8l0f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z8l0f.png" alt="http://i33.tinypic.com/11t8pkl.png"></a>
  </p>
  
  <p>What I get: </p>
  
  <p><a href="https://i.stack.imgur.com/CgqLi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CgqLi.png" alt="http://i37.tinypic.com/160q5hw.png"></a>
  </p>