Click here to Skip to main content
15,891,607 members
Articles / Desktop Programming / MFC
Article

ParamTooltip

Rate me:
Please Sign up or sign in to vote.
4.69/5 (20 votes)
11 Nov 20041 min read 40.6K   1.7K   35   1
Implements a Tooltip control like that displayed with the Intellisense technology.

Sample Image of the demo ParamTooltip

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer Dreaming With Objects S.L.
Spain Spain
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralDestroyWindow Pin
Roger6519-Nov-04 4:07
Roger6519-Nov-04 4:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.