?
Solved

Add tooltip to a child window

Posted on 2002-05-22
11
Medium Priority
?
795 Views
Last Modified: 2013-11-20
I want to add tooltip to an ocx control placed on a dialog child window. I also have for the ocx mouse move event.
I used:

EnableToolTips(TRUE);
...
ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify)
...
BOOL CTopologyDlg::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
{    
    TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
    UINT nID =pNMHDR->idFrom;
    if (pTTT->uFlags & TTF_IDISHWND)
    {
        // idFrom is actually the HWND of the tool
        nID = ::GetDlgCtrlID((HWND)nID);
        if(nID)
        {
            pTTT->lpszText = MAKEINTRESOURCE(nID);
            pTTT->hinst = AfxGetResourceHandle();
            return(TRUE);
        }
    }
     return(TRUE);
}

What else do I need ?

Thanks.
0
Comment
Question by:yonit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
11 Comments
 
LVL 16

Expert Comment

by:AlexNek
ID: 7027312
2 yonit
Do you need one tooltip for the Ocx item in a dialog or you need different tooltips in the Ocx item area? Which problems do you have?

PS:
nID = ::GetDlgCtrlID((HWND)nID);
Hurrah, Microsoft programming style!! :(
0
 

Author Comment

by:yonit
ID: 7027322
I need just one in the mouse over event.
I don't see the toolbar.
any other code is welcome :)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:yonit
ID: 7027336
Do I have to use CToolTipCtrl ?
I see samples without the control
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 7027362
>I don't see the toolbar.
Do you want the toolbar on the dialog?

Here is the way for tooltip control:

class CTooltipControl: public CStatic
{
...
  CToolTipCtrl m_ToolTip;
};

void CTooltipControl::PreSubclassWindow()
{
..
     // Create the tooltip
     CRect rect;
     GetClientRect(rect);
     m_ToolTip.Create(this);
     m_ToolTip.AddTool(this, "My Tooltip", rect, TOOLTIP_ID);

     CStatic::PreSubclassWindow();
}

BOOL CTooltipControl::PreTranslateMessage(MSG* pMsg)
{
     m_ToolTip.RelayEvent(pMsg);
     return CStatic::PreTranslateMessage(pMsg);
}
0
 

Author Comment

by:yonit
ID: 7027375
no toolbar. just tooltip
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 7027381
TESTHELP: ActiveX Control with Tooltips and Help. (Sample only on CD, I have it)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample/html/_sample_mfc_testhelp.asp
0
 
LVL 16

Accepted Solution

by:
AlexNek earned 1200 total points
ID: 7027391
class CTesthelpCtrl : public COleControl
{
      void RelayEvent(UINT message, WPARAM wParam, LPARAM lParam);
      CToolTipCtrl m_ttip;
};


void CTesthelpCtrl::RelayEvent(UINT message, WPARAM wParam, LPARAM lParam)
{
            // This function will create a MSG structure, fill it in a pass it to
            // the ToolTip control, m_ttip.  Note that we ensure the point is in window
            // coordinates (relative to the control's window).
            if(NULL != m_ttip.m_hWnd)
            {
                         MSG msg;
                         msg.hwnd = m_hWnd;
                         msg.message = message;
                         msg.wParam = wParam;
                         msg.lParam = lParam;
                         msg.time = 0;
                         msg.pt.x = LOWORD(lParam);
                         msg.pt.y = HIWORD(lParam);

                         m_ttip.RelayEvent(&msg);
            }

}

int CTesthelpCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
            if (COleControl::OnCreate(lpCreateStruct) == -1)
                         return -1;
            // The following code will create a the ToolTip control
            // once the ocx's window is created.
            if(!m_ttip.Create(this))
                TRACE(_T("Unable to Create ToolTip"));
            else
                if(!m_ttip.AddTool(this, LPCTSTR(m_szToolTipText)))
                     TRACE(_T("Unable to add tip for the control window"));
                else
                     m_ttip.Activate(m_bShowToolTip);


            return 0;
}

void CTesthelpCtrl::OnShowToolTipChanged()
{
            // Activate or DeActivate the ToolTip
            if(m_ttip.m_hWnd && AmbientUserMode())
            {
                 m_ttip.Activate(m_bShowToolTip);
                 SetModifiedFlag();
            }
}

void CTesthelpCtrl::OnToolTipTextChanged()
{
            // Change the ToolTip's text
            if(m_ttip.m_hWnd && AmbientUserMode())
            {
                 m_ttip.UpdateTipText((LPCTSTR)m_szToolTipText,this);
                 SetModifiedFlag();
            }

}
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question