Solved

Add tooltip to a child window

Posted on 2002-05-22
11
794 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
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!

 

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 300 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

724 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