Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I've used this article (http://msdn.microsoft.com/en-us/library/windows/desktop/hh298369%28v=vs.85%29.aspx[^]) to add a tooltip for two regions.

Firstly, I graphically draw two regions:
C++
//first rectangle
HBRUSH brush1 = CreateSolidBrush(RGB(225, 0, 0));
RECT a = {20, 20, 70, 50};
FillRect(GetDC(hwnd), &a, brush1);

//second rectangle
HBRUSH brush2 = CreateSolidBrush(RGB(0, 0, 255));
RECT b = {70, 20, 120, 50};
FillRect(GetDC(hwnd), &b, brush2);

And now I'm trying to add two tips for these two regions:
C++
INITCOMMONCONTROLSEX icc;
InitCommonControlsEx(&icc);
icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
icc.dwICC = ICC_BAR_CLASSES;

HWND tooltip_hwnd = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, "TooltipIM", WS_POPUP |  TS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, NULL, (HINSTANCE)GetModuleHandle(NULL), NULL);
     
SetWindowPos(tooltip_hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
SendMessage(tooltip_hwnd, TTM_SETMAXTIPWIDTH, 0, 200);
SendMessage(tooltip_hwnd, TTM_SETDELAYTIME, TTDT_AUTOPOP, 15000);

TOOLINFO ti = {0};
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = hwnd;
ti.hinst = (HINSTANCE)GetModuleHandle(NULL);
ti.uId = 1;
ti.lpszText = "first";
RECT frst = {20, 20, 70, 50};
ti.rect.left = frst.left;
ti.rect.top = frst.top;
ti.rect.right = frst.right;
ti.rect.bottom = frst.bottom;
//add tip for first region
SendMessage(tooltip_hwnd, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);

ti.uId = 2;
ti.lpszText = "second";
RECT scnd = {70, 20, 120, 50};
ti.rect.left = scnd.left;
ti.rect.top = scnd.top;
ti.rect.right = scnd.right;
ti.rect.bottom = scnd.bottom;
//add tip for second region
SendMessage(tooltip_hwnd, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);

And it works fine! But I don't understand why the following happens: when the mouse cursor moves from the first region to the second one, the tooltip window is blinking when changing tips.
https://www.youtube.com/watch?v=cblAF7hUPOA[^]
Why does this happening?
I made an experiment in c++ builder. I put on the form two buttons and placed them next to each other. And the result was next: when the mouse cursor moves from the first button to the second one, the tooltip window does not blink:
https://www.youtube.com/watch?v=ITdYX6bXMUg[^]
How to achieve the same effect in my code?
Posted
Updated 3-Sep-14 7:31am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900