关闭

CToolTipCtrl

579人阅读 评论(0) 收藏 举报

MSDN CToolTioCtrl类介绍

Visual Studio 6.0

CToolTipCtrl Class Members

Construction

CToolTipCtrl Constructs a CToolTipCtrl object.
Create Creates a tool tip control and attaches it to a CToolTipCtrl object.

Attributes

GetText Retrieves the text that a tool tip control maintains for a tool.
GetToolInfo Retrieves the information that a tool tip control maintains about a tool.
SetToolInfo Sets the information that a tool tip maintains for a tool.
GetToolCount Retrieves a count of the tools maintained by a tool tip control.
GetDelayTime Retrieves the initial, pop-up, and reshow durations currently set for a tool tip control.
SetDelayTime Sets the initial, pop-up, and reshow durations for a tool tip control.
GetMargin Retrieves the top, left, bottom, and right margins set for a tool tip window.
SetMargin Sets the top, left, bottom, and right margins for a tool tip window.
GetMaxTipWidth Retrieves the maximum width for a tool tip window.
SetMaxTipWidth Sets the maximum width for a tool tip window.
GetTipBkColor Retrieves the background color in a tool tip window.
SetTipBkColor Sets the background color in a tool tip window.
GetTipTextColor Retrieves the text color in a tool tip window.
SetTipTextColor Sets the text color in a tool tip window.

Operations

Activate Activates and deactivates the tool tip control.
AddTool Registers a tool with the tool tip control.
DelTool Removes a tool from the tool tip control.
HitTest Tests a point to determine whether it is within the bounding rectangle of the given tool and, if so, retrieves information about the tool.
RelayEvent Passes a mouse message to a tool tip control for processing.
SetToolRect Sets a new bounding rectangle for a tool.
UpdateTipText Sets the tool tip text for a tool.
Update Forces the current tool to be redrawn.
Pop Removes a displayed tool tip window from view.

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

创建并操纵一个CToolTipCtrl
创建一个CToolTipCtrl的对象.

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

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

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

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

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

调用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);
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:782098次
    • 积分:10671
    • 等级:
    • 排名:第1512名
    • 原创:250篇
    • 转载:101篇
    • 译文:27篇
    • 评论:99条
    最新评论