Print Page | Close Window

ToolTipContxt for items in CTreeCtrl

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=9133
Printed Date: 11 May 2024 at 11:54pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: ToolTipContxt for items in CTreeCtrl
Posted By: znakeeye
Subject: ToolTipContxt for items in CTreeCtrl
Date Posted: 18 December 2007 at 7:21am
I'm trying to display Office2007-styled tooltips for all items in my CXTTreeCtrl-derived class. This seems tricky! I found this piece of information, but I still can't get it to work: http://forum.codejock.com/forum_posts.asp?TID=8578&KW=tree+tooltip - http://forum.codejock.com/forum_posts.asp?TID=8578&KW=tree+tooltip
 
Any ideas on how to accomplish this?



Replies:
Posted By: rdhd
Date Posted: 19 December 2007 at 2:29pm
Unfortunately CJ does not provide a tooltip control that is subclassed from the MFC tooltip control. Otherwise one could just call SetToolTips and pass in the pointer to a subclassed control. So its a bit harder to do but can be done.
 
First call CTreeCtrl's SetToolTips(NULL) - that turns off the MFC tooltips in the CTreeCtrl (which if I remember correct codejock does subclass CXTTreeCtrl from).
 
Then you have to relay mouse messages to the context using the CJ context's FilterToolTipMessage method (if you relay the mouse event from a handler you have to convert from client to screen). That goes something like this (I subclassed CTreeCtrl to get the mouse messages and implemented a "RelayEvent" method where I pass in e.g., WM_MOUSEMOVE as the first arg):

void MyListCtrl::RelayEvent(UINT message, WPARAM wParam, LPARAM lParam)

{

MSG msg;

msg.hwnd= m_hWnd;

msg.message= message;

msg.wParam= wParam;

msg.lParam= lParam;

POINT pt;

pt.x = LOWORD (lParam);

pt.y = HIWORD (lParam);

ClientToScreen(&pt);

msg.time= clock();

msg.pt.x= pt.x;

msg.pt.y= pt.y;

m_ToolTipContext.FilterToolTipMessage(this, &msg);

}

Then you also need to implement OnToolHitTest and OnToolTipText (depending on how you want to supply the text - it can be supplied in the OnToolHitTest routine).

Make sure the ID you provide in OnToolHitTest changes with each cell or CJ won't ask for the text. I do something like this in OnToolHitTest:

pTI->rect = rectCell;

pTI->hwnd = m_hWnd;

pTI->uId = (UINT)(( nItem << 10 ) + (hi.iSubItem & 0x3ff) + 1 );

pTI->lpszText = LPSTR_TEXTCALLBACK;



Posted By: znakeeye
Date Posted: 02 January 2008 at 4:06am
Thanks for your response. Though, I can't get it working here. OnToolHitTest and OnToolTipText are never called
 
Here is my WM_MOUSEMOVE trap:
 
BOOL CMyTreeCtrl::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT *pResult)
{
 if (message == WM_MOUSEMOVE)
  RelayEvent(message, wParam, lParam);
...
}
 


Posted By: znakeeye
Date Posted: 03 January 2008 at 4:58am
For God's sake! Solved it...
 
I had removed "const" from the OnToolHitTest declaration, due to a call to the non-const function CancelToolTips()...
 
I had a feeling long ago, but I ignored it until now. Thanks for your code. I believe I can use it here.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net