how to grey check box in visual c++ 5.0

I would like to, when loading dialog box (property page) after checking status of check box to, if it is checked to grey it to ptevent editing. (once checked, can not be unchecked any more)

Compailer is visual c++ 5.0 OS windows NT

mzdravkoAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
inprasConnect With a Mentor Commented:
Hi
Try doing this
//Explicitly checking check box
       m_Check.SetCheck(1);
//If checked then disable
      if( m_Check.GetCheck())
      {
            m_Check.EnableWindow(FALSE);
      }

Regards
0
 
mzdravkoAuthor Commented:
Hi Inpras,

I have already done that. I just wanted to ask for a way ti amke it grey. It is already disabled with EnableWindow(FALSE) but it is still in white color. I need to be grey to show user that it can not be changed.

Sorry for missunderstanding

regards
0
 
SDUCommented:
Try this:
Note, I don't know the RGB for grey but that should not be a problem to find

Add a member variable like this
   CBrush                  m_WhiteBrush;

in your OnInitDialog,
   m_WhiteBrush.CreateSolidBrush(RGB(255,255,255));   // This brusk is white


then add this method
HBRUSH YourClass::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
      HBRUSH hbr = YourBaseClass::OnCtlColor(pDC, pWnd, nCtlColor);

   if ( pWnd->GetDlgCtrlID() == IDC_YOUR_CTL_ID )
   {
      if ( nCtlColor == CTLCOLOR_STATIC )
      {
         pDC->SetBkColor(RGB(255,255,255));  // This background is white
         hbr = m_WhiteBrush;
      }
   }

   return hbr;
}

It worked for me when I wanted to have a readonly edit box with a white background
0
 
inprasCommented:
Hi mzdravko

1 Create a brush with grey color


2 map the OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)

in this fn write the fol code
      if (pWnd->GetDlgCtrlID() == IDC_CHECK1)      
      {
//You can check here for the getcheck
if(m_Check.GetCheck())
{
            pDC->SetBkColor("Your color");
            hbr = m_WtB;
}
      }
and to prevent user to change it
//in onclick event
3 void CCheckDlg::OnCheck1()
{
      if( !m_Check.GetCheck())
      {
            m_Check.SetCheck(TRUE);
      }
}
Hope this helps

Regards
0
All Courses

From novice to tech pro — start learning today.