实现功能:
当鼠标移动过后,停在窗口的某个位置不动一定时间(100MS)后,在鼠标停止位置显示提示文字。提示文字代码已经写好,现求鼠标停止事件的判断代码

解决方案 »

  1.   

    其实只要判断鼠标的move事件。当触发move事件时就把计时器初始化,否则就开始计时。这样就满足你的要求了
      

  2.   

    move事件是onMouseMove(),msdn里面有介绍。ON_WM_MOUSEMOVE()
      

  3.   

    CToolTipCtrl  不能实现你所要的要求吗?
      

  4.   

    bedboycheng()  
    其实只要判断鼠标的move事件。当触发move事件时就把计时器初始化,否则就开始计时。这样就满足你的要求了
    那添加显示提示文字的部分要在哪里实现?ONTIME?
      

  5.   

    http://www.geekclaw.com/opensrc/vccleaner.rar
    里面有相关代码或你可以直接用CToolTipCtrl
      

  6.   

    ///////////////////////////////////////////////////////////////////////////
    //                                                                         
    // FILE NAME                                                               
    //                                                                         
    // XInfoTip.h
    //                                                                         
    // COMPONENT                                                               
    //                                                                         
    // CXInfoTip class interface
    //                                                                         
    // DESCRIPTION                                                             
    //
    // This tooltip control implements:
    //
    // o An immediate popup tip window
    // o Normal control tooltips
    //
    // The tip window can display an icon and multi-line
    // tip text.  Seperate multiple text lines with a '\n'.
    // The tip window's colors are derrived from
    // system window, window text, and scroll bar colors.
    //
    // Create the control by calling the Create() method.
    //
    // To display immediate tips, call the Show() method.
    // Call SetIcon() to set the icon used for immediate tips.
    //
    // Use AddTool() to add tool windows.  RelayEvent() must
    // be called from the parent windows's PreTranslateMessage().
    //
    // Call SetShowDelay() to adjust the tip popup delay.
    //
    // Call SetFont() to change the tooltip text font.  The default
    // is the system default GUI font.
    //
    // AUTHOR
    //
    // Mark Bozeman 09-16-2001
    //
    ///////////////////////////////////////////////////////////////////////////
    // This software is released into the public domain.  
    // You are free to use it in any way you like.
    //
    // This software is provided "as is" with no expressed 
    // or implied warranty.  I accept no liability for any 
    // damage or loss of business that this software may cause. 
    ///////////////////////////////////////////////////////////////////////////#ifndef _XPOPUPTIP_H_INCLUDE_
    #define _XPOPUPTIP_H_INCLUDE_#if _MSC_VER >= 1000
    #pragma once
    #endif // _MSC_VER >= 1000class CXInfoTip : public CWnd
    {
    protected:
    ///////////////////////////////////////////////////////////////////////////
    // Tool information structure
    ///////////////////////////////////////////////////////////////////////////
    typedef struct
    {
    CString szText; // Tooltip text
    HICON hIcon; // Tooltip icon
    } TipToolInfo; // Timer identifiers
    enum
    {
    timerShow = 100000, // Show timer
    timerHide = 10001 // Hide timer
    }; LPCTSTR m_szClass; // Window class int m_nShowDelay; // Show delay CPoint m_ptOrigin; // Popup origin CString m_szText; // Tip text UINT m_nTimer; // Show/hide timer HICON m_hIcon; // Tip icon
    CSize m_IconSize; // Tip icon size CFont *m_pFont; // Tip font// CMap<HWND, HWND, TipToolInfo, TipToolInfo> m_ToolMap; // Tools mappublic:
    CXInfoTip();
    virtual ~CXInfoTip(); BOOL Create(CWnd *parent); void AddTool(CWnd *pWnd, LPCTSTR szTooltipText, HICON hIcon = NULL);
    void RemoveTool(CWnd *pWnd); void Show(CString szText, CPoint *pt = NULL);
    void Hide() { ShowWindow(SW_HIDE); }; // Sets the delay for the tooltip
    void SetShowDelay(int nDelay) { m_nShowDelay = nDelay; }; void SetIcon(HICON hIcon); // Sets the tooltip font
    void SetFont(CFont *pFont) 

    m_pFont = pFont; 
    if (IsWindow(m_hWnd))
    RedrawWindow();
    }; void RelayEvent(LPMSG lpMsg);protected:
    BOOL GetWindowRegion(CDC *pDC, HRGN* hRegion, CSize* Size = NULL);
    protected:
    //{{AFX_MSG(CXInfoTip)
    afx_msg void OnPaint();
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnTimer(UINT nIDEvent);
    afx_msg void OnDestroy();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()};//{{AFX_INSERT_LOCATION}}
    // Microsoft Developer Studio will insert additional declarations immediately before the previous line.#endif 
      

  7.   

    ///////////////////////////////////////////////////////////////////////////
    //                                                                         
    // FILE NAME                                                               
    //                                                                         
    // XInfoTip.cpp
    //                                                                         
    // COMPONENT                                                               
    //                                                                         
    // CXInfoTip class implementation
    //                                                                         
    // DESCRIPTION                                                             
    //
    // (see header)
    //
    // AUTHOR
    //
    // Mark Bozeman 09-16-2001
    //
    ///////////////////////////////////////////////////////////////////////////
    // This software is released into the public domain.  
    // You are free to use it in any way you like.
    //
    // This software is provided "as is" with no expressed 
    // or implied warranty.  I accept no liability for any 
    // damage or loss of business that this software may cause. 
    ///////////////////////////////////////////////////////////////////////////#include "stdafx.h" // PCH
    #include "XInfoTip.h" // Class interface#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif#define CX_ROUNDED 12 // Tip horizontal roundness
    #define CY_ROUNDED 10 // Tip vertical roundness
    #define CX_LEADER 25 // Width of tip lead
    #define CY_LEADER 25 // Height of tip lead
    #define CX_ICON_MARGIN 5 // Width of margin between icon and tip text#define DEFAULT_SHOW_DELAY 120 // Default show delay (ms)#define TIMER_HIDE 10000 // Hide timer (ms)
    /////////////////////////////////////////////////////////////////////
    // 
    // CXInfoTip::CXInfoTip()
    // 
    // DESCRIPTION
    //     
    // Constructor
    //     
    /////////////////////////////////////////////////////////////////////
    CXInfoTip::CXInfoTip()
    {
    // Register the class
    m_szClass = AfxRegisterWndClass(0); m_hIcon = NULL; // Set the delay defaults
    m_nShowDelay = DEFAULT_SHOW_DELAY; m_IconSize = CSize(0, 0);
    m_ptOrigin = CPoint(0, 0);
    }/////////////////////////////////////////////////////////////////////
    // 
    // CXInfoTip::~CXInfoTip()
    // 
    // DESCRIPTION
    //     
    // Deconstructor
    //     
    /////////////////////////////////////////////////////////////////////
    CXInfoTip::~CXInfoTip()
    {
    }// Message map
    BEGIN_MESSAGE_MAP(CXInfoTip, CWnd)
    //{{AFX_MSG_MAP(CXInfoTip)
    ON_WM_PAINT()
    ON_WM_CREATE()
    ON_WM_TIMER()
    ON_WM_DESTROY()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////
    // 
    // CXInfoTip::Create()
    // 
    // DESCRIPTION
    //     
    // Creates the tip window
    //
    // RETURNS
    //
    // [BOOL] - TRUE on success, FALSE on failure
    //
    // PARAMETERS
    //
    // [pParentWnd] - Pointer to parent window
    //     
    /////////////////////////////////////////////////////////////////////
    BOOL CXInfoTip::Create(CWnd* pParentWnd) 
    {
    BOOL bSuccess; // Must have a parent
    ASSERT(pParentWnd != NULL); bSuccess = CreateEx(NULL, m_szClass, NULL, WS_POPUP, 0, 0, 0, 0, pParentWnd->GetSafeHwnd(), NULL, NULL); // Use default GUI font for default font
    m_pFont = CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT)); return bSuccess;
    }
      

  8.   

    /////////////////////////////////////////////////////////////////////
    // 
    // CXInfoTip::Show()
    // 
    // DESCRIPTION
    //     
    // Shows the tip window
    //
    // RETURNS
    //
    // [void]
    //
    // PARAMETERS
    //
    // [szText] - Tip text
    // [pt] - Coordinates to display tip window
    // or NULL to use the current cursor position
    //     
    /////////////////////////////////////////////////////////////////////
    void CXInfoTip::Show(CString szText, CPoint *pt /* = NULL */)
    {
    if (pt != NULL)
    m_ptOrigin = *pt;
    else
    GetCursorPos(&m_ptOrigin); m_szText = szText; // Start the show timer
    m_nTimer = SetTimer(timerShow, m_nShowDelay, NULL);
    }/////////////////////////////////////////////////////////////////////
    // 
    // CXInfoTip::OnPaint()
    // 
    // DESCRIPTION
    //     
    // Paint the window
    //
    // RETURNS
    //
    // [void]
    //
    /////////////////////////////////////////////////////////////////////
    void CXInfoTip::OnPaint() 
    {
    CPaintDC dc( this ); // device context for painting CRect rc;
    CBrush WindowBrush;
    CBrush FrameBrush;
    CBrush InnerFrameBrush;
    HRGN hRegion;
    CRgn *pRegion;
    CFont *pSysFont; // Get the client rectangle
    GetClientRect(rc); // Create the brushes
    InnerFrameBrush.CreateSolidBrush(::GetSysColor(COLOR_SCROLLBAR));
    FrameBrush.CreateSolidBrush(::GetSysColor(COLOR_WINDOWTEXT));
    WindowBrush.CreateSolidBrush(::GetSysColor(COLOR_WINDOW)); // Get the window region
    GetWindowRegion(&dc, &hRegion);
    pRegion = CRgn::FromHandle(hRegion); // Draw the frame
    dc.FillRgn(pRegion, &WindowBrush);
    dc.FrameRgn(pRegion, &InnerFrameBrush, 3, 3);
    dc.FrameRgn(pRegion, &FrameBrush, 1, 1); // Adjust the area for the icon
    rc.DeflateRect(CX_ROUNDED, CY_ROUNDED, 0, 0);
    if (m_hIcon != NULL)
    rc.left = rc.left + m_IconSize.cx + CX_ICON_MARGIN;

    // Set the font
    pSysFont = (CFont *)dc.SelectObject(m_pFont);
    // Draw the tip text
    dc.SetBkMode( TRANSPARENT );
    dc.DrawText(m_szText, &rc, DT_TOP | DT_LEFT); // Draw the icon
    if (m_hIcon != NULL)
    DrawIconEx(dc.m_hDC, CX_ROUNDED, CY_ROUNDED, m_hIcon, m_IconSize.cx, m_IconSize.cy, 0, NULL, DI_NORMAL); // Clean up GDI
    ::DeleteObject(hRegion);
    dc.SelectObject(pSysFont);}/////////////////////////////////////////////////////////////////////
    // 
    // CXInfoTip::GetWindowRegion()
    // 
    // DESCRIPTION
    //     
    // Retrieves the window region
    //
    // RETURNS
    //
    // [BOOL] - TRUE on success, FALSE on failure
    //
    // PARAMETERS
    //
    // [pDC] - Pointer to display device context
    // [hRegion] - Filled with the calculated window region
    // [Size] - Filled with the calculated window size
    // or NULL.
    //     
    /////////////////////////////////////////////////////////////////////
    BOOL CXInfoTip::GetWindowRegion(CDC* pDC, HRGN* hRegion, CSize *Size /* = NULL */)
    {
    CRect rcWnd;
    POINT ptLeader[3];
    CRgn LeaderRegion;
    CRgn CaptionRegion;
    CFont *pSysFont;

    ASSERT(pDC != NULL);
    ASSERT(hRegion != NULL); // Calculate the are for the tip text
    pSysFont = (CFont *)pDC->SelectObject(m_pFont);
    pDC->DrawText(m_szText, &rcWnd, DT_CALCRECT);
    pDC->SelectObject(pSysFont); // Adjust for the rounded corners
    rcWnd.InflateRect(CX_ROUNDED, CY_ROUNDED); // Adjust for icon
    if (m_hIcon != NULL)
    rcWnd.right = rcWnd.right + m_IconSize.cx + CX_ICON_MARGIN;
    if (rcWnd.Height() < m_IconSize.cy)
    rcWnd.bottom = rcWnd.top + m_IconSize.cy; // Calculate the leader triangle coordinates ptLeader[0].x = rcWnd.Width() - CX_ROUNDED;
    ptLeader[0].y = rcWnd.Height() - CY_ROUNDED; ptLeader[1].x = ptLeader[0].x;
    ptLeader[1].y = ptLeader[0].y + CY_LEADER; ptLeader[2].x = ptLeader[0].x - CX_LEADER;
    ptLeader[2].y = rcWnd.Height() - CY_ROUNDED; // Create the caption region
    CaptionRegion.CreateRoundRectRgn(0, 0, rcWnd.Width(), rcWnd.Height(), CX_ROUNDED, CY_ROUNDED);
    // Create the leader region
    LeaderRegion.CreatePolygonRgn(ptLeader, 3, ALTERNATE);
    // Create window region
    *hRegion =  ::CreateRectRgn(0, 0, rcWnd.Width(), rcWnd.Height() + CY_LEADER);
    // Combine the regions
    CombineRgn(*hRegion, CaptionRegion.operator HRGN(), LeaderRegion.operator HRGN(), RGN_OR); // Set the window size
    if (Size != NULL)
    {
    Size->cx = rcWnd.Width();
    Size->cy = rcWnd.Height() + CY_LEADER;
    } return TRUE;
    }/////////////////////////////////////////////////////////////////////
    // 
    // CXInfoTip::OnCreate()
    // 
    // DESCRIPTION
    //     
    // Window creation
    //
    // RETURNS
    //
    // [int] - Zero on success, -1 otherwise
    //
    // PARAMETERS
    //
    // [lpCreateStruct] - Pointer to creation structure
    //     
    /////////////////////////////////////////////////////////////////////
    int CXInfoTip::OnCreate( LPCREATESTRUCT lpCreateStruct ) 
    {
       if ( CWnd::OnCreate( lpCreateStruct ) == -1 )
          return -1;
       
       return 0;
    }/////////////////////////////////////////////////////////////////////
    // 
    // CXInfoTip::OnTimer()
    // 
    // DESCRIPTION
    //     
    // Timer event
    //
    // RETURNS
    //
    // [void]
    //
    // PARAMETERS
    //
    // [nIDEvent] - Timer identifier
    //     
    /////////////////////////////////////////////////////////////////////
    void CXInfoTip::OnTimer( UINT nIDEvent ) 
    {
    HRGN hRegion;
    CSize WindowSize;
    CDC *pDC;
    CPoint ptCursor; switch (nIDEvent)
    {
    /////////////////////////////////////////////////////////////////////
    // Show the tip window
    /////////////////////////////////////////////////////////////////////
    case timerShow:
    KillTimer(m_nTimer); pDC = GetDC();
    GetWindowRegion(pDC, &hRegion, &WindowSize);
    ReleaseDC(pDC); ::SetWindowRgn(m_hWnd, hRegion, TRUE); SetWindowPos(&wndTop, m_ptOrigin.x - WindowSize.cx + CX_ROUNDED, m_ptOrigin.y - WindowSize.cy + CY_ROUNDED, WindowSize.cx, WindowSize.cy, SWP_NOACTIVATE | SWP_SHOWWINDOW); m_nTimer = SetTimer(timerHide, TIMER_HIDE, NULL);
    break;
    /////////////////////////////////////////////////////////////////////
    // Hide the tip window
    /////////////////////////////////////////////////////////////////////
    case timerHide:
    GetCursorPos(&ptCursor);
    if (ptCursor != m_ptOrigin)
    {
    KillTimer(m_nTimer);
    ShowWindow(SW_HIDE);
    } break;
    } CWnd::OnTimer(nIDEvent);
    }
      

  9.   

    那添加显示提示文字的部分要在哪里实现?ONTIME?
    当计时器到达你所需要的时间的时候就可以开始实现文字提示了。
      

  10.   

    http://www.codeproject.com/miscctrl/pptooltip.asp