实现了一个类:CHIDE类,继承自: public CButton(按钮的CHide类)
class CHide : public CButton { // Construction public: CHide(); // Attributes public: CHide *pBtn; // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CHide) //}}AFX_VIRTUAL // Implementation public: virtual ~CHide(); // Generated message map functions protected: //{{AFX_MSG(CHide) afx_msg void OnMouseMove(UINT nFlags, CPoint point); //}}AFX_MSG DECLARE_MESSAGE_MAP() };
按钮指针:
public: CHide *pBtn;
鼠标移动消息:
BEGIN_MESSAGE_MAP(CHide, CButton) //{{AFX_MSG_MAP(CHide) ON_WM_MOUSEMOVE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CHide message handlers void CHide::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default pBtn->ShowWindow(SW_SHOW);//显示 ShowWindow(SW_HIDE);//隐藏 CButton::OnMouseMove(nFlags, point); }
主对话框中引入头文件:
#include "Hide.h"
在主对话框中只在初始化函数中实现了:
// TODO: Add extra initialization here m_btn1.pBtn=&m_btn2; m_btn2.pBtn=&m_btn1;
m_btn2的地址给m_btn1的CHide 类型指针 pBtn