15,980
社区成员




void XCStatic::OnMouseMove(UINT nFlags,CPoint point)
{
CStatic::OnMouseMove(nFlags,point);
//如果鼠标还在窗口内
if(m_mousein)
{
CRect rect;
GetClientRect(rect);
//鼠标位置离开了客户区,解除鼠标捕获,并改写状态量m_bOverControl
if(!rect.PtInRect(point))
{
//this->SetWindowTextW(_T("鼠标移出"));
m_mousein= FALSE;
ReleaseCapture();
//其他鼠标离开时的操作
//eg: ReDrawWindow();
return;
}
this->SetWindowTextW(_T("还在里面"));
}
//如果鼠标进入窗口,置鼠标捕获,状态参量
else
{
m_mousein= TRUE;
//其他鼠标进入时的操作
this->SetWindowTextW(_T("鼠标刚移进来"));
SetCapture();
}
}
#if !defined(AFX_MYSTATIC_H__0DA3C73A_2538_46C5_9EE7_6E41E9DA3896__INCLUDED_)
#define AFX_MYSTATIC_H__0DA3C73A_2538_46C5_9EE7_6E41E9DA3896__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MyStatic.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CMyStatic window
class CMyStatic : public CStatic
{
// Construction
public:
CMyStatic();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyStatic)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMyStatic();
// Generated message map functions
protected:
//{{AFX_MSG(CMyStatic)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//}}AFX_MSG
afx_msg void OnMouseHover();
afx_msg void OnMouseLeave();
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MYSTATIC_H__0DA3C73A_2538_46C5_9EE7_6E41E9DA3896__INCLUDED_)
// MyStatic.cpp : implementation file
//
#include "stdafx.h"
#include "dlgprint.h"
#include "MyStatic.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyStatic
CMyStatic::CMyStatic()
{
}
CMyStatic::~CMyStatic()
{
}
BEGIN_MESSAGE_MAP(CMyStatic, CStatic)
//{{AFX_MSG_MAP(CMyStatic)
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_MOUSEHOVER,OnMouseHover)
ON_MESSAGE(WM_MOUSELEAVE,OnMouseLeave)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyStatic message handlers
void CMyStatic::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//SetWindowText("鼠标进入");
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = m_hWnd;
tme.dwFlags = TME_LEAVE | TME_HOVER;
tme.dwHoverTime = 1;
_TrackMouseEvent(&tme);
CStatic::OnMouseMove(nFlags, point);
}
void CMyStatic::OnMouseHover()
{
SetWindowText("鼠标进入");
}
void CMyStatic::OnMouseLeave()
{
SetWindowText("鼠标离开");
}