问题
I want to create a simple tooltip that will pop when user hovers over a button.
To do that I have studied this example from MSDN.
Everything works fine when I first time hover over the button, but after that tooltip never shows up again ( I have checked return values for HWND of the tooltip and for SendMessage( ..., TTM_ADDTOOL, ... ) and there were no errors ). 
I have tried to find the solution online, but have failed. The only resource I have found that might be useful is this tutorial but it suggests to subclass the control in order to relay mouse messages to the tooltip control-I will not accept this type of solution because I believe what I ask for is the basic functionality tooltip control provides.
EDITED ON JANUARY 21st 2014:
Following instructions from the link member Stuart suggested* I was able to partially solve the problem. Now tooltip is shown after clicking on the main window's client area and then hovering back over the button.
However, after I click on the button tooltip never shows up again .
Browsing through Internet, I have found this example and after adding these directives:
#pragma comment( linker, "/manifestdependency:\"type='win32' \
    name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
    processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \
    language='*'\"")
#pragma comment( lib, "comctl32.lib")
the problem seemed to disappear. Now I was able to click on a button, hover over edit control and edit control's tooltip would appear.
However, after clicking on a button, then clicking on the client area of the main window, and then hovering over the button again its tooltip did not show!
Then I have continued to search over the Internet and have found this article on CodeProject and it does exactly what I need.
So I have started to analyze the source code of the first example and this article. I was unable to see the difference. However, appearances were different! It seems that the article did not use Visual Styles, and taking into the consideration MSDN article member Stuart mentioned, I have started to suspect that this might be the manifest issue.
So I have tried to compile all the programs without the first pragma comment submitted above, but in my test application ( the one created as default Win32 project ) InitCommonControlsEx failed, in the example program I have got error Failed to save the updated manifest to the file ".\Debug\foosyerdoos tooltip.exe.embed.manifest". The parameter is incorrect., and the article application failed to create tooltip controls.
After creating the fresh blank project, and after copying the code from the first example-only this time without pragma comment-SendMessage failed to add both tooltips.
So, without first pragma comment submitted above, I can not use tooltip controls or so it seems.
END OF EDIT
Here are the instruction for creating the minimal example that illustrates the problem:
- Create 
default Win32 projectinMS Visual Studio; Add the bellow
WM_CREATEhandler:case WM_CREATE: { HWND hButton = CreateWindowEx( 0, L"Button", L"test me!", WS_CHILD | WS_VISIBLE | WS_BORDER | BS_PUSHBUTTON, 50, 150, 150, 25, hWnd, (HMENU)8003, hInst, 0 ); HWND hwndTip = CreateWindowEx( NULL, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWnd, NULL, hInst, NULL ); // Associate the tooltip with the tool. TOOLINFO toolInfo = { 0 }; toolInfo.cbSize = sizeof(toolInfo); toolInfo.hwnd = hWnd; toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS; toolInfo.uId = (UINT_PTR)hButton; toolInfo.lpszText = L"test 1"; SendMessage( hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo ); } return 0L;Compile and run-
tooltipshould show on first hover, but never again.
I work on Windows XP, using MS Visual Studio Express 2008. 
Visual Styles are enabled, I have linked comctl32.lib and have initiated INITCOMMONCONTROLSEX structure's dwICC member with ICC_STANDARD_CLASSES | ICC_TAB_CLASSES | ICC_BAR_CLASSES.
EDIT ( January 31st, 2014 ) :
After testing this very same code snippet on my laptop, which has Windows 7 I can confirm that everything works fine. This is the problem with my Windows XP I guess...
END OF EDIT:
My question is really simple:
How to adjust my code so the tooltip is shown every time user hovers over the button?
Thank you.
Best regards.
回答1:
You are chasing the wrong problem, this behavior is by design for tooltips. The exact rules it uses are not documented anywhere I know of and I never personally found any need to reverse-engineer it so I can only tell you what I've seen.
The bigger idea behind the feature is that it avoids wearing out the user with info that he already knows. Tooltips were very much designed to be tips, just a sliver of information that isn't crucial to proper operation of the program. It appears to be implemented by keeping track of a tip for a tool already having been displayed and not display it again if the tool was used. Which of course makes a lot of sense, the user doesn't need to be reminded what a tool does after he used it.
There is no message to reset that "the tip was displayed" state. It will reset when it displays the tip for another tool. Altering the tip resets it as well.
I'd reiterate that this is something you should not try to fix. The behavior is perfectly sensible. If it is important anyway then you'll have to take control and display the tip yourself, TTM_ACTIVATE message.
回答2:
Your code works on my laptop with Windows 7 as you are expecting.
Since this is Microsoft's example, I highly doubt that there is a mistake in it.
To follow the advice of Sherlock Holmes: "Once you eliminate the impossible, all what is left, no matter how improbable, is truth." Since code works, then it must be problem with Windows XP, which can be confirmed with the above follow up comments to your question.
I would check if I have downloaded all automatic updates or would reinstall and try your code again. You could also test your code on other machine running Windows XP to see if your own is the problem.
Good luck.
来源:https://stackoverflow.com/questions/21238449/tooltip-is-never-shown-again-after-i-click-on-the-button