MFC: RadioButton not working (grayed out) in class subclasses CWnd

INTRODUCTION . I have a class (custom window) derived from CWND. This custom class has a switch (CButton) and a bunch of other static controls.

PROBLEM . When you create a switch, it becomes unavailable and clicking does nothing. The code used to create it is pretty simple:

m_radioButton->Create(_T("rButton1.1"), WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON , CRect(5,5,300,15), this,2001);

I tried to add

ON_BN_CLICKED (2001, method ())

but it does not work.

I also have ShowWindow () and EnableWindow () methods, but that didn't work either.

QUESTION . Since this class is not derived from CDialog, DDX is not available. Could this be a problem? Is there any way around this? My message card has only SIZE, CREATION and DESTRUCTION, except ON_BN_CLICKED.

Any suggestion is welcome.

BIG NOTE : MFC newbie is here, your help is much appreciated.

Research . I only found this important stack overflow question , but that doesn't help my case. Also stumbled upon this cool page in a subclass of mfc , but it doesn't answer my question.

BIG QUESTION . Since I do not receive answers, is this situation really not so widespread, and it is fundamentally wrong if I do not receive from CWND at all and receive from CDialog or something else?

+4
1

, . CWnd . , "CTestWindow", CWnd, OnCreate() CTestWindow. () .

IMPLEMENT_DYNAMIC(CTestWindow,CWnd)
BEGIN_MESSAGE_MAP(CTestWindow, CWnd)
    ON_WM_CREATE()
    ON_BN_CLICKED(2001, method)
END_MESSAGE_MAP()

int CTestWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    CButton *m_radioButton = new CButton;
    if (CWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
    if(!m_radioButton->Create(_T("rButton1.1"), WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON , CRect(5,5,300,25), this,2001)){
        return -1;
    }
    return 0;
}

void CTestWindow::method(){
    AfxMessageBox(_T("I m clicked"));
}

:

CString strMyClass;
    try
    {
        strMyClass = AfxRegisterWndClass(
            CS_VREDRAW | CS_HREDRAW,
            ::LoadCursor(NULL, IDC_ARROW),
            (HBRUSH) ::GetStockObject(WHITE_BRUSH),
            ::LoadIcon(NULL, IDI_APPLICATION));
    }
    catch (CResourceException* pEx)
    {
        AfxMessageBox(_T("Couldn't register class! (Already registered?)"));
        pEx->Delete();
    }
    if(m_wndTest.Create(strMyClass,_T("Custom Window"),WS_OVERLAPPEDWINDOW | WS_VISIBLE,CRect(0,0,400,400),this,200,NULL) == -1){
        return;
    }
    m_wndTest.SetWindowPos(NULL,120,120,500,500,SWP_SHOWWINDOW);
0

All Articles