Note that there are some explanatory texts on larger screens.

plurals
  1. POChange Color of read only CEdit control Artifacts and Text Highlighting issue
    text
    copied!<p>I have an Edit control that is read only that has text in it. I would like to switch the default gray background to white but have been having limited luck. In my first go, I was executing the following code during initialization of the dialog:</p> <pre><code>CEdit *m_ctrlEditOne = (CEdit*) GetDlgItem(IDC_EDIT1); CDC *m_ctrlEEditWee = m_ctrlEditOne-&gt;GetDC(); m_ctrlEEditWee-&gt;SetBkColor(RGB(255,0,0)); Invalidate(true); </code></pre> <p>Another solution I tried was:</p> <pre><code>HBRUSH CTestingDlg::OnCtlColor(CDC* pDC, CWnd *pWnd, UINT nCtlColor) { if (pWnd-&gt;GetStyle() &amp; ES_READONLY) //if(pDC-&gt;GetRuntimeClass == &amp; ES_READONLY) { switch (nCtlColor) { case CTLCOLOR_STATIC: pDC-&gt;SetBkColor(RGB(255,255,255)); return (HBRUSH)GetStockObject(NULL_BRUSH); default: //return NULL; return CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } } //return NULL; return CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } </code></pre> <p>In the screenshot below, you can see that the text is inserted after the fact (this is what needs to happen) and appears highlighted in blue - I have no idea where to begin on how to make it just appear as normal, non-highlighted text. When clicking on it, it appears normally. In the bottom left corners of each edit control, one can see a square which should not be appearing there. Also, you can see some artifacts of what looks like to be a combo box dropdown selection appearing in the larger boxes.</p> <p><img src="https://i.stack.imgur.com/uwCoo.png" alt="enter image description here"></p> <p>I would appreciate any pointers on how to get rid of the artifacts and fix the highlighting issue with inserted text.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload