Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Setting a BGColor for my dialog changes my CEdit boxes backgrounds

Hello everyone,

I'm using the "OnCtlColor" function to modify my dialog background color, and this URL to change my background on the CEdit boxes:  http://www.codeproject.com/staticctrl/coloredit_colorstatic.asp#xx1234972xx

The bgcolor for the dialog window overwrites the background for the CEdit boxes. I just want a Red dialog window...with white CEdits boxes.

Can someone point me in the right direction please.  Thanks.
0
VirtueTech
Asked:
VirtueTech
  • 3
  • 2
  • 2
1 Solution
 
Knut HunstadCommented:
Your dialog's OnCtlColor will catch the WM_CTLCOLOR message instead of CColorEdit. You need to do something like this in the dialog's OnCtlColor:

   if (pWnd == &m_ebCtl) {
      pDC->SetTextColor(BLACK);
     return brWhite; // A white brush that exists throughout the dialogs lifetime
   }

or if you want to keep the Codeproject system, you could change CColorEdit::CtlColor to be public and then all you need is this change in the dialog's OnCtlColor:

   if (pWnd == &m_ebCtl)
      return m_ebCtl.CtlColor(pDC, nCtlColor);
0
 
VirtueTechAuthor Commented:
Well...see I am doing that in OnCtlColor

However whatever I set for the background of the dialog window....it is the same for the CEdit boxes. If I don't set the dialog BGColor then CEdits boxes backgrounds work perfectly. I can control their colors and everything.

When I color the dialog it seems as if the CEdits boxes are transparent. But the transparent option for the CEdit boxes is set to FALSE.
0
 
AlexFMCommented:
To change dialog background use OnEraseBkgnd function. OnCtlColor is used only for child controls.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Knut HunstadCommented:
I didn't say so, but my suggestion was based on an actual test, using the Codeproject solution and getting the exact same problem after defining OnCtlColor for the dialog. So I know his works, OnCtlColor is called for the dialog itself as well! Which doesn't mean AlexFM couldn't be right about using OnEraseBkgnd, I haven't tried that :-)

Here is my whole code for OnCtlColor, I guess I should have shown that:

HBRUSH CTest2Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // Not sure if this is really necessary, but it doesn't seem to hurt?
   if (pWnd == &m_ctlCColorEdit) // This is the CColorEdit control asking which color to use
      return m_ctlCColorEdit.CtlColor(pDC, nCtlColor); // note that you need to _return_ the brush, calling SetBkColor doesn't do it!
   return m_brBlue; // This is the brush for the dialog itself
}

and remember to change CtlColor for CColorEdit to public first.

Try this, or show us your version of OnCtlColor, I'm guessing you are missing some detail here! Or see if OnEraseBkgnd does the trick...
0
 
AlexFMCommented:
Right, OnCtlColor with nCtlColor = CTLCOLOR_DLG allows to change dialog background, assuming that OnEraseBkgnd is default.
"OnCtlColor is used only for child controls." This was mistake.
0
 
Knut HunstadCommented:
"So I know his works"

As a stand alone phrase, to my (non-english) ears this could sound like an accusation of some "he" doing things in not so good ways! Should be: "So I know this works", of course :-)

Better safe than sorry, I became victim of a nasty flame war (not on EE) because of a similar mistake once...
0
 
VirtueTechAuthor Commented:
Hey,

I must have been tired last night when I read your 1st reply. It made perfect sense this morning.

I have made the CColorEdit::CtlColor public and updated the mian dialog like you said.

It worked perfectly. Thanks for your time.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now