Solved

OnCtlColor and multiline edit - odd behaviour

Posted on 2010-08-25
4
849 Views
Last Modified: 2013-11-20
I have a multi line edit control on a dialog (no subclassing of the edit control).  In the dialog I have the following code

HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
      HBRUSH hbr = CMyDlg::OnCtlColor(pDC, pWnd, nCtlColor);

      // TODO:  Change any attributes of the DC here
      if(nCtlColor == CTLCOLOR_STATIC)
      {.....
      }
      else if(nCtlColor == CTLCOLOR_EDIT)
      {
            UINT nID = pWnd->GetDlgCtrlID();
            switch(nID)
            {
            case IDC_EDIT_BENEFICIARY:
                  pDC->SetBkMode(TRANSPARENT);
                  return (HBRUSH)m_brBeneficiary;
            }
      }

where m_brBeneficiary is a CBrush aand set as follows in the c'tor
      m_brBeneficiary.CreateSolidBrush(RGB(255, 0, 0));


When I type into the edit control I get text as in picture 1 (sort of bold font - WRONG), now if I select some text in the control the font appears as I want it to appear see picture 2.  <Picture 3 shows what happens without the OnCtlColor>

Any ideas what is going on and more important how to get it to work correctly.

VS 2005 on Windows 7


0010.jpg
0011.jpg
0012.jpg
0
Comment
Question by:AndyAinscow
  • 2
  • 2
4 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 33520927
Hi Andy,

I think the problem is the 'pDC->SetBkMode(TRANSPARENT);' because this causes the control to draw the entered text just over the existing (and I guess for some reason the font mapping makes the font getting bold after some entered text) - you can simply verify this by entering some text and then deleting using backspace ...

So I would suggest to not use 'pDC->SetBkMode(TRANSPARENT);' - instead use 'SetBkColor' to set the text's background color to the same as the brush's color, i.e. 'pDC->SetBkColor(RGB( 255, 0, 0 ));' for a red filled edit control.

Hope that helps,

ZOPPO
0
 
LVL 44

Author Comment

by:AndyAinscow
ID: 33521171
And I thought I had tried all possibles

this doesn't work
            pDC->SetBkColor(RGB(255, 0, 0));
//            pDC->SetBkMode(TRANSPARENT);
//            return (HBRUSH)m_brBeneficiary;


but this does
            pDC->SetBkColor(RGB(255, 0, 0));
//            pDC->SetBkMode(TRANSPARENT);
            return (HBRUSH)m_brBeneficiary;



Set the bkcolor AND supply the brush is required.


0
 
LVL 44

Author Closing Comment

by:AndyAinscow
ID: 33521177
Thanks
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 33521221
You're welcome - I'm glad I could help you ...

have a nice day,

best regards,

ZOPPO
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 96
pre4 challenge 19 100
abstract class with all non abstract mentods 6 76
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 253
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question