Introduction
This article demonstrates creating a class to show tooltips for methods and its parameters, like Intellisense technology.
Using the class
Using the class is easy. You only have to instantiate an object, create the control and add information about the methods and its parameters, and then show it in any screen position.
Create a ParamTooltipCtrl in your application
Include ParamTooltipCtrl.h in the source file where you want to use the CParamTooltipCtrl
control:
#include "ParamTooltipCtrl.h"
Create a member variable for the control:
CParamTooltipCtrl m_wndTT;
Create the control and initialize it with the names of methods and their parameters:
m_wndTT.Create(this);
CString sMethod;
vector<CString> setParams;
sMethod = "int DrawText";
setParams.push_back(CString("const CString &str"));
setParams.push_back(CString("LPRECT lpRect"));
setParams.push_back(CString("UINT nFormat"));
m_wndTT.AddMethod(sMethod, setParams);
setParams.resize(0);
setParams.push_back(CString("LPCTSTR lpszString"));
setParams.push_back(CString("int nCount"));
setParams.push_back(CString("LPRECT lpRect"));
setParams.push_back(CString("UINT nFormat"));
m_wndTT.AddMethod(sMethod, setParams);
Show the ParamTooltipCtrl control in the screen
When you want to show the control, call the methods SetCurMethod
and SetCurParam
to set the method and parameter you want to emphasize, and then call the method ShowTooltip
:
m_wndTT.SetCurMethod(0);
m_wndTT.SetCurParam(1);
m_wndTT.ShowTooltip(CPoint(300,300));
To hide the control, call the CWnd::ShowWindow
method:
m_wndTT.ShowWindow(SW_HIDE);
Iterate between methods and parameters
To iterate between the previous and next methods, and previous and next parameters, use the ShowPrevMethod
, ShowNextMethod
, ShowPrevParam
and ShowNextParam
methods:
void CParamToolTipView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch( nChar ) {
case VK_UP:
m_wndTT.ShowPrevMethod();
break;
case VK_DOWN:
m_wndTT.ShowNextMethod();
break;
case VK_LEFT:
m_wndTT.ShowPrevParam();
break;
case VK_RIGHT:
m_wndTT.ShowNextParam();
break;
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
Points of Interest
The method CParamTooltipCtrl::Draw
draws the bitmaps creating it in memory, so you don't have to load it from resources.
History
Version 1.0 - Wed, 10 Nov of 2004.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.