tags:

views:

34

answers:

4

hi,

How to set tooltip at runtime in MFC Treeview ?

I am creating treeview like this :

                        m_pTreeview->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP |                     
            TVS_SINGLEEXPAND,CRect(38, 82, 220 ,250), this, IDC_NDS_TREEVIEW);

Any help is appreciated..

A: 

If you're referring to the tooltips for items in the tree control, you need to add TVS_INFOTIP to the window styles in Create (see list of tree-view styles). You'll also have to handle the TVN_GETINFOTIP notification message to provide the tooltip text depending on the item.

casablanca
@casablanca : can u provide me some sample on this ?
Swapnil Gupta
I have just added TVS_INFOTIP in treeview while creating but it is not showing any tooltip. how to do the next step ?
Swapnil Gupta
A: 

Add TVS_INFOTIP style to your tree-view. You also need to handle the TVN_GETINFOTIP notification using an ON_NOTIFY handler as described here. In your handler member function cast the NMHDR * parameter to NMTVGETINFOTOOLTIP * and set the tooltip string in this structure.

Praetorian
can u provide me some sample on this ?
Swapnil Gupta
There's sample code in the links I've posted.
Praetorian
A: 

Use TVS_INFOTIP style to tree-view, and handle the TVN_GETINFOTIP notification using an ON_NOTIFY handler. Typecast the NMHDR ptr to NMTVGETINFOTOOLTIP ptr as (NMTVGETINFOTOOLTIP *)pnmhdr and then set the tooltip string in this structure.

Pankaj Sonawane
A: 

Here some code : -- In .H file

afx_msg void OnMyTreeGetInfoTip NMHDR pNMHDR LRESULT pResult

In BEGIN MESSAGE MAP block add - ON_NOTIFY_REFLECT (TVN_GETINFOTIP, OnMyTreeGetInfoTip)

And use handler

void CMyTreeView::OnMyTreeGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult)

{ LPNMTVGETINFOTIP pGetInfoTip = (LPNMTVGETINFOTIP)pNMHDR

CString strItemTxt = m_TreeCtrl.GetItemText(pGetInfoTip->hItem);

strcpy(pGetInfoTip->pszText, strItemTxt);

*pResult = 0;

}

Pankaj Sonawane
You should edit your previous response instead of posting multiple ones.
Praetorian