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;
}
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;
}