Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

OnCtlColor and multiline edit - odd behaviour

Posted on 2010-08-25
4
Medium Priority
?
861 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 2000 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 45

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 45

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

963 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