Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get tooltip info in MFC

Status
Not open for further replies.

gorgor

Programmer
Aug 15, 2002
164
0
0
US
I'm having trouble getting info from a tool tip in MFC. I initialize a tooltip:

m_pToolTip->Create(this, TTS_NOPREFIX);
m_pToolTip->SetMaxTipWidth(SHRT_MAX);
m_pToolTip->SetTipTextColor(0x000000ff);//0x00bbggrr
m_pToolTip->SetDelayTime(TTDT_AUTOPOP, 1000*60*60*24); //leave tooltip popped up for 1 day
m_pToolTip->SetDelayTime(TTDT_INITIAL, 0); //instant tool tips
m_pToolTip->AddTool(this, "", NULL, 0);
m_pToolTip->Activate(FALSE);

And later I want to get the bounding rectangle of the tooltip. However, I can't find any examples on how to get the information. Here's what I've tried:

CToolInfo toolInfo;
m_pToolTip->GetToolInfo(toolInfo, this, 0);
CRect rect = toolInfo.rect;

For some reason this doesn't seem to work. I try to setup a quick watch on "rect" when I debug, and it is telling me "Error: symbol "rect" not found". Could someone please show me how to fix my code so that I can retrieve the information on the tooltip?

Thanks in advance!
 
I guess it may be important to note that the tooltip gets activated later in the program and gettoolinfo isn't called until after the tooltip is activated.
 
Hi,
I did it on Win32-SDK based programs...Steps are
1.Create tooltip window in WM_INITDIALOG as-

hWndToolTip = CreateWindowEx(0, TOOLTIPS_CLASS,NULL, WS_POPUP |TTS_NOPREFIX|TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, 10, 10, hDlg, NULL, hIsntance, NULL);

Then fill the names of controls in this event WM_INITDIALOG as-
TOOLINFO ti[5];
for(int iCntr=0;iCntr <5;iCntr++)
{
ZeroMemory(&ti[iCntr], sizeof(ti[iCntr]));
ti[iCntr].cbSize = sizeof(ti[iCntr]);
ti[iCntr].uFlags = TTF_IDISHWND | TTF_SUBCLASS;
ti[iCntr].hwnd = hDlg;
switch(iCntr)
{
case 0: ti[iCntr].uId = (UINT)GetDlgItem(hDlg, IDC_BUTT1);
break;
.....

2. Then you should fill the case WM_MOUSEMOVE:
{
MSG msg;

//we need to fill out a message structure and pass it to the tooltip
//with the TTM_RELAYEVENT message
msg.hwnd = hDlg;
.....
SendMessage(hWndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
.......

3.Then you can give tooltip text in WM_NOTIFY event as-
LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)lParam;
switch (lpttt->hdr.code)
{
case TTN_NEEDTEXT:
{
if (lpttt->hdr.idFrom == (UINT)GetDlgItem(hDlg, IDC_BUTT1))
{
lstrcpy(lpttt->szText, TEXT(&quot;your tooltip&quot;));
break;
}
....
....

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top