Clistbox greying
-
How do a grey a CListBox based on some option , say option A the ListBox should be enabled with Window color as bg for option B, the listbox should be disabled with btn face color and all list items also greyed..like a greyed edit box PS its CListBox not a CListCtrl
-
How do a grey a CListBox based on some option , say option A the ListBox should be enabled with Window color as bg for option B, the listbox should be disabled with btn face color and all list items also greyed..like a greyed edit box PS its CListBox not a CListCtrl
I don't know if I exactly understood what you want to do, but if you want to enable or disable the control you can use the
EnableWindow()
function, e.g.:void EnableMyListBox()
{
myListBox.EnableWindow(TRUE);
}void DisableMyListBox()
{
myListBox.EnableWindow(FALSE);
}When you disable the listbox it will be grayed out. Hope it'll help! Regards, mYkel
-
I don't know if I exactly understood what you want to do, but if you want to enable or disable the control you can use the
EnableWindow()
function, e.g.:void EnableMyListBox()
{
myListBox.EnableWindow(TRUE);
}void DisableMyListBox()
{
myListBox.EnableWindow(FALSE);
}When you disable the listbox it will be grayed out. Hope it'll help! Regards, mYkel
-
True, but I want the background to be greyed as well. If I do a fillrect with a brush (COLOR_BTNFACE), EnableWindow(FALSE) still causes it to have a white background even though the listbox is disabled.
See
CWnd::OnCtlColor()
documentation. I don't have experiences with it but, it could solve your problem. Robert-Antonio "CRAY is the only computer, which runs an endless loop in just 4 hours" -
True, but I want the background to be greyed as well. If I do a fillrect with a brush (COLOR_BTNFACE), EnableWindow(FALSE) still causes it to have a white background even though the listbox is disabled.
As another poster said you can use the
OnCtlColor()
method for this. Assuming you have a button for changing between the grayed and not grayed state like this:void CListBoxGrayingTestDlg::OnButtonGray()
{
// TODO: Add your control notification handler code hereif(m\_bGrayed) { m\_bGrayed = FALSE; m\_MyListBox.EnableWindow(TRUE); } else { m\_bGrayed = TRUE; m\_MyListBox.EnableWindow(FALSE); }
}
Adding a message handler for
WM_CTLCOLOR
you can now do something like this:HBRUSH CListBoxGrayingTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// Set background transparent
pDC->SetBkMode(TRANSPARENT);
if (pWnd->GetDlgCtrlID() == IDC_MYLISTBOX)
{
if(m_bGrayed)
return (HBRUSH)GetStockObject(GRAY_BRUSH);
else
return (HBRUSH)GetStockObject(WHITE_BRUSH);
}
// TODO: Return a different brush if the default is not desired
return hbr;
}Now the background will be grayed, when the control is disabled... ;) Regards, mYkel