locked
Tooltip text problem RRS feed

  • Question

  • I wrote the function below to add text to a tooltip.  It isn't writing the text, but no errors are generating. Any ideas what I'm doing wrong?  It's a 64-bit app using Visual Studio 2013 - I created the tooltip like this:

             xstyle=WS_EX_TOPMOST;
             style=WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON;

             htooltip=CreateWindowEx(xstyle,TOOLTIPS_CLASS,NULL,style,0,0,0,0,hwnd,(HMENU)800,hinstance,NULL);

    And this is the function: (the strtowstr() is a function that works in dozens of places in my program, so that is not the problem)

    VOID settexttooltip(HWND hwnd,HWND htooltip,HWND hctl,std::string stxt)
    {
         std::wstring wtxt=strtowstr(stxt);
         TOOLINFO ti={0};

         ti.cbSize=sizeof(TOOLINFO);
         ti.uFlags=TTF_SUBCLASS | TTF_IDISHWND;
         ti.hwnd=hwnd;
         ti.uId=(UINT_PTR)hctl;
         //ti.lpszText=const_cast<wchar_t*>(wtxt.c_str());
         ti.lpszText=(LPWSTR)wtxt.c_str();

         SendMessage(htooltip,TTM_ADDTOOL,0,(LPARAM)&ti);
         return;
    }



    • Edited by TallGuy63 Thursday, August 25, 2016 9:19 PM
    Thursday, August 25, 2016 9:16 PM

Answers

  • As an afterthought -- did the app include a manifest for the v6 common controls dll?
    • Marked as answer by TallGuy63 Friday, August 26, 2016 2:37 PM
    Friday, August 26, 2016 2:59 AM
  • Calling InitCommonControls isn't enough.  You need to include a manifest for the v6 common controls dll.  An easy way is to put the following into your code -

    #if defined _M_IX86
      #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_IA64
      #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_X64
      #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #else
      #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #endif

    BTW, your code should be -

    icc.dwICC=ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES | ICC_TAB_CLASSES | ICC_PROGRESS_CLASS;

    or you coud use

    icc.dwICC=ICC_WIN95_CLASSES;



    • Edited by RLWA32 Friday, August 26, 2016 10:57 AM
    • Marked as answer by TallGuy63 Friday, August 26, 2016 2:37 PM
    Friday, August 26, 2016 9:10 AM

All replies

  • Two thoughts --

    1. Why are you  using (HMENU)800 in the call to CreateWindowEx?

    2. Send the tooltip control a TTM_ACTIVATE message with wParam TRUE after TTM_ADDTOOL.

    Thursday, August 25, 2016 10:22 PM
  • I added the TTM_ACTIVATE after each add and it made no difference; same problem.  The tooltips do not come up.

    VOID settexttooltip(HWND hwnd,HWND htooltip,HWND hctl,std::string stxt)
    {
         std::wstring wtxt=strtowstr(stxt);
         TOOLINFO ti={0};

         ti.cbSize=sizeof(TOOLINFO);
         ti.uFlags=TTF_SUBCLASS | TTF_IDISHWND;
         ti.hwnd=hwnd;
         ti.uId=(UINT_PTR)hctl;
         ti.lpszText=(LPWSTR)wtxt.c_str();

         SendMessage(htooltip,TTM_ADDTOOL,0,(LPARAM)&ti);
         SendMessage(htooltip,TTM_ACTIVATE,TRUE,0);

         return;
    }

    Friday, August 26, 2016 1:27 AM
  • You must replace (HMENU) 800 in CreateWindowEx for the tooltip with NULL.

    • Edited by RLWA32 Friday, August 26, 2016 2:40 AM
    Friday, August 26, 2016 2:34 AM
  • Hi TallGuy63,

    thanks for posting here.

    >>I added the TTM_ACTIVATE after each add and it made no difference; same problem.  The tooltips do not come up.

    When you add a tool to a tooltip control, the lpszText member of the TOOLINFO structure must specify the address of the string to display for the tool. After you add a tool, you can change the text using the TTM_UPDATETIPTEXT message.

    For more information, please refer to this document.

    https://msdn.microsoft.com/en-us/library/windows/desktop/bb760250(v=vs.85).aspx#Activation

    Hope this could be help of you.

    Best Regards,
    Sera Yu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

    Friday, August 26, 2016 2:53 AM
  • As an afterthought -- did the app include a manifest for the v6 common controls dll?
    • Marked as answer by TallGuy63 Friday, August 26, 2016 2:37 PM
    Friday, August 26, 2016 2:59 AM
  • I've made the recommended changes and it's still not working... took out the control id (HMENU)800 and replaced with NULL; I'm already including the initcommoncontrols for tooltips:

         icc.dwSize=sizeof(INITCOMMONCONTROLSEX);
         icc.dwICC=ICC_BAR_CLASSES & ICC_LISTVIEW_CLASSES & ICC_TAB_CLASSES & ICC_PROGRESS_CLASS;
         InitCommonControlsEx(&icc);

            //create tooltip
             xstyle=WS_EX_TOPMOST;
             style=WS_POPUP | TTS_ALWAYSTIP;  // | TTS_BALLOON;

    htooltip=CreateWindowEx(xstyle,TOOLTIPS_CLASS,NULL,style,0,0,0,0,hwnd,NULL,hinstance,NULL);

    VOID settexttooltip(HWND hwnd,HWND htooltip,HWND hctl,std::string stxt)
    {
         std::wstring wtxt=strtowstr(stxt);
         TOOLINFO ti={0};

         ti.cbSize=sizeof(TOOLINFO);
         ti.uFlags=TTF_SUBCLASS | TTF_IDISHWND;
         ti.hwnd=hwnd;
         ti.uId=(UINT_PTR)hctl;
         ti.lpszText=(LPWSTR)wtxt.c_str();

         SendMessage(htooltip,TTM_ADDTOOL,0,(LPARAM)&ti);
         SendMessage(htooltip,TTM_ACTIVATE,TRUE,0);

         return;
    }


    • Edited by TallGuy63 Friday, August 26, 2016 3:47 AM
    Friday, August 26, 2016 3:46 AM
  • Calling InitCommonControls isn't enough.  You need to include a manifest for the v6 common controls dll.  An easy way is to put the following into your code -

    #if defined _M_IX86
      #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_IA64
      #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_X64
      #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #else
      #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #endif

    BTW, your code should be -

    icc.dwICC=ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES | ICC_TAB_CLASSES | ICC_PROGRESS_CLASS;

    or you coud use

    icc.dwICC=ICC_WIN95_CLASSES;



    • Edited by RLWA32 Friday, August 26, 2016 10:57 AM
    • Marked as answer by TallGuy63 Friday, August 26, 2016 2:37 PM
    Friday, August 26, 2016 9:10 AM
  • I added and changed the following to my code and it still doesn't work (But thanks for catching the "&" that for some insane reason was there instead of the "|"):

         icc.dwICC=ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES | ICC_TAB_CLASSES | ICC_PROGRESS_CLASS;

    #if defined _M_IX86
      #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")

    #elif defined _M_IA64

      #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_X64
      #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #else
      #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #endif

    • Marked as answer by TallGuy63 Friday, August 26, 2016 2:37 PM
    • Unmarked as answer by TallGuy63 Friday, August 26, 2016 2:38 PM
    Friday, August 26, 2016 2:09 PM
  • Oops... my bad... LOL

    That fixed it !

    Thank you so much for the input everyone who commented...

    • Edited by TallGuy63 Friday, August 26, 2016 2:22 PM
    Friday, August 26, 2016 2:12 PM
  • There must be something else wrong in the code that we haven't seen.

    I've uploaded a skeleton Win32 project to onedrive that creates a window with an edit control and a tooltip for it.  It works in x86 and x64.  You can download it from Win32Tooltip.zip

    Friday, August 26, 2016 2:34 PM
  • Oops... my bad... LOL

    That fixed it !

    Thank you so much for the input everyone who commented..

    I'd appreciate it if you would mark my response as the answer to the question. .,. Thanks!


    • Edited by RLWA32 Friday, August 26, 2016 2:39 PM
    Friday, August 26, 2016 2:38 PM
  • Hi everyone

    What #include file is added in this program? I get TOOLTIPS_CLASS,.. undefined. I am using VS2012.

    Regards

    Chong

    Sunday, August 28, 2016 5:06 PM
  • What #include file is added in this program? I get TOOLTIPS_CLASS,.. undefined. I am using VS2012.

    The header file for the common controls is commctrl.h.

    For the v6 common controls you will need to include the manifest and properly call InitCommonControlsEx as described above to register the common control classes.  You can see the sample mentioned above at Win32Tooltip.zip


    • Edited by RLWA32 Sunday, August 28, 2016 5:42 PM added new link
    Sunday, August 28, 2016 5:39 PM