Print Page | Close Window

CXTTreeCtrl

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Controls
Forum Description: Topics Related to Codejock Controls
URL: http://forum.codejock.com/forum_posts.asp?TID=15673
Printed Date: 29 April 2024 at 6:21am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTTreeCtrl
Posted By: feffe
Subject: CXTTreeCtrl
Date Posted: 20 November 2009 at 8:55am
Hi
 
My CXTResizeDialog has a CXTTreeCtrl inside.
 
I'd like that my TreeCtrl has tooltips with Office style, and that when the tooltip is shown
for a SELECTED item of the tree, the tooltip changes background color.
 
I think that the 2 problems are related...
 
I've tried to apply the code of ToolTipContext Sample propertiesdialog.cpp,
but probably set the theme for a treectrl is quite different than for a button.
 
Could anybody help me?
 
Thanks a lot :)
 
EDIT: The main question is... Can I have office-like tooltips in a treectrl???



Replies:
Posted By: rdhd
Date Posted: 04 December 2009 at 5:50pm
If the CXTTreeCtrl is derived from CTreeCtrl, then it is probably getting the "old yeller" tooltip (XP) from the MFC/OS control. I have turned that tip off on some of our MFC/OS based controls by calling SetTooltips(NULL). CTreeCtrl has that method too and we have a tree control derived from the MFC one on whch I have implemented the CJ office style tip. You have to create the CJ tooltip context for the tree control, set up the theme and implement the tipping yourself (I usually use the static CJ tip context's FillinToolInfo method call from my OnToolHitTest code.)
 

void MyTreeCtrl::OnMouseMove( UINT nFlags, CPoint point )

{

SetToolTips( NULL );

...
}
 

class __declspec(FUNC_DECL) MyTreeCtrl : public CTreeCtrl

{

...

CXTPToolTipContext m_ToolTipContext;

}
 

BOOL MyTreeCtrl::PreTranslateMessage( MSG* pMsg )

{

BOOL bPreTrans = TRUE;

if( m_bUseCodejockTips )

{

m_ToolTipContext.FilterToolTipMessage(this, pMsg);

}

bPreTrans = CTreeCtrl::PreTranslateMessage( pMsg );

return bPreTrans;

}

INT_PTR MyTreeCtrl::OnToolHitTest(CPoint point, TOOLINFO* pTI) const

{

UINT temp = 0;

if( false == m_bUseCodejockTips )

{

return CTreeCtrl::OnToolHitTest( point, pTI );

}

else

{

//CPoint treePt = point;

//ClientToScreen( &treePt );

//m_tree.ScreenToClient( &treePt );

////TVHITTESTINFO HitTestInfo;

//HTREEITEM hItem = HitTest( treePt, 0 );

HTREEITEM hItem = HitTest( point, &temp );

if( hItem )

{

pTI->lpszText = NULL;

pTI->hwnd = GetSafeHwnd();

pTI->uId = (UINT_PTR)hItem;// both are the same size on 32/64 bit system

// Get the item rectangle for the text only. The MSDN does not say so but at least on my Vista

// machine I have found that passing in FALSE for bTextOnly results in the returned rectangle

// being clipped to the client rect of the tree.

CRect rect;

GetItemRect( hItem, &rect, TRUE );

// Now get the tree's client rectangle.

CRect clientRect;

GetClientRect(&clientRect);

// Now union the two so I can see if the result is larger than the client rect. If it is, then

// I assume the user cannot see all the text string and I will tip the user.

CRect unionRect;

unionRect.UnionRect(&clientRect,&rect);

BOOL bTip = unionRect != clientRect;

if( false == bTip )

{

// Text may be within the client rect of the tree control but if it is pushed off-screen, say

// by moving it to the right side of the monitor the text may not be visible to the user. So

// I will compare to the desktop and tip if I think the user cannot see the full text.

CRect desktopRect;

if (::GetWindowRect (GetDesktopWindow ()->GetSafeHwnd (), &desktopRect))

{

AdjustDesktopRectForMultipleMonitors(&desktopRect);

ClientToScreen( clientRect );

CRect intersectRect;

intersectRect.IntersectRect( clientRect, desktopRect );

bTip = intersectRect != clientRect;

}

}

if( bTip )

{

CString strText = GetItemText( hItem );

// I have also found that if I send in the "text only" rectangle, and the text is not fully

// displayed due to the client rect, if the user places the mouse over the icon, CJ does not

// display the text. I need the item rect for the entire item.

CRect entireRect;

GetItemRect( hItem, &entireRect, FALSE );

CXTPToolTipContext::FillInToolInfo( pTI, pTI->hwnd, entireRect, pTI->uId, strText );

return (UINT_PTR)hItem;

}

}

}

return -1; // not found

}

At some point, init the context member data to your liking. Here's what I do:
 
void InitializeCXTPToolTipContext( CXTPToolTipContext* pToolTipContext )

{

if( pToolTipContext )

{

pToolTipContext->SetDelayTime(TTDT_INITIAL, 300);

pToolTipContext->SetDelayTime(TTDT_RESHOW, 0);// even 1 is useless

pToolTipContext->SetDelayTime(TTDT_AUTOPOP, 15000);// appears to be useless

pToolTipContext->SetStyle(xtpToolTipOffice2007);

pToolTipContext->ShowTitleAndDescription();

pToolTipContext->ShowImage(TRUE, 0);

pToolTipContext->SetMargin(CRect(5, 5, 5, 5));

pToolTipContext->SetMaxTipWidth(300);

//pToolTipContext->SetDelayTime(TTDT_INITIAL, 900);

//pToolTipContext->SetDelayTime(TTDT_RESHOW, 900);

pToolTipContext->SetTipBkColor(XTPColorManager()->GetColor(COLOR_GRADIENTINACTIVECAPTION));

}

}




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