?
Solved

MFC: How to change BG color of a group-box (CStatic)

Posted on 2007-10-10
5
Medium Priority
?
6,262 Views
Last Modified: 2013-12-14
Hello,

I have a group-box in my MFC dialog box. Its variable is class CStatic.
I need to set the groupbox' background color to white.

How can I do that?

Thanks!
0
Comment
Question by:OhadA
  • 3
5 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 20047394
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 20047406
Change the id of your static from IDC_STATIC to IDC_STATIC_NEW

/ Dlg Bg Color using OnCtlColor mapping
HBRUSH CSampleDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

   if (pWnd->GetDlgCtrlID() == IDC_STATIC_NEW)
   {
      m_Brush = CreateSolidBrush(...); / / You can create this OnInitDialog Also
      // Return handle to our CBrush object
      hbr = m_brush;
   }
   return hbr;
}
0
 

Author Comment

by:OhadA
ID: 20047498
Thanks buddies.
I tried this code:

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

   if (pWnd->GetDlgCtrlID() == IDC_INNERFRAME)
   {
      HBRUSH m_Brush = CreateSolidBrush(RGB(255, 255, 255)); // You can create this OnInitDialog Also
      // Return handle to our CBrush object
      hbr = m_Brush;
   }
   return hbr;
}

I've put a breakpoint in the createsolidbrush line, and it actually reaches there. But I see to effect. The background isn't white, just the normal gray.

What could be the problem?
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 2000 total points
ID: 20048593
can you try the same for a static label? so we can make sure this issue only there for the static frame.
0
 
LVL 3

Expert Comment

by:Adrien de Croy
ID: 20097653
are you running any other GUI libraries?  e.g CodeJock libraries with Skins turned on will override this method.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

839 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