RT.
自己写了个按钮类.
class CMyButton : public CBitmapButton然后在void CMyButton::OnLButtonDown(UINT nFlags, CPoint point)中
我想通知父窗口该按钮已被按下,该如何做?默认的CMyButton::OnLButtonDown(UINT nFlags, CPoint point)会调用CBitmapButton::OnLButtonDown(nFlags, point).
但有时有反应,有时没反映.能否通过发送WM_COMMAND通知父窗口?这样的话WM_COMMAND的wParam和lParam该怎么获得?比如下面的Control identifier.
wParam (high word)                | wParam (low word)  | lParam 
Control-defined notification code | Control identifier | Handle to the control window 

解决方案 »

  1.   

    LRESULT CALLBACK WindowProc(
      HWND hwnd,       // handle to window
      WM_COMMAND,      // the message to send
      WPARAM wParam,   // notification code and identifier
      LPARAM lParam    // handle to control (HWND)
    );wParam 是按钮的ID
    lParam 是按钮的句柄。
      

  2.   

    默认的CMyButton::OnLButtonDown(UINT nFlags, CPoint point)会调用CBitmapButton::OnLButtonDown(nFlags, point). 
    但有时有反应,有时没反映. 如果是这种情况的话,发送消息也是一样,最好就是看看为什么会发生这种情况
      

  3.   

    CMyButton会自动通知父窗口按钮已被按下的,父窗口响应NM_CLICK消息。
    不需要你在向父窗口发送什么消息。
      

  4.   

    CBitmapButton并不是CMyButton的父窗口。建议直接向CMyButton的父窗口GetParentOwner发送消息。
      

  5.   

    可以试下在PreTranslateMessage里捕获WM_LBUTTONDOWN
      

  6.   

    刚试过每次都能响应
    .h文件class CMyBitmapBtn : public CBitmapButton
    {
    // Construction
    public:
    CMyBitmapBtn();// Attributes
    public:// Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMyBitmapBtn)
    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~CMyBitmapBtn(); // Generated message map functions
    protected:
    //{{AFX_MSG(CMyBitmapBtn)
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    //}}AFX_MSG DECLARE_MESSAGE_MAP()
    };.cpp
    [code=c/c++]
    CMyBitmapBtn::CMyBitmapBtn()
    {
    }CMyBitmapBtn::~CMyBitmapBtn()
    {
    }
    BEGIN_MESSAGE_MAP(CMyBitmapBtn, CButton)
    //{{AFX_MSG_MAP(CMyBitmapBtn)
    ON_WM_LBUTTONDOWN()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMyBitmapBtn message handlersvoid CMyBitmapBtn::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    MessageBox("ButtonDown");
    CButton::OnLButtonDown(nFlags, point);
    }
    [code]对话框的按钮 关联一个 CMyBitmapBtn 类型类型的 变量就行了,
    不知道楼主要干啥不用在 CMyBitmapBtn里加 lbuttonDown消息吧???
    TO :tttyd (雪影) 天天看你回帖不用上班呀??
      

  7.   


    void CMyBitmapBtn::OnLButtonDown(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default
    MessageBox("ButtonDown");
    CButton::OnLButtonDown(nFlags, point);
    }[/Quote]这里吧,俺的是CBitmapButton::OnLButtonDown(nFlags, point);应该就是这个函数帮俺通知的父窗口吧?
    假如想把CBitmapButton::OnLButtonDown(nFlags, point);注释掉,自己发消息给父窗口呢?应该是别的什么地方出问题了.俺再试试.CBitmapButton::OnLButtonDown(nFlags, point);里面应该是发送一个WM_COMMAND消息给父窗口吧,不知怎么实现的..to 1楼:
    LRESULT CALLBACK WindowProc( 
      HWND hwnd,      // handle to window 
      WM_COMMAND,      // the message to send 
      WPARAM wParam,  // notification code and identifier 
      LPARAM lParam    // handle to control (HWND) 
    ); wParam 是按钮的ID 
    lParam 是按钮的句柄。俺就是不懂怎么得到当前自定义按钮类所关联的资源的ID,以为这个类关联了很多IDC_BTN_XXX之类.
      

  8.   

    如果你想让这个控件在窗口函数里响应鼠标消息。FMC程序的话直接双点对话框上的按钮控件 直接添加就行?只要把控件关联个 CBitmapButton 变量就行,不知道楼主具体要干啥
      

  9.   

    已经将控件关联CMyButton类了.
    就是有时点下去没反应.
      

  10.   

    把按钮关联的变量删除呢?每次点都有反映吗?如果还是有时不反映的话就不是CMyButton的事。
      

  11.   

    找到了,是把按钮的OwnerDraw设成TRUE就变这样了,经常点下去没反应..
    有人遇到过么?