【问题标题】:MFC Button ToolTip not showing after button clickMFC 按钮工具提示在按钮单击后不显示
【发布时间】:2012-08-07 13:42:21
【问题描述】:

我正在使用 MFC CToolTipCtrl 为按钮创建工具提示。现在我在 Windows XP 中运行应用程序时遇到问题。当我将鼠标放在按钮上时,会弹出工具提示,但单击按钮后没有显示工具提示。在 windows 7 中没有这样的问题。我使用以下代码创建工具提示

pToolTip->Create(this);

TOOLINFO ToolInfo;
ToolInfo.cbSize     = sizeof(TOOLINFO);
ToolInfo.lpszText   = const_cast<LPTSTR>(szToolTipText);
ToolInfo.hinst      = AfxGetInstanceHandle();
ToolInfo.hwnd       = pButton->m_hWnd;
ToolInfo.uFlags     = TTF_SUBCLASS | TTF_IDISHWND;
ToolInfo.uId        = (UINT)pButton->m_hWnd;

pToolTip->SendMessage(TTM_ADDTOOL, 0, (LPARAM) &ToolInfo);

【问题讨论】:

    标签: mfc windows-xp tooltip windows-messages


    【解决方案1】:

    尝试在preTanslateMessage函数中调用relayevent。

    来自 MSDN:http://msdn.microsoft.com/en-US/library/x61cthdf(v=vs.80).aspx

    为了通知工具提示控件重要消息,例如 WM_LBUTTONXXX 消息,您必须将消息中继到您的工具提示控件。此中继的最佳方法是在所有者窗口的 PreTranslateMessage 函数中调用 CToolTipCtrl::RelayEvent。

    以下示例说明了一种可能的方法(假设工具提示控件名为 m_ToolTip):

    if(pMsg->message== WM_LBUTTONDOWN ||
            pMsg->message== WM_LBUTTONUP ||
            pMsg->message== WM_MOUSEMOVE)
    m_ToolTip.RelayEvent(pMsg);
    
    return CMyView::PreTranslateMessage(pMsg);
    

    如果你使用上面的VS2010,你可以直接使用CMFCButton,它有设置工具提示的方法,让生活更轻松。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多