鼠标放在菜单上面的时候,会看到浮动的显示该菜单所能实现的功能!
鼠标在客户区移动的时候,怎样做才能实现显示该点坐标的浮动显示呢?

解决方案 »

  1.   

    其实不论什么提示,就是一个窗口,你可以定制一个窗口,当MOUSE到移动到相应的地方,再显示该窗口
      

  2.   

    说的是tooltips吧?我记得在msdn看过一片文章,全面介绍了各种tooltips的技巧
    在这里http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0497/tooltip/tooltip.htm&nav=/msj/0497/newnav.htm
      

  3.   

    可以利用 ToolTipCtrl,以下是代码(在 CView 中测试通过,如果你的窗口客户区小于窗口大小,要坐标变换一下):// class members:
    CToolTipCtrl m_ctrlToolTip;// declare message enter
    afx_msg BOOL OnTTNNeedText(UINT id, NMHDR * pNMHDR, LRESULT * pResult);// implementations of massage map
    ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnTTNNeedText)// OnCreate : Override and add these code
    if (m_ctrlToolTip.Create(this, 0))
        m_ctrlToolTip.AddTool(this, LPSTR_TEXTCALLBACK, &NULL);// PreTranslateMessage : Override and add these code
    if (NULL != m_ctrlToolTip.GetSafeHwnd()) 
        m_ctrlToolTip.RelayEvent(pMsg);// OnMouseMove : Override and add these code
    if (m_ctrlToolTip.GetStyle() & WS_VISIBLE)
        m_ctrlToolTip.Update();// OnNeedText : write these code
    BOOL CYourWnd::OnTTNNeedText(UINT id, NMHDR * pNMHDR, LRESULT * pResult)
    {
        TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;    POINT pt;
        GetCursorPos(&pt);
        ScreenToClient(&pt);    _stprintf(pTTT->szText, _T("x = %d, y = %d"), pt.x, pt.y);    return(TRUE);
    }
      

  4.   

    多等一会,或者 Create 后加一句m_ctrlToolTip.SetDelayTime(100);
      

  5.   

    那段代码可以用的,你可以把MouseMove里的if (m_ctrlToolTip.GetStyle() & WS_VISIBLE)
    这句,去掉,就始终都会存在了,然后把这个IF改成你需要的条件,比如移动到某一特定区域再显示tooltip
      

  6.   

    早上再试了一下可以了,真是奇怪!那个NULL的&符号要去掉编译才能通过!不过我做的是滚动视图,当我拖动滚动条后再放在上面就没有提示了?这是什么原因阿?
      

  7.   

    一个可能更好的解决方案:// class members
    CToolTipCtrl m_ctrlToolTip;
    BOOL m_bTrackingToolTip; /* initialize FALSE */// declare message enters
    afx_msg BOOL OnTTNNeedText(UINT id, NMHDR * pNMHDR, LRESULT * pResult);
    afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);// add these to message map
    ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnTTNNeedText)
    ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)// OnCreate : Override & add these code
    if ( !m_ctrlToolTip.Create(this) )
        return -1;TOOLINFO ti;
    ti.cbSize = sizeof(TOOLINFO);
    ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
    ti.hwnd   = this->GetSafeHwnd();
    ti.uId    = (UINT)this->GetSafeHwnd();
    ti.hinst  = AfxGetInstanceHandle();
    ti.lpszText  = LPSTR_TEXTCALLBACK;
    ti.rect.left = ti.rect.top = ti.rect.bottom = ti.rect.right = 0; // Add the tool to the control, displaying an error if needed.
    if(!m_ctrlToolTip.SendMessage(TTM_ADDTOOL, 0, (LPARAM)&ti))
        return -1;m_bTrackingToolTip = FALSE;// OnMouseMove : Override & add these code
    const UINT X_OFFSET = 15;
    const UINT Y_OFFSET = X_OFFSET;if (FALSE == m_bTrackingToolTip)
    {
        TOOLINFO ti;
        ti.cbSize = sizeof(TOOLINFO);
        ti.hwnd   = this->GetSafeHwnd();
        ti.uId    = (UINT)this->GetSafeHwnd();    if (m_ctrlToolTip.SendMessage(TTM_TRACKACTIVATE, (WPARAM)TRUE, (LPARAM)&ti))
            m_bTrackingToolTip = TRUE;    TRACKMOUSEEVENT tme;
        tme.cbSize = sizeof(TRACKMOUSEEVENT);
        tme.dwFlags = TME_LEAVE;
        tme.hwndTrack = this->GetSafeHwnd();
        tme.dwHoverTime = 0;   _TrackMouseEvent(&tme);
    }

    if (m_bTrackingToolTip && (m_ctrlToolTip.GetStyle() & WS_VISIBLE))
    {
        ClientToScreen(&point);    m_ctrlToolTip.SendMessage(TTM_TRACKPOSITION, 0,
            (LPARAM)MAKELPARAM(point.x + X_OFFSET, point.y + Y_OFFSET));
    }// writen OnTTNNeedText 
    BOOL CYourWnd::OnTTNNeedText(UINT id, NMHDR * pNMHDR, LRESULT * pResult)
    {
        TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;    POINT pt;    GetCursorPos(&pt);
        ScreenToClient(&pt);    _stprintf(pTTT->szText, _T("x = %d, y = %d"), pt.x, pt.y);    return(TRUE);
    }// writen OnMouseLeave
    LRESULT CYourWnd::OnMouseLeave(WPARAM wParam, LPARAM lParam)
    {
        if (m_bTrackingToolTip)
        {
            TOOLINFO ti;
            ti.cbSize = sizeof(TOOLINFO);
            ti.hwnd   = this->GetSafeHwnd();
            ti.uId    = (UINT)this->GetSafeHwnd();        if (m_ctrlToolTip.SendMessage(TTM_TRACKACTIVATE, (WPARAM)FALSE, (LPARAM)&ti))
                m_bTrackingToolTip = FALSE;
        }
        return TRUE;
    }