Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a tooltip to CMenu item(s)

A while ago, I have tried to add a tooltip for testing purposes on a CMenu item. Now I would need it, and I'm facing the same issue again.

This question and answer(s): MFC : How to add tooltip in Cmenu items?
doesn't help me at all, as this "newline magic" is simply not working.

Also, it seems like I'm not the only one having problems with it: MFC CMenu tooltip not being displayed

void CTextListCtrl::CreateMenu(void)
{
    m_Menu.CreateMenu();
    CMenu submenu;
    submenu.CreatePopupMenu();
    submenu.AppendMenuW(MF_STRING, IDC_RESEND_POPUP, L"&Resend\nShow me the tooltip");
    //Other menu items...
    m_Menu.AppendMenuW(MF_POPUP, reinterpret_cast<UINT_PTR>(submenu.m_hMenu), L"");
    submenu.Detach();
}

The result is this:

enter image description here

However, increasing the letters of the text results in a bigger pop-up menu, not a menu tooltip.

I have seen the other links in this answer, and checked them and the projects. But these are not what I want.

Does someone know what I did wrong, or is there another solution/source which could be helpful ?


Edit: As I have mentioned before in a comment, here is a sample solution with minimum requirements to reproduce the problem. (See CMenuListCtrl.cpp(100))
Tested with VS2010 & VS2015 (same result).

like image 407
Blacktempel Avatar asked Jul 22 '15 09:07

Blacktempel


People also ask

What is a tooltip menu?

The tooltip, also known as infotip or hint, is a common graphical user interface (GUI) element in which, when hovering over a screen element or component, a text box displays information about that element, such as a description of a button's function, what an abbreviation stands for, or the exact absolute time stamp ...

Where do you put tooltips?

The tooltip text is placed inside an inline element (like <span>) with class="tooltiptext" . CSS: The tooltip class use position:relative , which is needed to position the tooltip text ( position:absolute ).

How do you display a tooltip?

Set a ToolTip in the designerIn Visual Studio, add a ToolTip component to the form. Select the control that will display the ToolTip, or add it to the form. In the Properties window, set the ToolTip on ToolTip1 value to an appropriate string of text.

How do I add a tooltip to a button?

To add a tooltip to a button you can use the title attribute on the button element. This will create a tooltip when the user hovers over the button element. And it's really as simple as that, be sure to leverage the use of tooltips to provides better context for your users.


1 Answers

Here's trick that will fix your problem, "newline magic" will work for sure.

Ensure that you are using version 6 of ComCtl32.dll.

Add below block in stdafx.h file and rebuild your project.

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

enter image description here

like image 161
user1 Avatar answered Oct 10 '22 19:10

user1