使用TrackMouseEvent()可定制窗口在鼠标离开时发送WM_MOUSELEAVE消息 

解决方案 »

  1.   

    overwrite WindowProc() 试试 
      

  2.   

    请看源码,原理查MSDN中的TrackMouseEvent
    void CMouseMoveDlg::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    LPTRACKMOUSEEVENT lpET=new TRACKMOUSEEVENT;
    lpET->cbSize=sizeof(TRACKMOUSEEVENT);
    lpET->dwFlags=TME_LEAVE;
    lpET->dwHoverTime=NULL;
    lpET->hwndTrack=this->m_hWnd;
    _TrackMouseEvent(lpET);
    CDialog::OnMouseMove(nFlags, point);
    }BOOL CMouseMoveDlg::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if (pMsg->message==WM_MOUSELEAVE)
    {
    MessageBox("鼠标移出了窗体");
             }
    return CDialog::PreTranslateMessage(pMsg);
    }
      

  3.   

    SetCapture()函数设置后,不论鼠标在不在窗口上,你的窗口都能接收到鼠标消息.
      

  4.   

    1:在OnLButtonDown()
    {
        SetCapture();
    }2: 在OnLButtonUp()
    {   if(GetCapture()==this)//在窗口中
       {
         ReleaseCapture();//判断是了释放
         ……;
         
       }} 就可知道鼠标在不在窗口中了。
      

  5.   

         LPTRACKMOUSEEVENT lpET=new TRACKMOUSEEVENT;
                             在函数体内重复使用new?不能在窗口创建时一次使用?
        lpET->cbSize=sizeof(TRACKMOUSEEVENT);
        lpET->dwFlags=TME_LEAVE;
        lpET->dwHoverTime=NULL;
        lpET->hwndTrack=this->m_hWnd;
        _TrackMouseEvent(lpET);
        CDialog::OnMouseMove(nFlags, point);