dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: CMFCToolTipCtrl in CView

  1. #1
    Join Date
    Jan 2009
    Posts
    290

    CMFCToolTipCtrl in CView

    Hi everyone. Would you give me a solution to a following issue: on an MDI app, with CView as CMyView, and here a spread a self developed control, derived from CWnd. This control draw some rectangles. The issue here is to display a CMFCToolTipCtrl when I am with mouse over these rectangles ... that is all. But I didn't make it by now.

    I have tried to handle
    Code:
    ON_NOTIFY(TTN_NEEDTEXT, ID_MYCTRL, OnGetTooltipText)
    in CMyView ... OnGetTooltipText is not called.

    If I pass OnMouseMove from CMyCtrl (derived CWnd) to CMyView, and is this handler to call CMFCToolTipCtrl::Popup() is happen something: the tooltip is showing, CMyView is loosing the focus, and tooltip is closing, the CMyView is get the focus again, and CMyCtrl is send again OnMouseMove to the parent, which is CMyView, the tooltip is show again, and this is looping foe ever, which reveal me that is not the right solution ...

    this is the architecture of my CMyView:
    Code:
    void CMyView::OnInitialUpdate()
    {
    	CView::OnInitialUpdate();
    
    	VERIFY(m_pMyCtrl->Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL, CRect(0, 0, 0, 0), this, ID_MYCTRL));
    ...
    }
    and
    Code:
    void CMyView::OnSize(UINT nType, int cx, int cy)
    {
    	CView::OnSize(nType, cx, cy);
    
    	// TODO: Add your message handler code here
    	if (NULL != m_pMyCtrl->GetSafeHwnd() && cx > 0 && cy > 0)
    	{
    		CRect rect(CPoint(0, 0), CSize(cx, cy));
    		m_pMyCtrl->MoveWindow(rect);
    	}
    }
    how you would show correctly a tooltip when you mouse pointer is somewhere on view ? What is the right way to do this ?

    Thank you for any hint.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,405

    Re: CMFCToolTipCtrl in CView

    Maybe this MSDN article could help you: How to Create a Tooltip for a Rectangular Area?
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2009
    Posts
    290

    Re: CMFCToolTipCtrl in CView

    Hi Victor, and thank you for your post. There is a small problem regarding this example, this one is showing the tooltip for a rectangle who is already setup during creation, and in my case the tooltip should be visible only when the mouse pointer is hovering certain rectangles inside of my control, control which is spread over entire CMyView ...

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,405

    Re: CMFCToolTipCtrl in CView

    Quote Originally Posted by mesajflaviu View Post
    Hi Victor, and thank you for your post. There is a small problem regarding this example, this one is showing the tooltip for a rectangle who is already setup during creation, and in my case the tooltip should be visible only when the mouse pointer is hovering certain rectangles inside of my control, control which is spread over entire CMyView ...
    You could update tooltip data after moving/resizing your control. Just use TTM_SETTOOLINFO message!
    Victor Nijegorodov

  5. #5
    Join Date
    Jan 2009
    Posts
    290

    Re: CMFCToolTipCtrl in CView

    Quote Originally Posted by VictorN View Post
    You could update tooltip data after moving/resizing your control. Just use TTM_SETTOOLINFO message!
    Ok, I'll try.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,405

    Re: CMFCToolTipCtrl in CView

    BTW, you could use MFC class CToolTipCtrl (or CMFCToolTipCtrl) and its methods like CToolTipCtrl::AddTool, CToolTipCtrl::SetToolRect rather than directly sending TTM_... messages.
    See https://docs.microsoft.com/en-us/cpp...s?view=vs-2019
    Victor Nijegorodov

  7. #7
    Join Date
    Jan 2009
    Posts
    290

    Re: CMFCToolTipCtrl in CView

    Yes, but that rectangles are changing dynamically, so I guess this is the long road to achieve the task ... I have in CMyCtrl a HitTest(CPoint pt) method which return me an item ID ... I guess sending TTM_ messages will be more suitable ... but I don't know if I could use CMFCToolTipCtrl with these messages (TTM_). I am studying this issue ...

  8. #8
    Join Date
    Jan 2009
    Posts
    290

    Re: CMFCToolTipCtrl in CView

    Quote Originally Posted by VictorN View Post
    BTW, you could use MFC class CToolTipCtrl (or CMFCToolTipCtrl) and its methods like CToolTipCtrl::AddTool, CToolTipCtrl::SetToolRect rather than directly sending TTM_... messages.
    See https://docs.microsoft.com/en-us/cpp...s?view=vs-2019
    You are right, I think I can use CMFCToolTipCtrl with AddTool/SetToolRect methods ...

    Thank you.

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,405

    Re: CMFCToolTipCtrl in CView

    You are welcome!
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)