高手大侠:
   如题目,我再自定义了一个C++类并从CWnd继承下来得一个类CMyChart只能响应OnPaint()时间而WM_LBUTTONDOWN...等事件统统没有,虽然向导可以生成但是消息没有进来

解决方案 »

  1.   

    不行,我试过的,再消息处理上我完全遵照这VC的样子,定义AFX_MSG...在实现代码内油ON_MESAGE...
    消息就是不进来,会不会是我继承类有关系呢?
    如果我把CWnd改CEdit 或者CButton就可以响应鼠标按钮事件!
      

  2.   

    你可以重载PreTranslateMessage函数,在函数里面增加语句:
    if(pMsg->message == WM_LBUTTONDOWN)
    {//这里设置断点}
    如果能跟踪到该断点,说明可以,其他就不多说了
    ^_^  Good Luck
      

  3.   

    这个函数我已经跟踪过了,而且在那里等待这消息流进来,可惜我感兴趣的没有到来,等到的只有WM_PAINT这个消息,真的很郁闷!
      

  4.   

    高手请看这是生成的程序代码
    .h的定义
    class UCWnd : public CWnd
    {
    // Construction
    public:
    UCWnd();// Attributes
    public:// Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(UCWnd)
    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~UCWnd(); // Generated message map functions
    protected:
    //{{AFX_MSG(UCWnd)
    afx_msg void OnPaint();
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    //}}AFX_MSG DECLARE_MESSAGE_MAP()
    };.cpp的实现UCWnd::UCWnd()
    {
    }UCWnd::~UCWnd()
    {
    }
    BEGIN_MESSAGE_MAP(UCWnd, CWnd)
    //{{AFX_MSG_MAP(UCWnd)
    ON_WM_PAINT()
    ON_WM_CREATE()
    ON_WM_LBUTTONDOWN()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // UCWnd message handlersvoid UCWnd::OnPaint() 
    {
    CPaintDC dc(this); // device context for painting

    // TODO: Add your message handler code here
    //dc.TextOut(10,20,"HEllo WOrld");

    CRect rect;
    GetClientRect(&rect);
    dc.Ellipse(rect); // Do not call CWnd::OnPaint() for painting messages
    }int UCWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    if (CWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

    // TODO: Add your specialized creation code here


    return 0;
    }void UCWnd::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    AfxMessageBox("Hello WOrld");

    CWnd::OnLButtonDown(nFlags, point);
    }//对话框引用这个类 其中m_wndUC是UCWnd的实例DWORD dwStyle=WS_CHILDWINDOW|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN;
    CRect rect;
    GetClientRect(&rect);
    m_wndUC.Create("Static","UCWnd",dwStyle,rect,this,1000220,NULL);如果Static 改写Edit就可以响应鼠标按钮,但是画出的是一个EDIT的东西
    改成 ListBox就可以了也不影响使用又能响应消息,
    非常感谢 krh2001(边城浪子)!的提醒,