BOOL CProcMemWnd::CreateToolTipCtrl() // CProcMemWnd继承CFrameWnd
{
m_hwndTooltip=CreateWindow(TOOLTIPS_CLASS, (LPSTR) NULL, TTS_ALWAYSTIP, 
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
        NULL, (HMENU) NULL, NULL, NULL);  
TOOLINFO ti;            ti.cbSize = sizeof(TOOLINFO); 
            ti.uFlags = 0; 
            ti.hwnd = GetSafeHwnd(); 
            ti.hinst = NULL; 
            ti.uId = (UINT) ID_MEM_REFRESH; 
            ti.lpszText = "fsfsdfsdfdsfs"; 
CRect rcButton;
m_wndToolBar1.GetItemRect(5,&rcButton);
ti.rect=rcButton; 
            ::SendMessage(m_hwndTooltip, TTM_ADDTOOL, 0, 
                    (LPARAM) (LPTOOLINFO) &ti);  
 
::SendMessage(m_hwndTooltip,TTM_ACTIVATE,(WPARAM)TRUE,0);
return TRUE;}int CProcMemWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{

CreateCtrlOnToolbar();
EnableToolTips();
return 0;
}
BOOL CProcMemWnd::PreTranslateMessage(MSG* pMsg) 
{
if (m_hwndTooltip)
{
switch (pMsg->message)

        case WM_MOUSEMOVE: 
        case WM_LBUTTONDOWN: 
        case WM_LBUTTONUP: 
        case WM_RBUTTONDOWN: 
        case WM_RBUTTONUP:             
::SendMessage(m_hwndTooltip, TTM_RELAYEVENT, 0,         (LPARAM) (LPMSG) &pMsg);         
}             
}
return CFrameWnd::PreTranslateMessage(pMsg);
}

解决方案 »

  1.   

    程序代码如上所示,可是程序运行当中没有Tooltip显示
      

  2.   

    这是别人给我的一段代码,我用了一下可以!
    或者到这里看一下!http://expert.csdn.net/Expert/topic/1607/1607711.xml?temp=.6588251可以利用 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);
    }
      

  3.   

    To seagis(阿辛) :
    这个ToolTip不是要在视图,而是在工具条上
      

  4.   

    你是说在工具条上移动鼠标的时候,图标上有tooltip吗?