Click here to Skip to main content
15,888,106 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All :)

I'm writing my own ToolTipMesssageBox which has functionality close to that of message box but displays a tool tip instead.

I'm almost ready with this task and everything works fine except of a smal detail, the balloon always appears below the co-ordinates I give in the function (the co-ordinates of the point that's supposed to be pointed by the balloon's stem). The stem correctly points at the co-ordinates I give, but it sticks out of the upper edge of the balloon and thus the balloon is below the given point.

I examined MSDN and found no obvious way of controling this aspect of the balloon tooltip's appearance. Then I searched for articles in Code Project and found many, some of which show pictures of balloon tooltips that look exactly as I want: Balloon Tips Galore![^] (The first picture). But when I looked in the code I couldn't find anything that forces the balloon to appear this way, it looks like it's automatic.

I'd like to see the balloon normaly appearing above the provided point and appear below it only if there is not enough room for it above i.e. the point is too close to the upper edge of the desktop. Now it has exactly the oposite behaviour. (and covers some of my program's controls, which souldn't be a big problem since the balloon can easily dismissed, but still it would have been much better if ti appears above...)

I'm begining to fear that this is the way it is, and nothing can be done (except for writig a new balloon tool tip control from scratch, which I'm not willing to do), so any help is appreciated! :)

Thanks in advance.

Here the requested code sample :)
This is the code that creates the tool tip, it's in the OnCreate function of the transparent window that acts as parent of the tool tip control.

C++
TOOLINFO ToolInfo;
LPARAM   lParam;
CRect    CtrlRect;
DWORD    dwStyle = WS_POPUP | TTS_ALWAYSTIP | TTS_NOPREFIX | TTS_CLOSE |(AreBalloonsEnabled() ? TTS_BALLOON : 0);

m_wndToolTip.CreateEx(this, dwStyle, WS_EX_TOPMOST);
m_pwndCtrl->GetWindowRect(&CtrlRect);
m_pwndCtrl->GetParent()->ScreenToClient(&CtrlRect);

memset(&ToolInfo, 0, sizeof(ToolInfo));

ToolInfo.cbSize   = sizeof(ToolInfo);
ToolInfo.uFlags   = TTF_TRACK;
ToolInfo.hwnd     = m_hWnd;
ToolInfo.uId      = 1;
ToolInfo.rect     = CtrlRect;
ToolInfo.lpszText = m_strText.GetString();

m_pwndCtrl->GetWindowRect(&CtrlRect);

    // this piece determines the the co-crdinates which will be pointed bythe
    // stem. That is in the middle of the control that's pointed as tool
lParam            = LPARAM(CtrlRect.left + CtrlRect.Width() / 2);
lParam           &= 0x0000ffff;
lParam           |= LPARAM(CtrlRect.top + CtrlRect.Height() / 2 << 16);

m_wndToolTip.SendMessage(TTM_ADDTOOL, NULL, (LPARAM)&ToolInfo);
m_wndToolTip.SetTipBkColor(RGB(255, 255, 128));
m_wndToolTip.SetTitle(m_ttmbIcon, m_strTitle.GetString());
m_wndToolTip.SendMessage(TTM_TRACKACTIVATE, TRUE, (LPARAM)&ToolInfo);
m_wndToolTip.SendMessage(TTM_TRACKPOSITION, 0,    (LPARAM)lParam);
Posted
Updated 5-Oct-12 4:05am
v6
Comments
bbirajdar 5-Oct-12 8:08am    
I teleported myself to your place and checked the code in your machine. I found that there is problem in your code and needs to be fixed. However, you will need to wait till few more readers teleport themselves and check your code and provide a solution...
Ivan Ivanov 83 5-Oct-12 8:53am    
Sory maybe I wasn't clear enough. The article "Balloon Tips Galore" isn't my own. I just included it for the picture ;) so people can see what I mean.
Jochen Arndt 5-Oct-12 8:16am    
Did you read this MSDN article http://msdn.microsoft.com/en-us/library/hh298401%28v=vs.85%29.aspx?
Ivan Ivanov 83 5-Oct-12 9:15am    
I haven't read this exact article but I've already tried those flags and I just tried them again but they don't do the trick. For example the TTF_CENTERTIP centers the stem horizontaly but the balloon is still below the point. Maybe I should provide more information on what exactly is the case. Strangely it says that the appearance I want is the default, so apparently I'm not doing something right.


For example if the balloon apears above the point I give, it will slightly exceed the upper edge of the program but since the program window is close to the center of the desktop that shouldn't be a problem, sould it?

Thanks anyway :)I'll read this article again carefully.
Jochen Arndt 5-Oct-12 9:40am    
According to the article and the images, you must omit the center flag to show the tip above the control. Or you can use the track flag and set the position explicitely.

Showing a short piece of code is always helpful as already suggested by aspnet_regiis. You may use the green 'Improve question' link to add more information to your question.

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