我是VC2008
#include <afxwin.h>
#include<windows.h>
class CMyApp : public CWinApp
{
public:
    virtual BOOL InitInstance ();
};
class CMainWindow : public CFrameWnd
{
public:
    CMainWindow ();
      BOOL m_bMouseOver;
protected:
    afx_msg void OnPaint ();
        afx_msg int OnCreate(LPCREATESTRUCT);
        afx_msg void OnLButtonDown(UINT,CPoint);
        afx_msg void OnRButtonDown(UINT,CPoint);
afx_msg void OnMouseMove(UINT,CPoint);
afx_msg void OnMouseLeave();
afx_msg void OnMouseHover(UINT nFlags, CPoint point);    DECLARE_MESSAGE_MAP ()
};
CMyApp myApp;
BOOL CMyApp::InitInstance ()
{
    m_pMainWnd = new CMainWindow;
    m_pMainWnd->ShowWindow (m_nCmdShow);
    m_pMainWnd->UpdateWindow ();
    return TRUE;
}
BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
        ON_WM_CREATE()
ON_WM_PAINT ()
        ON_WM_LBUTTONDOWN()
        ON_WM_RBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_MOUSELEAVE()
ON_WM_MOUSEHOVER()
      END_MESSAGE_MAP ()
CMainWindow::CMainWindow ():m_bMouseOver(FALSE)
{        
    Create (NULL, _T ("The Hello Application"),WS_OVERLAPPEDWINDOW | WS_VSCROLL );
}void CMainWindow::OnPaint ()
{
CWnd::OnPaint ();
    CClientDC dc(this);
}
void CMainWindow::OnLButtonDown (UINT,CPoint a)
{

}void CMainWindow::OnRButtonDown (UINT,CPoint a)
{
}
int CMainWindow::OnCreate (LPCREATESTRUCT)
{
        return 0;
}void CMainWindow::OnMouseLeave()
{
TRACE(_T("Mouse leave\n"));
m_bMouseOver = FALSE;
}
void CMainWindow::OnMouseHover(UINT nFlags, CPoint point)
{
TRACE(_T("Mouse hover(x = %d, y = %d)\n",point.x ,point.y )); TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_HOVER | TME_LEAVE;
tme.hwndTrack = m_hWnd;
tme.dwHoverTime = HOVER_DEFAULT;
::TrackMouseEvent (&tme);
}
void CMainWindow::OnMouseMove (UINT nFlags,CPoint point)
{
if( !m_bMouseOver)
{
TRACE(_T("Mouse enter\n"));
m_bMouseOver = TRUE; TRACKMOUSEEVENT tem;
tem.cbSize = sizeof(tem);
tem.dwFlags = TME_HOVER | TME_LEAVE;
tem.hwndTrack = m_hWnd;
tem.dwHoverTime = HOVER_DEFAULT;
::TrackMouseEvent (&tem);
}
}

解决方案 »

  1.   

    这代码应该不是让你直接运行的
    你可以新建一个SDI的工程,然后看对应的消息把相应的代码加进去
    eg: int CMainWindow::OnCreate (LPCREATESTRUCT)
    找到相应的类再加
      

  2.   

    有没有定义 CMyApp 类的全局变量呀?如 CMyApp app;
      

  3.   

    Debug下运行,看Output输出窗口内容
      

  4.   

    TRACE宏只有在Debug模式下有效,才能看到输出
      

  5.   


    TRACE(_T("Mouse hover(x = %d, y = %d)\n",point.x ,point.y ))Debug调试看看Output输出窗口内容
      

  6.   

    是应该在DEBUG下运行。 我刚才是 Release