CTabCtrl 添加 tooltip方法

if(pMsg->message == WM_MOUSEMOVE && pMsg->hwnd == m_cTabCtrl.m_hWnd)
{
 CPoint point(LOWORD(pMsg->lParam),HIWORD(pMsg->lParam));
TCHITTESTINFO TestInfo;
 TestInfo.pt = point;
int iTabNum = m_cTabCtrl.HitTest(&TestInfo);
 if (iTabNum != -1 )
 {
TCITEM item;
char ItemText[255];
 item.mask = TCIF_TEXT;
 item.pszText = ItemText;
item.cchTextMax = 255;
 m_cTabCtrl.GetItem( iTabNum, &item );
TRACE( "OnTab: %s/n", ItemText );
}
 }



void CToolTipTestDlg::OnMouseMove(UINT nFlags, CPoint point)
{
char * TabName[] = { "About", "Info" };
for ( int i = 0; i < 2; i++ ) {
 CRect rect; m_cTabCtrl.GetItemRect( i, &rect );
if ( rect.PtInRect( point ) )
TRACE( "On %s/n", TabName[i] );
}
 CDialog::OnMouseMove(nFlags, point);
}




//Dlg.h
CDlg : public CDialog {
 public:
CToolTipCtrl *m_ptip;
 }
//Dlg.cpp
CDlg::~Dlg() { delete m_ptip; m_ptip = NULL; }
BOOL CDlg::OnInitDialog()
{ m_ptip = new CToolTipCtrl;
 if(!m_ptip->Create(this))
{
 TRACE("Unable To create ToolTip/n");
 return TRUE;
}
 m_ptip->AddTool( GetDlgItem(IDC_BUTTON1), "提示条");
 m_ptip->Activate(TRUE); return TRUE;
}
 BOOL CDlg::PreTranslateMessage(MSG* pMsg)
{
 if (m_ptip != NULL) m_ptip->RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}





CTabCtrl------ToolTip

BOOL CControl15Dlg::OnInitDialog()
{
m_tooltip = NULL;
}

BOOL CControl15Dlg::PreTranslateMessage(MSG* pMsg)
{

if (NULL != m_tooltip)
m_tooltip->RelayEvent(pMsg);

return CDialog::PreTranslateMessage(pMsg);
}

void CControl15Dlg::OnSetTooltips()
{
// do not create twice
if(m_tooltip != NULL)
return;

m_tooltip = new CToolTipCtrl;
if (!m_tooltip->Create(this))
{
TRACE("Unable To create ToolTip/n");
return;
}

m_tab.SetToolTips(m_tooltip);

int count = m_tab.GetItemCount();
int id = IDS_TOOLTIP1;
for (int i = 0; i < count; i++)
{
id++;
CRect r;
m_tab.GetItemRect(i, &r);
VERIFY(m_tooltip->AddTool(&m_tab, id, &r, id));
}

// Activate the tooltip control.
m_tooltip->Activate(TRUE);

}

void CControl15Dlg::OnGetToolTips()
{
CToolTipCtrl* pTooltip = m_tab.GetToolTips();
char prompt[200];
sprintf(prompt, "the pointer to the tooltip is:%d", pTooltip);

AfxMessageBox(prompt);
}


<img src="http://visit.geocities.yahoo.com/visit.gif?us1203435194" alt="setstats" border="0" width="1" height="1"> 1

你可能感兴趣的:(null,delete,button,border)