Click to See Complete Forum and Search --> : How do I use a "dynamic" tool tip in a CView?


hiltonc
April 8th, 1999, 03:05 PM
I have a standard doc-view app, and i want to display a tool tip whenever the mouse moves on the view. the tip is going to display the coordinates of the mouse. what is the best way to do this?

Harvey Hawes
April 8th, 1999, 05:20 PM
Hi,

There is an excellent article in the back issues of Microsoft System Journal (MSJ). I think it's either in MSJ April 97 or 98. There is a picture on the cover. You can download the source from microsoft. Works well.

HTH,

Harvey

Harvey Hawes

Software Engineer
BioScience Analysis Software Ltd.

Masters Candidate
Cardiovascular/Respiratory Sciences
Faculty of Medicine
University of Calgary
Calgary, Alberta, Canada

Mallik Bulusu
April 9th, 1999, 01:22 AM
In the view class declare following variables (i declared it as public, you can decide on that):

class CMyView : public CView
{
.....
....
public:
CRect toolRect;
CToolTipCtrl m_ToolTip;
CPoint oldPt;
....
...
};

void CMyView::OnInitialUpdate()
{

.....
....
....

//initialize oldPt to (0,0)
oldPt.x = 0;
oldPt.y = 0;

//create the tooltipctrl
m_ToolTip.Create(this,TTS_ALWAYSTIP);
this->GetWindowRect(&toolRect);
ScreenToClient(&toolRect);
}


BOOL CMyView::PreTranslateMessage(MSG* pMsg)
{
POINT pTemp = pMsg->pt;
CString cstrToolTip;
switch (pMsg->message)
{
case WM_MOUSEMOVE:
if((oldPt.x != pMsg->pt.x) ||(oldPt.y != pMsg->pt.y))
{
m_ToolTip.DelTool(this, IDD_VIEW_ID);

cstrToolTip.Format("[%d ,%d]",pTemp.x, pTemp.y);




//id of the form view in resource is needed for addtool call below.

m_ToolTip.AddTool(this, (LPCTSTR)cstrToolTip, &toolRect, IDD_VIEW_ID);
m_ToolTip.Activate(TRUE);
m_ToolTip.SetDelayTime(1000);
m_ToolTip.RelayEvent(pMsg);

oldPt.x = pMsg->pt.x;
oldPt.y = pMsg->pt.y;
}
default:
break;
}
return

//depends on the view you derive from, call its pretranslatemessage....
CFormView::PreTranslateMessage(pMsg);

}