AndyAinscow
asked on
OnCtlColor and multiline edit - odd behaviour
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.CreateSoli dBrush(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
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.CreateSoli
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
You're welcome - I'm glad I could help you ...
have a nice day,
best regards,
ZOPPO
have a nice day,
best regards,
ZOPPO
ASKER
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.