你的rect是基于screen的还是client的。转换一下。

解决方案 »

  1.   

    我知道啊,lParam是客户区的,我也用ClientToScreen(hwnd,&point)换过了,并且调试的时候,我一出BUTTON区域,在立刻发生的WM-MOUSEMOVE中断处,查到point刚好是BUTTON的边界!这到底是怎么回事啊??
      

  2.   

    我怀疑你的响应的不是BUTTON的MOUSEMOVE,而是它父窗口的MOUSEMOVE.
      

  3.   

    是不是这个消息被Button自己capture了?
      

  4.   

    to shesh(无所谓),对对,我响应的是父窗口的MOUSEMOVE,我可以响应BUTTON的MOUSEMOVE吗?愿闻其详!解决后必以全分奉上!
      

  5.   

    那你要重载CButton了,不用MFC的话,偶不懂。
      

  6.   

    过程是这样的:
    point.x = LOWORD(lParam);
    point.y = HIWORD(lParam);
    rect = GetWindowRect(hButtuon,&rect);
    ClientToScreen(hwnd,&point);
    有问题吗?可就是不行啊!
      

  7.   

    在CButton类的派生类中重载PreTranslateMessage(),在里面捕获之,也可以自己仿照APPWIZARD建立的代码建立消息映射,通过消息映射处理这个消息
      

  8.   

    对话框捕获了mousemove消息 or Mr_Bomber is right
      

  9.   

    重载CButton类,响应WM_MOUSEMOVE消息和WM_MOUSELEAVE(未公开消息,在鼠标离开窗口时响应)。
      

  10.   

    SDK的话,用SetWindowLong给Button设置自己的消息处里函数吧,WM_MOUSEMOVE不是Notify类型的消息,不会发给父窗口的,不能直接定义消息映射
      

  11.   

    http://www.csdn.net/expert/topic/411/411075.shtm
    代码有13000行的超cool表格程序,如何开发成activeX控件,有兴趣的人留下email,我把源程序发给你们
    分数为150分
    十万火级,如能给出答案,再送300分
    有兴趣的人留下email
    我把程序发给你们。 
    一个很cool的表格程序,请问如何改为activeX控件,有兴趣的我把源代码发给你们,感兴趣的人留下email,
    是vc写的非常cool  
      

  12.   

    鼠标移动到button上时,button 就将鼠标这是的移动消息截获了,换句话说,button 也是一个窗口,此时鼠标消息被这个窗口处理。而此时button这个wnd没有重载OnMouseMove函数的话,就处理不了MouseMove事件了。鼠标移动到button边界后从button窗口进入到了父窗口,这时父窗口处理MouseMove事件,所以会调用OnMouseMove函数。其实你只要只在button里重载OnMouseMove函数就能实现的,你可以试一下
      

  13.   

    to kingtsui,我在写SetWindowLong设置的消息处理函数时遇到问题了,程序怎么就不调用我的处理函数?我是在创建窗口的同时,调用SetWindowLong的,然后在消息处理函数的WM_DRAWITEM的消息里画BUTTON,可是画不出。
      

  14.   

    to Martens,我是用SDK的,你能从SDK的角度给我解释吗?谢谢了!
      

  15.   

    欧不懂咧,呵呵,非用SDK不可吗?
      

  16.   

    在MFC中用BUTTON的父类(对话框)SUBCLASSDLGITEM。
    实际上就是SDK中调用SETWINDOWLONG,见MFC\SRC\WINCORE.CPP中的函数实现。
      

  17.   

    建议重载CButton
    #if !defined(AFX_MYBUTTON_H__7C6D5CAA_A730_4F48_835F_956D31ECA192__INCLUDED_)
    #define AFX_MYBUTTON_H__7C6D5CAA_A730_4F48_835F_956D31ECA192__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // MyButton.h : header file
    ///////////////////////////////////////////////////////////////////////////////
    // CMyButton windowclass CMyButton : public CButton
    {
    // Construction
    public:
    CMyButton();// Attributes
    public:// Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMyButton)
    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~CMyButton(); // Generated message map functions
    protected:
    //{{AFX_MSG(CMyButton)
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg void ParentNotify(UINT message, LPARAM lParam);
    //}}AFX_MSG DECLARE_MESSAGE_MAP()
    };///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MYBUTTON_H__7C6D5CAA_A730_4F48_835F_956D31ECA192__INCLUDED_)
    // MyButton.cpp : implementation file
    //#include "stdafx.h"
    #include "MyView.h"
    #include "MyButton.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CMyButtonCMyButton::CMyButton()
    {
    }CMyButton::~CMyButton()
    {
    }
    BEGIN_MESSAGE_MAP(CMyButton, CButton)
    //{{AFX_MSG_MAP(CMyButton)
    ON_WM_MOUSEMOVE()
    ON_WM_PARENTNOTIFY_REFLECT()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMyButton message handlersvoid CMyButton::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CString str;
    str.Format("x=%d,y=%d",point.x,point.y);
    SetWindowText(str);
    CButton::OnMouseMove(nFlags, point);
    }void CMyButton::ParentNotify(UINT message, LPARAM lParam) 
    {
    // TODO: Add your message handler code here

    }#if !defined(AFX_MYDLG_H__2BE49736_563A_4BAC_9388_62D53CF5473F__INCLUDED_)
    #define AFX_MYDLG_H__2BE49736_563A_4BAC_9388_62D53CF5473F__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // MyDlg.h : header file
    //
    #include "mybutton.h"
    /////////////////////////////////////////////////////////////////////////////
    // CMyDlg dialogclass CMyDlg : public CDialog
    {
    // Construction
    public:
    CMyDlg(CWnd* pParent = NULL);   // standard constructor// Dialog Data
    //{{AFX_DATA(CMyDlg)
    enum { IDD = IDD_DIALOG1 };
    CMyButton m_button;
    //}}AFX_DATA
    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMyDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected: // Generated message map functions
    //{{AFX_MSG(CMyDlg)
    afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };//{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MYDLG_H__2BE49736_563A_4BAC_9388_62D53CF5473F__INCLUDED_)// MyDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "MyView.h"
    #include "mybutton.h"
    #include "MyDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CMyDlg dialog
    CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CMyDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CMyDlg)
    //}}AFX_DATA_INIT
    }
    void CMyDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CMyDlg)
    DDX_Control(pDX, IDC_BUTTON2, m_button);
    //}}AFX_DATA_MAP
    }
    BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
    //{{AFX_MSG_MAP(CMyDlg)
    ON_WM_SHOWWINDOW()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMyDlg message handlersvoid CMyDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
    {
    CDialog::OnShowWindow(bShow, nStatus);

    // TODO: Add your message handler code here
    //ShowWindow(SW_SHOWMAXIMIZED);
    }