mzdravko
asked on
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
Compailer is visual c++ 5.0 OS windows NT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.CreateSolidBr ush(RGB(25 5,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,25 5,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
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.CreateSolidBr
then add this method
HBRUSH YourClass::OnCtlColor(CDC*
{
HBRUSH hbr = YourBaseClass::OnCtlColor(
if ( pWnd->GetDlgCtrlID() == IDC_YOUR_CTL_ID )
{
if ( nCtlColor == CTLCOLOR_STATIC )
{
pDC->SetBkColor(RGB(255,25
hbr = m_WhiteBrush;
}
}
return hbr;
}
It worked for me when I wanted to have a readonly edit box with a white background
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
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
ASKER
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