How to set a Tool Tip for a window

9 02 2009

description2

 

 

Consider a situation that you have a dialog based application that contains several buttons and you want to appear tool tips when the user puts the cursor on the buttons and disappear when the cursor leave.

tool-tip-sample

 howcanidoit2

  

 

MFC provides a CToolTipCtrl  class for the Windows common tool tip control. Actually this is a CWnd derived class. Also we can customize the tool tip text and background by the functions SetTipBkColor, SetTipTextColor etc.

mycodesnippet2

 

 

CToolTipCtrl* m_ToolTip;
BOOL CMyDialog::OnInitDialog()
{
   //create a tool tip control
   m_ToolTip= new CToolTipCtrl();
   m_ToolTip->Create(this);
  
   //Get the button
   CWnd* pWnd = GetDlgItem(IDC_MY_TOOL_TIP_BUTTON);
  
   //add tool tip for our particular button
   m_ToolTip->AddTool(pWnd,"Click here for registering...");
  
   //activate the tool tip
   m_ToolTip->Activate(TRUE);
  
   //*** you could change the defualt settings ***
   //m_ToolTip->SetTipBkColor(RGB(0,255,0));
   //m_ToolTip->SetTipTextColor(RGB(255,0,0))

   return TRUE;
}

mynote2

 

 

Please refer the CToolTipCtrl class specific styles  TTS_ALWAYSTIP and  TTS_NOPREFIX in  the MSDN.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: