Solved

Add tooltip to a child window

Posted on 2002-05-22
11
788 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 79
Complete beginner needs help making a cron job 9 125
sum67 challenge 35 107
Way to decrease size of apk file 9 86
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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 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