Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2010: Checkboxes have gray background on the white Tab in dialog. How to fix it?

I am adding a new dialog to the C++ application (Visual Studio 2010). I cannot get rid of the gray background of checkboxes that are placed on the tab that is white by default:

Dialog being edited in the resource editor

The related text in the .rc file is the following:

IDD_ExportHTML DIALOGEX 164, 128, 292, 136
STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | WS_POPUP | WS_CAPTION | WS_SYSMENU
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
    LTEXT           "statFileName0",102,9,9,59,8
    LTEXT           "statFileName",101,9,20,190,8
    CONTROL         "",150,"SysTabControl32",TCS_RAGGEDRIGHT,11,38,201,92
    DEFPUSHBUTTON   "btnOK",IDOK,241,97,45,15
    PUSHBUTTON      "btnCancel",IDCANCEL,241,115,45,15
    CONTROL         "chboxLines",106,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,34,71,135,12
    CONTROL         "chboxBackground",107,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,34,84,135,12
    CONTROL         "chboxPaging",108,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,34,98,135,12
END

It behaves the same way when the application runs. What should I set or do tell the checkboxes they are children of the tab? Or how can I fix the problem

Thanks for your time and experience, Petr

like image 741
pepr Avatar asked Sep 13 '12 12:09

pepr


1 Answers

Do something like this:

HBRUSH CYourDialogHere::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{

    HBRUSH hbr = (HBRUSH)m_brush;
    CWnd *pCheckBox = GetDlgItem(IDC_CHECK1);  // put ID of your checkbox here.

    if (*pCheckBox == *pWnd)
    {
        pDC->SetBkColor(RGB(255, 0, 0));
    }
    else
        hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    return hbr;
}

More info is here

I don't know how much is your C++ skills, but you have to also add some lines in .h file of your project to include this OnCtlColor function and some change in message map of your dialog .cpp file.

like image 123
Vahid Farahmand Avatar answered Nov 06 '22 13:11

Vahid Farahmand