Sunday, August 24, 2008

Adding Tooltip To An ActiveX Control

By default, ActiveX controls do not support tooltips. This article demonstrates how to add tooltip to an ActiveX control. This control can be used to add tooltips to ActiveX controls that we develop. Steps Involved: We have used the 'MFC ActiveX Control Wizard' to develop the 'mytooltip' control. The steps involved are enumerated below:

(a) Select 'MFC ActiveX Control Wizard' as new project type with project name as 'mytooltip'. Click on 'OK'. to let the wizard generate the code.

(b) Open the 'stdafx.h' file associated with the project and add the following line: #include

The header file 'afxcmn.h' contains declarations for MFC classes that serve as wrappers to Windows Common Controls including CToolTipCtrl. Add the following lines to COleControl-derived class CMytooltipCtrl located in 'mytooltipctl.h': CToolTipCtrl m_ttip; Use ClassWizard to add an OnCreate( ) handler to the message map. It is in this routine that the ToolTip control will be created. Add the following code to this handler:

m_ttip.Create ( this ) ;
m_ttip.AddTool ( this, LPCTSTR ( m_toolTipText ) ) ;
m_ttip.SetTipBkColor ( RGB ( 255,255,0 ) ) ;
m_ttip.SetTipTextColor ( RGB ( 255,0,0 ) ) ;

Alter CMytooltipCtrl::DoPropExchange( ) by adding code to initialize the m_toolTipText and m_showToolTip properties:

PX_Bool(pPX, _T("ShowToolTip"), m_showToolTip, FALSE);
PX_String(pPX, _T("ToolTipText"), m_toolTipText, _T(""));

To allow the user of the control some control over the ToolTip functionality, use ClassWizard to add the following Automation properties to the CBasicCtrl class:

External Name: ShowToolTip ToolTipText
Type: BOOL CString
Variable name: m_showToolTip m_toolTipText
Notification function: OnShowToolTipChanged OnToolTipTextChanged

ShowToolTip will allow the user to suppress the display of the tooltip, and ToolTipText will track the text that is to be displayed when the tooltip is visible. To make this work we have added a virtual function PreTranslateMessage( ) to the control class and called RelayEvent( ) function from it.

1 comment:

Mohammad Hawash said...

thanks nice stuff

Add downloads

Your Title