Solved

Add tooltip to a child window

Posted on 2002-05-22
11
780 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

18 Experts available now in Live!

Get 1:1 Help Now