TIP是什么东西,讲出来大家学习学习

解决方案 »

  1.   

    to:hujun614(胡均)
    这招我 早就已经试过了 不行!!!
      

  2.   

    CToolTipCtrl!
    这个好象 没有什么 太难理解吧!:)
      

  3.   

    自己派生CToolTipCtrl类
    WWW.VCHELP.NET(可能是www.vckbase.com)
    有个例子,很好的.
      

  4.   

    http://www.csdn.net/Dev/Visual%20C++/source%20code/Misc/ 
    这个也看看,不过只是简单的多行提示
      

  5.   

    MFC里面 没有现成的类 实现? 好象IE4以后 WINDOWS就支持这种功能了
      

  6.   

    to:florist2000(善良的石头)
    自己派生??你说的那个例子我 没有找到 在那里????
      

  7.   

    to:florist2000(善良的石头)
    你说的那个例子我 看了
    http://www.csdn.net/Dev/Visual%20C++/source%20code/Misc/ 
    那是他自己封装的一个类 我希望直接用WINDOWS的!
    谁有什么建议吗?
      

  8.   

    给你找个例子吧,我以前用过,很好用的,而且是异形的提示窗口.
    ToolTipWnd.h 如下
    #if !defined(AFX_TOOLTIPWND_H__2C52D3E4_2F5B_11D2_8FC9_000000000000__INCLUDED_)
    #define AFX_TOOLTIPWND_H__2C52D3E4_2F5B_11D2_8FC9_000000000000__INCLUDED_#if _MSC_VER >= 1000
    #pragma once
    #endif // _MSC_VER >= 1000/////////////////////////////////////////////////////////////////////////////
    // CToolTipWnd window
    struct BTOOLINFO { HWND hwndTool;
    CString strToolText;
    COLORREF clrToolTextClr;};class CToolTipWnd : public CWnd
    {private:
    // Construction
    LPCTSTR lpWndCls;
    public:
    CToolTipWnd();
    HWND pCurrwnd;
    // Attributes
    public:
    void RelayEvent(LPMSG);
    BOOL Create(CWnd*);
    bool m_bStuck; void AddTool(CWnd *pWnd, CString strText, COLORREF clrTextColor=NULL);
    void SetWidth(int iWidth) { m_iWidth = iWidth; }
    void SetHeight(int iHeight) { m_iHeight = iHeight; }
    void SetBkColor(COLORREF clrRef) { m_clrBkColor = clrRef; }
    void SetFrameColor(COLORREF clrRef) { m_clrFrameColor = clrRef; }
    void SetDefTextColor(COLORREF clrRef) { m_clrTextColor = clrRef; }
    void SetFontHeight(int iHeight) { m_iFontHeight = iHeight; }
    void SetFontName(CString strFontName) { m_strFontName = strFontName; }private:
    CRgn rgn;
    CRgn rgnComb;
    CRgn rgnTri;
    CRect m_RectText;
    CFont m_fontText;

    CString m_strText;
    bool m_bMouseIn;
    COLORREF m_clrTextColor;
    COLORREF m_clrBkColor;
    COLORREF m_clrFrameColor;
    CMapPtrToPtr m_ToolPtr;
    int m_iWidth;
    int m_iHeight;
    int m_iFontHeight;
    CString m_strFontName; HWND m_hParentWnd;
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CToolTipWnd)
    protected:
    //}}AFX_VIRTUAL
    // Implementation
    public:
    virtual ~CToolTipWnd(); // Generated message map functions
    protected:
    //{{AFX_MSG(CToolTipWnd)
    afx_msg void OnPaint();
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Developer Studio will insert additional declarations immediately before the previous line.#endif // !defined(AFX_TOOLTIPWND_H__2C52D3E4_2F5B_11D2_8FC9_000000000000__INCLUDED_)
    ToolTipWnd.cpp内容如下
    // ToolTipWnd.cpp : implementation file
    //#include "stdafx.h"
    #include "ToolTipWnd.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CToolTipWndCToolTipWnd::CToolTipWnd()
    { lpWndCls = AfxRegisterWndClass(0);

    //Defaults
    m_bMouseIn = false;
    m_bStuck = false;

    m_iWidth = 100;
    m_iHeight = 60; m_clrBkColor = RGB(249,254,188); //light yellow
    m_clrFrameColor = RGB(0,0,255);  //blue
    m_clrTextColor = RGB(0,0,0);  //black m_iFontHeight = 14;
    m_strFontName = "Arial"; pCurrwnd = NULL;
    }CToolTipWnd::~CToolTipWnd()
    { BTOOLINFO *stToolInfo;
    CWnd *pWnd;
    for(POSITION pos = m_ToolPtr.GetStartPosition(); pos != NULL;)
    {
    m_ToolPtr.GetNextAssoc(pos, (void *&)pWnd, (void*&) stToolInfo);
    delete stToolInfo;
    }
    m_ToolPtr.RemoveAll();}
    BEGIN_MESSAGE_MAP(CToolTipWnd, CWnd)
    //{{AFX_MSG_MAP(CToolTipWnd)
    ON_WM_PAINT()
    ON_WM_CREATE()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    /////////////////////////////////////////////////////////////////////////////
    // CToolTipWnd message handlers
    BOOL CToolTipWnd::Create(CWnd* pParentWnd) 
    { BOOL bRet = CWnd::CreateEx(NULL, lpWndCls, NULL,
    WS_POPUP, 0, 0, m_iWidth, m_iHeight,
    pParentWnd->GetSafeHwnd(), NULL, NULL); m_hParentWnd = pParentWnd->GetSafeHwnd();

    if(bRet)
    SetOwner(pParentWnd); return bRet;}void CToolTipWnd::OnPaint() 
    {
    CPaintDC dc(this); // device context for painting

    CRect rectCl;
    GetClientRect(&rectCl); CRgn rgnComb;
    rgnComb.CreateRectRgn(rectCl.left+10,rectCl.top,rectCl.right,rectCl.bottom); int iRetComb = rgnComb.CombineRgn(&rgnTri, &rgn, RGN_OR);
    if(iRetComb==ERROR)
    {
    AfxMessageBox("ERROR in Combining Region");
    return;
    } CBrush pBrush;
    pBrush.CreateSolidBrush(m_clrFrameColor);

    CBrush pBrush1;
    pBrush1.CreateSolidBrush(m_clrBkColor);

    dc.FillRgn( &rgnComb, &pBrush1);
    dc.FrameRgn(&rgnComb, &pBrush, 2, 1); dc.SetBkMode(TRANSPARENT);
    dc.SetTextColor(m_clrTextColor);

    CFont *pFont = dc.SelectObject(&m_fontText);
    //dc.Rectangle(&m_RectText); CSize czTextWidth = dc.GetTextExtent(m_strText);

    if( czTextWidth.cx < m_RectText.Width())
    dc.DrawText(m_strText, m_RectText, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
    else
    dc.DrawText(m_strText, m_RectText, DT_CENTER | DT_WORDBREAK);

    dc.SelectObject(pFont);

    }
    int CToolTipWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    if (CWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

    CRect rectCl;
    GetClientRect(&rectCl); int x=0, y=0;
    CRect rectTemp; rectTemp = rectCl;
    rectTemp.left = rectTemp.left + 10;

    x = (int)( (float)((float)rectTemp.Width() / 2.0) / 1.41421);
    y = (int)( (float)((float)rectTemp.Height() / 2.0) / 1.41421); m_RectText.top = ( (rectTemp.Height() / 2) - y);
    m_RectText.left = ( (rectTemp.Width() / 2) - x) + 10;
    m_RectText.right = ( (rectTemp.Width() / 2) + x) + 10;
    m_RectText.bottom = ( (rectTemp.Height() / 2) + y); rgn.m_hObject = NULL;
    rgnTri.m_hObject = NULL;
    rgnComb.m_hObject = NULL; BOOL bRegRet = rgn.CreateEllipticRgn(rectCl.left+10,rectCl.top,rectCl.right,rectCl.bottom);

    CPoint ptTri[3];
    ptTri[0].x = rectCl.left;
    ptTri[0].y = (rectCl.bottom / 2) - 10; ptTri[1].x = rectCl.left + 15;
    ptTri[1].y = (rectCl.bottom / 2) - 5; ptTri[2].x = rectCl.left + 15;
    ptTri[2].y = (rectCl.bottom / 2) + 5;

    ptTri[3].x = rectCl.left;
    ptTri[3].y = (rectCl.bottom / 2) - 10; BOOL bRegTriRet = rgnTri.CreatePolygonRgn(ptTri, 3, ALTERNATE); rgnComb.CreateRectRgn(rectCl.left+10,rectCl.top,rectCl.right,rectCl.bottom);
    int iRetComb = rgnComb.CombineRgn(&rgnTri, &rgn, RGN_OR); if(iRetComb == ERROR)
    {
    AfxMessageBox("ERROR in Combining Region");
    return -1;
    } int bRgnWnd = SetWindowRgn(rgnComb.operator HRGN( ), TRUE); m_fontText.CreateFont(m_iFontHeight, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,m_strFontName);

    return 0;
    }void CToolTipWnd::RelayEvent(LPMSG lpMsg)
    { switch(lpMsg->message) 
    {
    case WM_KEYDOWN:
    if(IsWindowVisible())
    {
    ShowWindow(SW_HIDE);
    }
    break; case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN:
    if(IsWindowVisible())
    {
    ShowWindow(SW_HIDE);
    }
    break; case WM_MOUSEMOVE:
    {
    CWnd *pFocusWnd = AfxGetApp()->m_pMainWnd->GetFocus();
    if(pFocusWnd==NULL)
    break;
    CWnd* pWnd = CWnd::FromHandle(lpMsg->hwnd); HWND hWndTemp = ::GetParent(lpMsg->hwnd);

    CPoint pt;
    pt.x = lpMsg->pt.x;
    pt.y = lpMsg->pt.y;

    BTOOLINFO *stToolInfo;
    CWnd *pBToolWnd;

    for(POSITION pos = m_ToolPtr.GetStartPosition(); pos != NULL;)
    {
    m_ToolPtr.GetNextAssoc(pos, (void *&)pBToolWnd, (void*&) stToolInfo);

    if(!m_bMouseIn)
    {
    if(lpMsg->hwnd == stToolInfo->hwndTool)
    {

    if(m_bStuck && IsWindowVisible())
    {
    SetWindowPos(&wndTop,pt.x,pt.y,m_iWidth,m_iHeight,SWP_NOACTIVATE);
    ShowWindow(SW_SHOWNOACTIVATE);
    } m_bMouseIn = true;
    m_clrTextColor = stToolInfo->clrToolTextClr; 
    m_strText = stToolInfo->strToolText; 

    SetWindowPos(&wndTop,pt.x,pt.y,m_iWidth,m_iHeight,SWP_NOACTIVATE);
    ShowWindow(SW_SHOWNOACTIVATE);

    pCurrwnd = stToolInfo->hwndTool; break;
    }
    }
    else
    {
    CRect rect;
    ::GetWindowRect(pCurrwnd, &rect);
    if(m_bStuck && IsWindowVisible())
    {
    SetWindowPos(&wndTop,pt.x,pt.y,m_iWidth,m_iHeight,SWP_NOACTIVATE);
    ShowWindow(SW_SHOWNOACTIVATE);
    }


    CWnd* pWnd = CWnd::FromHandle(lpMsg->hwnd);
    CWnd *WndPt = pWnd->WindowFromPoint(lpMsg->pt);
    if(WndPt->GetSafeHwnd() != pCurrwnd)
    {
    m_bMouseIn = false;
    ShowWindow(SW_HIDE);
    }
    break;
    }
    }

    }
    break; //WM_MOUSEMOVE
    }
     
    }void CToolTipWnd::AddTool(CWnd *pWnd, CString strText, COLORREF clrTextColor)
    { BTOOLINFO *stToolInfo; if(!m_ToolPtr.Lookup( pWnd, ( void*& )  stToolInfo))
    {
    stToolInfo = new BTOOLINFO;
    stToolInfo->hwndTool = pWnd->GetSafeHwnd();
    stToolInfo->strToolText = strText;
    if(clrTextColor==NULL)
    stToolInfo->clrToolTextClr = m_clrTextColor;
    else
    stToolInfo->clrToolTextClr = clrTextColor;

    m_ToolPtr.SetAt(pWnd, stToolInfo);
    }}
      

  9.   

    如果你非要用VC自带的那个TIP
    你可以自己做,方法是我给你说的,派生自己的TIP类就是.方法如下
    CMyToolTipCtrl定制 
    1. 重载OnPaint ( )可以显示任意的东西, 
       但如何得到当前鼠标下窗口的TEXT呢??nbsp;
       (OnPaint没有相应的参数,总不能每次都显示一样的东西吧) 
    2. 需要重载 
       BOOL CMyToolTipCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM  
                lParam, LRESULT* pLResult)  
    参数的意义: 
    1. wParam 是光标所在的Window的句柄 
    2. lParam指向: 
       typedef struct tagNMHDR {  
        HWND hwndFrom; //ToolTip的窗口句柄 
        UINT idFrom;   //是光标所在的Window的句柄 
        UINT code;     // 
                       //ToolTip显示TEXT时Notify Message的顺序 
                       // code=-12,-521,-522 
                       // 依次为:将要显示TEXT,获取TEXT,清除显示TEXT; 
                       // 获取TEXT有定义:TTN_NEEDTEXTA(win95),TTN_NEEDTEXTW(winnt) 
                       // 而其余两个的我没有找到定义。 
        } NMHDR;  
     
     
    所以可以在OnChildNotify中记录下将要显示的TEXT,然后在OnPaint中作出自己的显示。 
     
      

  10.   

    看看Platform SDK里是怎么说的吧,现成的例子Multiline ToolTips
    Multiline ToolTips allow text to be displayed on more than one line. They are supported by version 4.70 and later of the common controls. Your application creates a multiline ToolTip by responding to a TTN_GETDISPINFO notification message. To force the ToolTip control to use multiple lines, send a TTM_SETMAXTIPWIDTH message, specifying the width of the display rectangle. Text that exceeds this width will wrap to the next line rather than widening the display region. The rectangle height will be increased as needed to accommodate the additional lines. The ToolTip control will wrap the lines automatically, or you can use a carriage return/line feed combination, \r\n, to force line breaks at particular locations.Note that the text buffer specified by the szText member of the NMTTDISPINFO structure can accommodate only 80 characters. If you need to use a longer string, point the lpszText member of NMTTDISPINFO to a buffer containing the desired text.The following code fragment is an example of a simple TTN_GETDISPINFO notification handler. It creates a multiline ToolTip by setting the display rectangle to 300 pixels and setting the lpszText member of NMTTDISPINFO to point to a buffer with the desired text.char szLongMessage[ ] =
    "This is a long message for the ToolTip, which will automatically "
    "be wrapped when it exceeds the maximum tip width.  "
    "Alternatively, you can use a \r\n"
    "carriage return/line feed combination\r\n"
    "to force line breaks at specific\r\n"
    "locations.";switch (lpnmhdr->code) {
      case TTN_GETDISPINFO:
        lpttd = (LPNMTTDISPINFO)lpnmhdr;
        SendMessage(lpnmhdr->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 300);
        lpttd->lpszText = szLongMessage;
        return 0;

    ...
     //Other notification handlers go here, as needed.
    }