|
|
|
|
Forum
Please
Log In
to post a new message or reply to an existing one. If you are not registered, please
register.
NOTE: Some forums may be read-only if you are not currently subscribed to
our technical support services.
Subject |
Author |
Date |
|
Kirby Zhang
|
Jun 7, 2005 - 3:16 AM
|
For example I’d like to show the nice looking menu tooltips for my toolbar buttons. Is this possible?
|
|
Technical Support
|
Jun 8, 2005 - 11:26 AM
|
You don’t have to wait until the next Prof-UIS release. We have coded the CExtCTA template class which can be applied to any CExtControlBar -derived class to make it display a balloon tip instead of the classic tooltip. The CExtCTA < CExtControlBar > resizable control bar displays balloon tips for its caption buttons. The CExtCTA < CExtToolControlBar > class displays balloon tips for all its buttons including the chevron button. In fact, this template class can be applied to any MFC CWnd -derived class which uses MFC’s shared tooltip feature based on the CWnd::OnToolHitTest() virtual method. Here is source code for the new class://///////////////////////////////////////////////////////////////////////////
// CExtCTA template (cool tip able)
#define __EXT_MFC_TIMER_ID_COOL_TIP_TEMPLATE 7654
template < class _CTA_BASE >
class CExtCTA : public _CTA_BASE
{
protected:
mutable CExtPopupMenuTipWnd m_wndCoolTip;
mutable int m_nLastToolHitID;
mutable CRect m_rcLastToolHit;
void _CancelTip() const
{
if( GetSafeHwnd() != NULL )
((CWnd*)this)->KillTimer( __EXT_MFC_TIMER_ID_COOL_TIP_TEMPLATE );
m_nLastToolHitID = -1;
m_rcLastToolHit.SetRectEmpty();
if( m_wndCoolTip.GetSafeHwnd() != NULL )
m_wndCoolTip.Hide();
CWnd::CancelToolTips();
}
protected:
virtual int OnToolHitTest(
CPoint point,
TOOLINFO * pTI
) const
{
ASSERT_VALID( this );
int nToolTipHit =
_CTA_BASE::OnToolHitTest( point, pTI );
bool bHide = true;
if( nToolTipHit >= 0 )
{
if( m_nLastToolHitID != nToolTipHit )
{
if( pTI->lpszText != NULL )
{
if( pTI->lpszText != LPSTR_TEXTCALLBACK )
{
bHide = false;
m_nLastToolHitID = nToolTipHit;
m_rcLastToolHit = pTI->rect;
ClientToScreen( &m_rcLastToolHit );
m_wndCoolTip.SetText(
LPCTSTR(LPVOID(pTI->lpszText))
);
((CWnd*)this)->SetTimer(
__EXT_MFC_TIMER_ID_COOL_TIP_TEMPLATE,
50,
NULL
);
m_wndCoolTip.Show(
(CWnd*)this,
m_rcLastToolHit
);
::free( pTI->lpszText );
} // if( pTI->lpszText != LPSTR_TEXTCALLBACK )
pTI->lpszText = NULL;
} // if( pTI->lpszText != NULL )
} // if( nToolTipHit >= 0 )
else
bHide = false;
nToolTipHit = -1;
}
if( bHide )
_CancelTip();
return nToolTipHit;
}
LRESULT WindowProc(
UINT message,
WPARAM wParam,
LPARAM lParam
)
{
if( message == WM_DESTROY || message == WM_NCDESTROY )
_CancelTip();
else if(
message == WM_TIMER
&& wParam == __EXT_MFC_TIMER_ID_COOL_TIP_TEMPLATE
)
{
if( m_nLastToolHitID < 0
|| m_rcLastToolHit.IsRectEmpty()
)
{
_CancelTip();
return 0;
}
POINT ptCursor;
if( ! ::GetCursorPos( &ptCursor ) )
{
_CancelTip();
return 0;
}
if( ! m_rcLastToolHit.PtInRect(ptCursor) )
{
_CancelTip();
return 0;
}
return 0;
}
LRESULT lResult =
_CTA_BASE::WindowProc( message, wParam, lParam );
return lResult;
}
virtual void PreSubclassWindow()
{
_CancelTip();
_CTA_BASE::PreSubclassWindow();
}
}; // class CExtCTA
|
|
Kirby Zhang
|
Jun 9, 2005 - 3:50 PM
|
Excellent! I will be giving this a try shortly.
|
|
Technical Support
|
Jun 7, 2005 - 7:35 AM
|
Thank you for the interesting question. The balloon tip was initially designed only for Prof-UIS pop-up menus but it is possible to use it outside menus. The Prof-UIS toolbar uses the only one shared tooltip window provided by the MFC framework for each thread by calling the CWnd::OnToolHitTest() virtual method. It is possible to create a CExtToolControlBar -derived class which would return an undefined tool hit testing value, handle mouse movement events and display balloon tips for its buttons. Prof-UIS 2.40 (coming soon) allows you to catch mouse hovering events both for toolbar buttons and menu items universally. This feature enables you to implement any kind of custom tooltip window. The new HelpNotes sample application demonstrates how to display pop-up rich edit view windows with a shadow for both toolbar buttons and menu items. We will regard you question as a feature request.
|
|
Kirby Zhang
|
Jun 7, 2005 - 4:21 PM
|
More generally, I’d like to be able to show cooltips for any kind of control. For example, I’d like a balloon tip that explains the meaning of some label text. Will this be possible in the next version?
|
|
Kirby Zhang
|
Jun 7, 2005 - 4:16 PM
|
Thank you for your detailed answer. I think it would be a great feature giving more consistent look and feel. I look forward to the next version!
|
|