Solved

Add tooltip to a child window

Posted on 2002-05-22
11
782 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
  • 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
 
LVL 16

Expert Comment

by:AlexNek
ID: 7027324
0
 

Author Comment

by:yonit
ID: 7027336
Do I have to use CToolTipCtrl ?
I see samples without the control
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now