Solved

OnCtlColor and multiline edit - odd behaviour

Posted on 2010-08-25
4
853 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sum13 challenge 24 149
abstract class with all non abstract mentods 6 87
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 1,690
Problem to App 4 145
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 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