0

I have two classes. class DialogBase is inherited from CDialog class DialogDerived is inherited from DialogBase.

BOOL DialodDervied::OnInitDialog()
{
     CDialogBase::OnInitDialog();
     //Add Dynamic Control to Main Dialog from here
}

I want to dynamically add a check box in the Dialog (CDialogBase) when it is called through the derived class. Is it possible? If yes, how?

1 Answer 1

2

Declare a member variable CButton m_ctrl_chk, override DialodDervied::OnCreate() and add code like

int DialodDervied::OnCreate(LPCREATESTRUCT lpCreateStruct)
{    if (CDialogEx::OnCreate(lpCreateStruct) == -1)
        return -1;

    m_ctrl_chk.Create(_T("Checkmate"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX,
        CRect(5, 5, 100, 20), this, 1234); // the 1234 value is the ID of the control

    return 0;
}

Use similar classes (CEdit, CStatic, CButton, ...) to create other type of controls in the same way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.