James A. Johnson
April 19th, 1999, 01:03 PM
To create a disabled control without the gray background and gray letters follow this tip.
Create a dialog control item with disabled un-checked. Then add a class to your dialog
to handle the WM_CTLCOLOR message. This will create a function for OnCtlColor().
Then use something like the following:
HBRUSH YourDialogBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // Copy the current color to the brush
CWnd* EditBox; // Create a CWnd Class to hold your controls data
// Only for Edit Controls
if(nCtlColor == CTLCOLOR_EDIT)
{
int ID = pWnd->GetDlgCtrlID(); // Get the dialog item ID
if(ID == IDC_EDIT1)
{
EditBox = GetDlgItem(IDC_EDIT1); // Populate the CWnd class
EditBox->ModifyStyle(NULL, WS_DISABLED, 0); // And set the window to disabled
pDC->SetTextColor(RGB(0,0,0)); // Set the Text color
hbr = CreateSolidBrush(RGB(255,255,255)); // and set the background color.
}
}
return hbr; // Return the new brush.
}
τΏτ
«=»
Create a dialog control item with disabled un-checked. Then add a class to your dialog
to handle the WM_CTLCOLOR message. This will create a function for OnCtlColor().
Then use something like the following:
HBRUSH YourDialogBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // Copy the current color to the brush
CWnd* EditBox; // Create a CWnd Class to hold your controls data
// Only for Edit Controls
if(nCtlColor == CTLCOLOR_EDIT)
{
int ID = pWnd->GetDlgCtrlID(); // Get the dialog item ID
if(ID == IDC_EDIT1)
{
EditBox = GetDlgItem(IDC_EDIT1); // Populate the CWnd class
EditBox->ModifyStyle(NULL, WS_DISABLED, 0); // And set the window to disabled
pDC->SetTextColor(RGB(0,0,0)); // Set the Text color
hbr = CreateSolidBrush(RGB(255,255,255)); // and set the background color.
}
}
return hbr; // Return the new brush.
}
τΏτ
«=»