//In class declaration (.H file ).private :CButton* m _pButton ;//In class implementation (.cpp file ) .m_pButton =new CButton ;ASSERT_VALID (m_pButton);m_pButton —>Create (_T ("Button Title ") , WS_CHILD |WS_VISIBLE |BS_PUSHBUTTON.Crect ( 0, 0, 100 , 24) , this , IDC _MYBUTTON )
{
// TODO: Add your specialized code here and/or call the base class
//m_pButton 为按钮CButton实例变量。
if(pMsg->hwnd==m_pButton.m_hWnd){
if(pMsg->message==WM_LBUTTONUP){
CRect rect;
m_pButton.GetWindowRect(&rect);
if(rect.PtInRect(pMsg->pt)){ // add you code here
return true;
}
}
if(pMsg->message==WM_KEYDOWN){
// add you code here
return true;
}
}
//
//
return CDialog::PreTranslateMessage(pMsg);
}