zoukankan      html  css  js  c++  java
  • CToolTipCtrl的使用实例MSDN

    如何操纵CToolTipCtrl来给自己的控件添加tool tip呢?MSDN给出了答案。

    创建并操纵一个CToolTipCtrl

    =======================

    1. 创建一个CToolTipCtrl的对象.

    2. 调用Create函数来创建windows通用提示控件并使之与CToolTipCtrl对象产生关联。

    3. 调用AddTool函数来把tool tip control注册到一个tool上,这样存储在tool tip中的信息就能在光标悬浮在这个tool上的时候显示出来。

    4. 调用SetToolInfo来设置tool tip为这个tool所保留的信息。

    5. 调用SetToolRect来设置该tol的一个新的范围矩形。

    6. 调用HitTest函数来判断一个点是否在某个给定tool的范围矩形之内,如果是的话,就返回这个tool的信息。

    7. 调用GetToolCount来得到一个tool tip所关联到的tool的个数。

    // Create and associate a tooltip control to the tab control of 
    // CMyPropertySheet.  CMyPropertySheet is a CPropertySheet-derived
    // class.
    BOOL CMyPropertySheet::OnInitDialog() 
    ...{
        BOOL bResult = CPropertySheet::OnInitDialog();
    
        // Create a tooltip control.  m_ToolTipCtrl is a member variable
        // of type CToolTipCtrl* in CMyPropertySheet class.  It is 
        // initialized to NULL in the constructor, and destroyed in the 
        // destructor of CMyPropertySheet class.
        m_ToolTipCtrl = new CToolTipCtrl;// 第一步,创建对象
        if (!m_ToolTipCtrl->Create(this)) //第二步,调用Create函数
            ...{
                TRACE("Unable To create ToolTip ");           
                return bResult;
        }
    
        // Associate the tooltip control to the tab control
        // of CMyPropertySheet.
        CTabCtrl* tab = GetTabControl();
        tab->SetToolTips(m_ToolTipCtrl);
        // Get the bounding rectangle of each tab in the tab control of the
        // property sheet. Use this rectangle when registering a tool with 
        // the tool tip control.  IDS_FIRST_TOOLTIP is the first ID string 
        // resource that contains the text for the tool.
        int count = tab->GetItemCount();
        int id = IDS_FIRST_TOOLTIP;
        for (int i = 0; i < count; i++)
            ...{
                id += i;
                CRect r;
                tab->GetItemRect(i, &r);
                VERIFY(m_ToolTipCtrl->AddTool(tab, id, &r, id));
        }
    
        // Activate the tooltip control.
        m_ToolTipCtrl->Activate(TRUE);
    
        return bResult;
    }
    
    // Override PreTranslateMessage() so RelayEvent() can be 
    // called to pass a mouse message to CMyPropertySheet's 
    // tooltip control for processing.
    BOOL CMyPropertySheet::PreTranslateMessage(MSG* pMsg) 
    ...{
        if (NULL != m_ToolTipCtrl)            
            m_ToolTipCtrl->RelayEvent(pMsg);
    
        return CPropertySheet::PreTranslateMessage(pMsg);
    }
  • 相关阅读:
    UVA 10618 Tango Tango Insurrection
    UVA 10118 Free Candies
    HDU 1024 Max Sum Plus Plus
    POJ 1984 Navigation Nightmare
    CODEVS 3546 矩阵链乘法
    UVA 1625 Color Length
    UVA 1347 Tour
    UVA 437 The Tower of Babylon
    UVA 1622 Robot
    UVA127-"Accordian" Patience(模拟)
  • 原文地址:https://www.cnblogs.com/awpatp/p/1597042.html
Copyright © 2011-2022 走看看