CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2006
    Posts
    52

    Tooltips not working for all controls in CFormView derived class

    I can't get tooltips to show up for the windows I want in my CFormView derived class. I have copied the code from the MSDN entry on EnableToolTips(). But only two windows respond with a tooltip:

    CONTROL "Tree1",IDC_TESTPLANS,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_EDITLABELS | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,1,36,85,91
    CONTROL "Tab1",IDC_TABCMD,"SysTabControl32",0x0,101,0,239,181

    Other windows do not respond. For these windows my function designed to catch the TTN_NEEDTEXTW and TTN_NEEDTEXTA messages is not called. Windows such as

    LISTBOX IDC_TESTPLANNAMES,0,119,48,40,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
    PUSHBUTTON "",IDC_BTN_COPY,105,177,24,24,BS_ICON

    Why wouldn't the messages be sent for those windows? I'm using the code

    ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &CCntlrView::OnTtnNeedText)
    ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &CCntlrView::OnTtnNeedText)

    (CCntrlView is the name of my class derived from CFormView.) And as I pointed out, I'm using the code straight from the example given in MSDN for CWnd::EnableToolTips(), with the only difference being that all my controls are created in the rc file as shown above.

    Any help appreciated.

    Thanks,
    Gary

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

    Re: Tooltips not working for all controls in CFormView derived class

    Show your CCntlrView::OnTtnNeedText method.
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2006
    Posts
    52

    Re: Tooltips not working for all controls in CFormView derived class

    Thanks for your quick reply! Here is the method:

    BOOL CCntlrView::OnTtnNeedText(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
    {

    UNREFERENCED_PARAMETER(id);
    UNREFERENCED_PARAMETER(pResult);

    // need to handle both ANSI and UNICODE versions of the message

    TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
    TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
    CStringA strTipText;
    UINT_PTR nID = pNMHDR->idFrom;
    if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
    pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
    {
    // idFrom is actually the HWND of the tool

    nID = ::GetDlgCtrlID((HWND)nID);
    }

    if (nID != 0) // will be zero on a separator

    strTipText.Format("Control ID = %d", nID);

    if (pNMHDR->code == TTN_NEEDTEXTA)
    {
    strncpy_s(pTTTA->szText, sizeof(pTTTA->szText), strTipText,
    strTipText.GetLength() + 1);
    }
    else
    {
    ::MultiByteToWideChar(CP_ACP , 0, strTipText, strTipText.GetLength() + 1,
    pTTTW->szText, sizeof(pTTTW->szText)/(sizeof pTTTW->szText[0]));
    }
    return TRUE;
    }

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

    Re: Tooltips not working for all controls in CFormView derived class

    First edit your post to add the Code tags around code snippets! Otherwise it is hard to read/understand it!
    Second, if you set a breakpoint in the beginning of the function and debug the code - will you go in there and for which controls?
    Victor Nijegorodov

  5. #5
    Join Date
    Aug 2006
    Posts
    52

    Re: Tooltips not working for all controls in CFormView derived class

    Wow, you are fast! Sorry about the lack of tags. I should have mentioned that I already put in a breakpoint at the beginning of the method. As expected, when the cursor is overthe control windows that show tooltips (IDC_TESTPLANS and IDC_TABCMD) the breakpoint breaks and the tooltips are displayed when the program is allowed to run. For any other control, when I have the cursor over the control, the function is not called (no break), and of course no tooltip is displayed. I should mention that IDC_TABCMD is behind other windows with only the tabs showing. When the mouse goes over the tabs of IDC_TABCMD, I get the tooltip showing. IDC_TESTPLANS is on top of IDC_TABCMD. The other windows that aren't working are also on top of IDC_TABCMD or to the side. I also tried creating one of the buttons on the fly as shown in the example for EnableToolTips. That is, I took a button's definition out of the rc file and added the following before the EnableToolTips():
    Code:
     	m_CopyFile.Create("", BS_PUSHBUTTON | BS_ICON, CRect(105,177,129,204), this, IDC_BTN_COPY);
    	m_CopyFile.SetIcon(GETAPP->LoadIcon(IDI_COPY));
    
    	EnableToolTips();
    It made no difference, the tooltips did not appear. I also tried it without the icon code above; still didn't work. Also I should mention that all the windows are moved to get to their initial positions, and move as the program's window changes size.

    Gary

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

    Re: Tooltips not working for all controls in CFormView derived class

    What if you would also handle TTN_NEEDTEXT Notification like in http://msdn.microsoft.com/en-us/libr...=vs.100).aspx?
    Victor Nijegorodov

  7. #7
    Join Date
    Aug 2006
    Posts
    52

    Re: Tooltips not working for all controls in CFormView derived class

    Actually, that's what I tried first and is why my function is called OnTtnNeedText. I copied the same code into it. Later on when I saw the more complicated method, I tried that, but got the same result: works for the two controls mentioned above, not for the others. Since you said "also", I now tried all three, so that I have:
    Code:
    	ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &CCntlrView::OnTtnNeedText)
    	ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &CCntlrView::OnTtnNeedText)
    	ON_NOTIFY_EX(TTN_NEEDTEXT, 0, &CCntlrView::OnTtnNeedText)
    Still it doesn't break in OnTtnNeedText for the controls that don't work. Thanks for your suggestions.

    Gary

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Tooltips not working for all controls in CFormView derived class

    Well, I use this technique since more than a decade and it worked for me in VC++6.0 and it is still working in VC 2010.
    Could you post tha small test project reproducing your problem, so we would try to investigate it?
    Victor Nijegorodov

  9. #9
    Join Date
    Aug 2006
    Posts
    52

    Re: Tooltips not working for all controls in CFormView derived class

    I'd be interested but I'm not familiar with the "small test project" (I searched the FAQ and other places but couldn't find it.) Does the "small" mean I reduce my enormous program down to the simplest form that has the problem and post the code somewhere?

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Tooltips not working for all controls in CFormView derived class

    Quote Originally Posted by garyflet View Post
    ... Does the "small" mean I reduce my enormous program down to the simplest form that has the problem and post the code somewhere?
    Yes.
    Victor Nijegorodov

  11. #11
    Join Date
    Aug 2006
    Posts
    52

    Re: Tooltips not working for all controls in CFormView derived class

    Here is a small version that doesn't work just like (I hope) the larger version of the program. There's a difference in behavior in the small version in that most of the controls don't appear until you resize the window. And my OnTtnNeedText() is never called in the small version. The buttons that I want to have tool tips are seen in the lower left corner after resizing the window. A delete (trash can), new file and copy file buttons. Thanks a lot for your help!
    Attached Files Attached Files

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Tooltips not working for all controls in CFormView derived class

    You forgot to add the Res subfolder to the archive.
    And BTW, there are no tooltips shown for your toolbar buttons either!
    I'd suggest you to start testing with a very simple "classic" SDI application with one push button... Then add additional controls...
    Victor Nijegorodov

  13. #13
    Join Date
    Aug 2006
    Posts
    52

    Re: Tooltips not working for all controls in CFormView derived class

    Sorry about not including the res directory. I have attached a file with the directory. To create the smalltest project, I did start with a simple default SDI project. Then I added the buttons that I cannot make tool tip functionality for, and added code to create them and resize them as they are in the original project. Other items came by default, such as the toolbar, and I'm not concerned with tool tips not working there because I made no attempt to add them. As mentioned before, the buttons I'm trying to get working are the buttons that are in the lower left corner after the user resizes the window. There is tool tip code for them, but it doesn't work. You might be able to see quickly why the tool tip code doesn't work.

    Thanks for your help,
    Gary
    Attached Files Attached Files

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured