1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
   |  
// CTplToolTip window
template <class GENERIC_TOOLTIP>
class CTplToolTip : public GENERIC_TOOLTIP
{
    // Construction
public:
    CTplToolTip(){}
 
// Attributes
 
public:
 
CToolTipCtrl m_tooltip;
CString      m_strText;
UINT         m_nIDTool;
 
// Operations
public:
 
    BOOL AddTool(LPCTSTR lpszText=LPSTR_TEXTCALLBACK,
                LPCRECT lpRectTool=NULL,UINT nIDTool=0)
    {
        m_strText=lpszText;
        m_nIDTool=nIDTool;        
        return m_tooltip.AddTool(this,lpszText,lpRectTool ,nIDTool );
    }
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTplToolTip)
public:
    virtual LRESULT DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
    {
        if(nMsg==WM_MOUSEACTIVATE && m_tooltip.m_hWnd != NULL)
        {
            m_tooltip.DelTool(this,m_nIDTool);
            m_tooltip.AddTool(this,m_strText,NULL,m_nIDTool);
 
        }
        return GENERIC_TOOLTIP::DefWindowProc( nMsg, wParam,lParam);
    }
    virtual BOOL PreTranslateMessage(MSG* pMsg)
    {
        if (m_tooltip.m_hWnd != NULL)
        {
            // translate the message based on TTM_WINDOWFROMPOINT
            MSG msg = *pMsg;            
            msg.hwnd = (HWND)m_tooltip.SendMessage(TTM_WINDOWFROMPOINT,
                                                0, (LPARAM)&msg.pt);
            CPoint pt = pMsg->pt;
            if (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST)
            ::ScreenToClient(msg.hwnd, &pt);
 
            msg.lParam = MAKELONG(pt.x, pt.y);
            // Let the ToolTip process this message.
            m_tooltip.RelayEvent(&msg);
    }
    return GENERIC_TOOLTIP::PreTranslateMessage(pMsg);
}
 
protected:
virtual void PreSubclassWindow()
{
    GENERIC_TOOLTIP::PreSubclassWindow();
 
    m_tooltip.Create(this); // la view ou la dialog   
    m_tooltip.SetDelayTime(1000); // le delay
    m_tooltip.Activate(TRUE); 
    m_tooltip.SetMaxTipWidth(500); // pour le multiligne.
} | 
Partager