CButtonST的tooltip在点击按钮后消失的问题~~~

真是很难让人相信,在使用CButtonST类多年之后,居然还有这种BUG没有被发现。其实这主要是由于自己很少编写文档试图结构的程序,而这个BUG只出现在文档试图程序中,也就是在对话框程序中完全正常。(从codeproject网站的BBS可以看出,这个BUG同样出现在ActiveX控件中)
自己分析了一会,没有找到原因,惭愧呀。后来从Codeproject网站的BBS找到相应的解决办法,具体如下:

关于这个问题,在codeproject网站的BBS里有如下讨论:
-------------------
a CButtonST button is assigned some tooltip text, and firstly the tooltip show normally, but if I press the button but not release until move the mouse out of the button, that is, i press the MouseLButton in a CButtonST, and release the MouseLButton outside a CButtonST, THEN, the tooltip do not work any more. is it a bug?
此问题无人回复。

Tooltip dissapears?
Great buttons, but have encountered some problems. Added CButtonST buttons to my test project.
I move the mouse cursor over the button and the tooltip shows. Then I press the button and after that if I move the mouse cursor over the button, no tooltip shows. I checked the messages sent to the button in Spy++. Before pressing the button it receives WM_NOTIFY messages, probably from the tooltip control with TTN_SHOW and TTN_POP. However this does not occur after pressing the button. Also I have added the TTS_ALWAYSTIP style for the sake of it but no effect. However, after I create a dialog when selecting a specific menu item in my app the buttons again can show the tooltips. I guess there is some activating/deactivating going on, but even though I add som m_ToolTip.Activate(TRUE) code here and there it will not help. Any ideas, anybody encountered the same problem? Appreciate the help!
 
I have the same problem – ish
I’m using the class in an OLE control which doesn’t allow PreTranslate message for CButtonST, so instead i’m doing some fudging in OnMouseMove() to cause the tooltip to appear. This works fine in all cases except when the tooltip times out (i.e. mouse on button and timeout occurs and tooltip hides). Once this has happen the button will never show the tip again. I can force it to be shown with CToolTipCtrl::Update() but this isn’t ideal.
这个讨论有个临时解决办法。

最后终于有人给出了一个解决方案,经过实验后,相当好用。

 

sI also worried about the same problem. Please try the following code.

— CButtonST.h —
protected:
    CString m_strTipText;

— CButtonST.cpp —
void CButtonST::SetTooltipText(LPCTSTR lpszText, BOOL bActivate)
{
    // We cannot accept NULL pointer
    if (lpszText == NULL) return;

    ////////////////////////////////////////// 添加+++++
    m_strTipText = lpszText;
    ///////////////////////////////////////////
// Initialize ToolTip
 InitToolTip();

 // If there is no tooltip defined then add it
 if (m_ToolTip.GetToolCount() == 0)
 {
  CRect rectBtn;
  GetClientRect(rectBtn);
  m_ToolTip.AddTool(this, lpszText, rectBtn, 1);
 } // if

 // Set text for tooltip
 m_ToolTip.UpdateTipText(lpszText, this, 1);
 m_ToolTip.Activate(bActivate);  

}

LRESULT CButtonST::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
    CancelHover();
    ///////////////////////////////////////////////////////////添加+++++

    if (m_ToolTip.m_hWnd != NULL) {
        m_ToolTip.DelTool(this, 1);
        if (m_strTipText.IsEmpty() != TRUE) {
            CRect rectBtn;
            GetClientRect(rectBtn);
            m_ToolTip.AddTool(this, m_strTipText, rectBtn, 1);
            m_ToolTip.Activate(TRUE);
        }
    }
    ////////
    return 0;
}


你可能感兴趣的:(null,文档,dialog,button,bbs,tts)