In my application, I have a slider control placed on a form view. What I
want is that when a user moved the pointer of the slider control, i want to
display the value of the current slider position in a tooltip over the
slider control. I have written following code for this but it is not
working. Please tell me what should i do?
void CMyFormView::OnInitialUpdate()
{
.........
m_slidertip.Create(&m_slider); // m_slider is class variable of type
CSliderCtrl
strcpy(m_slidertip_text, "Slider"); // char m_slidertip_text[500]
m_slidertip.AddTool(&m_slider, m_slidertip_text, &rc, IDC_SLIDER1);
m_slidertip.Activate(true);
........
}
BOOL CMyFormView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
m_slidertip.RelayEvent(pMsg);
return CFormView::PreTranslateMessage(pMsg);
}
void CMyFormView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
if((CSliderCtrl *)pScrollBar == &m_slider)
{
CString str;
str.Format("%d", m_slider.GetPos());
strcpy(m_slidertip_text, str);
m_slidertip.UpdateTipText(m_slidertip_text, &m_slider, IDC_SLIDER1);
m_slidertip.Update();
}
CFormView::OnHScroll(nSBCode, nPos, pScrollBar);
}
However, I am not getting any tooltip above my slider control. Please tell
me what should i do?
Thanks,
Arsalan
TBS_TOOLTIPS...
--
Jeff Partch [VC++ MVP]
"Jeff Partch [MVP]" <je...@mvps.org> schrieb im Newsbeitrag
news:%23vr2yVX...@TK2MSFTNGP09.phx.gbl...
I'd try handling the TTN_NEEDTEXT[A/W] notifications in a CSliderCtrl
subclass.
Simply providing handlers for TTN_NEEDTEXT in slider class will not
guarantee that slider will receive those messages.
Default implementation of OnToolHitTest (CWnd) designates parent window for
TTN_NEEDTEXT messages.
Arsalan,
You are confusing tool tips into thinking that you are adding rectangle as a
tool, and that is not a case.
Using m_slidertip_text as buffer is not necessary.
Here are code changes for you:
void CMyFormView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
m_slidertip.Create(&m_slider);
CRect rect;
m_slider.GetWindowRect(rect);
CString csPos;
csPos.Format("Slider Pos: %d", m_slider.GetPos());
m_slidertip.AddTool(&m_slider, csPos);
m_slidertip.Activate(true);
}
void CMyFormView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if((CSliderCtrl *)pScrollBar == &m_slider)
{
CString str;
str.Format("Slider Pos: %d", m_slider.GetPos());
m_slidertip.UpdateTipText(str, &m_slider);
}
CFormView::OnHScroll(nSBCode, nPos, pScrollBar);
}
Umm. If a TBS_TOOLTIPS style trackbar creates its TT using
LPSTR_TEXTCALLBACK, and provides the text by responding to this
notification, why wouldn't intercepting it in a subclass be a proper course
of action?
> Umm. If a TBS_TOOLTIPS style trackbar creates its TT using
> LPSTR_TEXTCALLBACK, and provides the text by responding to this
> notification, why wouldn't intercepting it in a subclass be a proper course
> of action?
I did not state in my post that this would not "be a proper action"; I just
pointed that:
"Simply providing handlers for TTN_NEEDTEXT in slider class *will not
guarantee* that slider will receive those messages."
Maybe I should have been clearer in my previous post:
Following would have to be taken under consideration:
1. Slider would have to be created with TBS_TOOLTIPS style in order to use
build in tooltips.
2. This style is not present in VS 6.0 modifying style will not create build
in tool tips, therefore slider would have to be created at the runtime.
3. Default implementation shows slider position only when slider is clicked
on and/or moving. Providing all of the above is true, handling TTN_NEEDTEXT
notifications would change tool tip text only when mouse is dragging slider.
Default implementation does not meet Arsalan 's requirements since does not
handle tooltips when mouse stops over slider.
In order to achieve this:
1. Arsalan's implementation can be used (with correction).
2. Default CWnd tool tip control could be used in dialog, where
EnableTooltips has to be called and TTN_NEEDTEXT notification has to be
handled.
3. Default tool tip could be used in a slider (subclassed using CSliderCtrl
derived class), where EnableTooltips has to be called, TTN_NEEDTEXT
notification has to be handled and OnToolHitTest has to be overridden.
Okay.
>
> Maybe I should have been clearer in my previous post:
>
Or I.
> Following would have to be taken under consideration:
>
> 1. Slider would have to be created with TBS_TOOLTIPS style in order to use
> build in tooltips.
Yes that was my original suggestion and the context of the follow-up
suggestion to intercept the notification.
> 2. This style is not present in VS 6.0 modifying style will not create
build
> in tool tips, therefore slider would have to be created at the runtime.
Or one can edit the *.rc file to add it. Nonetheless, this is a side issue.
TBS_TOOLTIPS has been established as the context in which this follow-up
suggestion was made.
> 3. Default implementation shows slider position only when slider is
clicked
> on and/or moving. Providing all of the above is true, handling
TTN_NEEDTEXT
> notifications would change tool tip text only when mouse is dragging
slider.
>
> Default implementation does not meet Arsalan 's requirements since does
not
> handle tooltips when mouse stops over slider.
No, Arsalon said, "What I want is that when a user moved the pointer of the
slider control, i want to
display the value of the current slider position in a tooltip over the
slider control".
That is why I originally suggested TBS_TOOLTIPS: it does this exact thing by
default. He then followed up that suggestion by saying, "Thanks but suppose
that based on this current position, i look a table and get a string from
that table and now i want to show that string then how should i proceed??"
Which is why suggested the TTN_NEEDTEXT interception as a follow-up. To
which you replied, "Simply providing handlers for TTN_NEEDTEXT in slider
class *will not guarantee* that slider will receive those messages".
Given the context and progression of the thread at the point you replied to
it, why wouldn't it be guaranteed?
> No, Arsalon said, "What I want is that when a user moved the pointer of the
> slider control, i want to
> display the value of the current slider position in a tooltip over the
> slider control".
>
I have might have misinterpreted this.
I have treated "user *moved* the pointer of the slider control" (notice past
tense) as one event and "display the value of the current slider position in
a tooltip over the slider control." as another independent event.
Other words:
Any time cursor is over tracker control, tool tip shows current position of
the slider.
I think the only person who can clarify this is Arsalon.