![]() |
ToolTipContxt for items in CTreeCtrl |
Post Reply ![]() |
Author | |
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() 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
Any ideas on how to accomplish this?
|
|
![]() |
|
rdhd ![]() Senior Member ![]() ![]() Joined: 13 August 2007 Location: United States Status: Offline Points: 921 |
![]() ![]() ![]() ![]() ![]() |
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; |
|
![]() |
|
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
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); ... }
|
|
![]() |
|
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
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.
|
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |