Click to See Complete Forum and Search --> : how to add tooltip for disable button


elliot115
July 17th, 2006, 03:15 AM
I wrapped one class as below:
class CMYButton: public CWindowImpl<CMyButton,CButton>
{


CToolTipCtrl m_hToolTip ;
}

I used WTL71.
I want to add tooltip for disable button in my class.

anyone can help will be appriciated.

Thanks in advance.

The below is my code.Now I found that tooltip will show in not the button's rect.

BOOL CMYButton::SetToolTip(LPCTSTR lpszTipText)
{
if ( m_hToolTip.m_hWnd && m_hToolTip.IsWindow() )
{
int nCount = m_hToolTip.GetToolCount() ;
for ( int i=nCount-1;i>=0;i--)
m_hToolTip.Pop() ;
}

if(lpszTipText)
{
LPTSTR lpsz = new TCHAR[lstrlen(lpszTipText) + 1];
if(!lpsz)
return FALSE;

lstrcpyn(lpsz, lpszTipText,lstrlen(lpszTipText) + 1); // overrun 08/18/2005
if(m_lpszTipText)
delete []m_lpszTipText;

m_lpszTipText = lpsz;

if (m_hWnd && ::IsWindow(m_hWnd) && ( GetStyle() & WS_VISIBLE ) )
{
//$ the new
TOOLINFO ti;
ZeroMemory(&ti, sizeof(ti));
ti.cbSize = sizeof(ti);
ti.uFlags = 0;
ti.hwnd = m_hWnd;
ti.uId = 0 ;
ti.lpszText = m_lpszTipText;
RECT rcCli ;
GetClientRect(&rcCli) ;
ti.rect = rcCli ;
if ( ! ::IsWindowEnabled(m_hWnd) )
{
ZeroMemory(&ti, sizeof(ti));
ti.cbSize = sizeof(ti);
ti.hwnd = GetParent();
ti.uFlags = TTF_SUBCLASS ;
ti.uId = (UINT)m_hWnd ;
ti.lpszText = m_lpszTipText;

RECT rc;
GetWindowRect(&rc) ;

POINT pt ;
pt.x = rc.left ;
pt.y = rc.top ;
::ScreenToClient(GetParent(),&pt) ;

ti.rect.left = pt.x ;
ti.rect.top = pt.y ;
ti.rect.right = pt.x + rc.right - rc.left ;
ti.rect.bottom = pt.y + m_nDlgBtnHeight ;
}
if ( m_hToolTip.m_hWnd && m_hToolTip.IsWindow() )
{
::SendMessage(m_hToolTip.m_hWnd, TTM_DELTOOL, 0, (LPARAM)&ti);
::SendMessage(m_hToolTip.m_hWnd, TTM_ADDTOOL, 0, (LPARAM)&ti);
}
}
}
else
{
if(m_lpszTipText)
delete []m_lpszTipText;

m_lpszTipText = NULL;
}
return TRUE;
}

elliot115
July 17th, 2006, 03:36 AM
and I create button in on window or subclass window in dialog.


what messages need I to handle with ?

WM_MOUSEMOVE,
WM_ENABLE
WM_SHOWWINDOW

or ??

who can post a demo ?
must wrap a toottip to a button class so the up level can use as this
CMYbutton aButton;
aButton.SetToolTip("This is a button") ;

if button is disable,that will also need to show the tooltip.
Thanks in advance.