views:

289

answers:

1

Hi, I have derived a CButton class and created my own radion button control. Its all working nicely with the exception that I can't get the parent dialog to detect when the radio button it clicked.

The parent dialog will detect the radio button click if I call CButton::OnLButtonUp() but the problem in doing that is that the framework also draws the radio button as well. I don't want to do that as I am drawing the radio button myself.

Can somebody please tell me how to stop Windows/MFC framework from drawing the control in this case? If I don't call CButton::OnLButtonUp() then yeah, Windows/MFC won't draw the control but my parent dialog won't get a BN_CLICKED notification either.

I know I could send a custom message back to my dialog but I don't want that - I want compatability with the BN_CLICKED message.

As you will see below, I have also tried posting a message back to the owning dialog and this doesn't work either.

void CNCCheckBox::OnLButtonUp(UINT nFlags, CPoint point) 
{
  if( m_Owner )
    m_Owner->PostMessage( BN_CLICKED, (WPARAM) IDC_RAD_1/*GetDlgCtrlID()*/, (LPARAM) this->m_hWnd );
  //CButton::OnLButtonUp(nFlags,point); // Can't use this!!
}
A: 

I've solved it. I got rid of OnDrawItem() (AFX_MSG), and added DrawItem (AFX_VIRTUAL) instead. Also, in PreSubClassWindow() I modify the style to the button is treated as a BS_PUSHBUTTON and BN_CLICKED events are now being sent to my parent dialog.

So in short: - Don't use OnPaint() - Don't use OnDrawItem() - Use:

//{{AFX_VIRTUAL(CNCCheckBox)
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
SparkyNZ