|
Thank you Oleg,
Before you published this example I got some reply from your tech support guys just suggesting to derive and implement my own CXTPToolbar class. So I did that yesterday, and actually managed to make it work for toolbar buttons. But when I tried the same for menu items – just didn’t work. Mistakenly, I derived from CXTPMenuBar instead of CXTPPopupBar. Your code example clarified all that, thank you. And since I had already my own class written for toolbars that worked, I simply applied the same for CXTPPopupBar – and oh miracle!!! I now can see tooltips for menu items, now that’s some hi-tech stuff J And it looks just amazing!!! Those VXPLib tooltips in combination with XTP library is kick-ass!!! I’m sending you a screenshot of what I got:

And for the menu items:

Now I would like to share the code I used for toolbars and menus, and which worked nicely for me:
class CXTPToolBarEx : public CXTPToolBar
{
DECLARE_XTP_COMMANDBAR(CXTPToolBarEx)
public :
CXTPToolBarEx();
virtual ~CXTPToolBarEx();
protected :
////////////////////////////////////////////////////////
// Toolbar messages:
//
afx_msg LRESULT OnHitTest(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnButtonCount(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnGetButton(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnGetButtonInfo(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
static int GetControlState(CXTPControl * pControl);
};
class CXTPPopupBarEx : public CXTPPopupBar
{
DECLARE_XTP_COMMANDBAR(CXTPPopupBarEx)
public :
CXTPPopupBarEx();
virtual ~CXTPPopupBarEx();
protected :
////////////////////////////////////////////////////////
// Toolbar messages:
//
afx_msg LRESULT OnHitTest(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnButtonCount(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnGetButton(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnGetButtonInfo(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
static int GetControlState(CXTPControl * pControl);
};
|
And implementation:
// CXTPToolBarEx
IMPLEMENT_XTP_COMMANDBAR(CXTPToolBarEx, CXTPToolBar)
CXTPToolBarEx::CXTPToolBarEx()
{
}
CXTPToolBarEx::~CXTPToolBarEx()
{
}
int CXTPToolBarEx::GetControlState(CXTPControl * pControl)
{
int iState = pControl->GetEnabled()?TBSTATE_ENABLED:0;
iState |= pControl->GetChecked()?TBSTATE_CHECKED:0;
iState |= (pControl->GetHideFlags()&xtpNoHide)?0:TBSTATE_HIDDEN ;
iState |= pControl->GetPressed()?TBSTATE_PRESSED:0;
iState |= pControl->GetWrap()?TBSTATE_WRAP:0;
return iState;
}
BEGIN_MESSAGE_MAP(CXTPToolBarEx, CXTPToolBar)
ON_MESSAGE(TB_HITTEST, OnHitTest)
ON_MESSAGE(TB_BUTTONCOUNT, OnButtonCount)
ON_MESSAGE(TB_GETBUTTON, OnGetButton)
ON_MESSAGE(TB_GETBUTTONINFO, OnGetButtonInfo)
END_MESSAGE_MAP()
// CXTPToolBarEx message handlers
LRESULT CXTPToolBarEx::OnHitTest(WPARAM wParam, LPARAM lParam)
{
LPPOINT lpPoint = (LPPOINT)lParam;
CXTPControl * pControl = GetControls()->HitTest(CPoint(lpPoint->x, lpPoint->y));
if(pControl)
return pControl->GetIndex();
return -1;
}
LRESULT CXTPToolBarEx::OnButtonCount(WPARAM wParam, LPARAM lParam)
{
return GetControls()->GetCount();
}
LRESULT CXTPToolBarEx::OnGetButton(WPARAM wParam, LPARAM lParam)
{
LPTBBUTTON lpButton = (LPTBBUTTON)lParam;
CXTPControl * pControl = GetControls()->GetAt(( int)wParam);
if(!pControl)
return FALSE;
lpButton->iBitmap = pControl->GetIndex();
lpButton->idCommand = pControl->GetID();
lpButton->fsState = GetControlState(pControl);
lpButton->dwData = pControl->GetTag();
lpButton->iString = (INT_PTR)(LPCTSTR)pControl->GetCaption();
lpButton->fsStyle = 0; // Unsupported;
return TRUE;
}
LRESULT CXTPToolBarEx::OnGetButtonInfo(WPARAM wParam, LPARAM lParam)
{
LPTBBUTTONINFO lpInfo = (LPTBBUTTONINFO)lParam;
CXTPControl * pControl = GetControls()->FindControl(xtpControlButton, ( int)wParam, FALSE, FALSE);
if(!pControl)
return -1;
if(lpInfo->dwMask & TBIF_STATE)
lpInfo->fsState = GetControlState(pControl);
return pControl->GetID();
}
//////////////////////////////////////////////////////////// /
// CXTPPopupBarEx
IMPLEMENT_XTP_COMMANDBAR(CXTPPopupBarEx, CXTPPopupBar)
CXTPPopupBarEx::CXTPPopupBarEx()
{
}
CXTPPopupBarEx::~CXTPPopupBarEx()
{
}
int CXTPPopupBarEx::GetControlState(CXTPControl * pControl)
{
int iState = pControl->GetEnabled()?TBSTATE_ENABLED:0;
iState |= pControl->GetChecked()?TBSTATE_CHECKED:0;
iState |= (pControl->GetHideFlags()&xtpNoHide)?0:TBSTATE_HIDDEN ;
iState |= pControl->GetPressed()?TBSTATE_PRESSED:0;
iState |= pControl->GetWrap()?TBSTATE_WRAP:0;
return iState;
}
BEGIN_MESSAGE_MAP(CXTPPopupBarEx, CXTPPopupBar)
ON_MESSAGE(TB_HITTEST, OnHitTest)
ON_MESSAGE(TB_BUTTONCOUNT, OnButtonCount)
ON_MESSAGE(TB_GETBUTTON, OnGetButton)
ON_MESSAGE(TB_GETBUTTONINFO, OnGetButtonInfo)
END_MESSAGE_MAP()
// CXTPPopupBarEx message handlers
LRESULT CXTPPopupBarEx::OnHitTest(WPARAM wParam, LPARAM lParam)
{
LPPOINT lpPoint = (LPPOINT)lParam;
CXTPControl * pControl = GetControls()->HitTest(CPoint(lpPoint->x, lpPoint->y));
if(pControl)
return pControl->GetIndex();
return -1;
}
LRESULT CXTPPopupBarEx::OnButtonCount(WPARAM wParam, LPARAM lParam)
{
return GetControls()->GetCount();
}
LRESULT CXTPPopupBarEx::OnGetButton(WPARAM wParam, LPARAM lParam)
{
LPTBBUTTON lpButton = (LPTBBUTTON)lParam;
CXTPControl * pControl = GetControls()->GetAt(( int)wParam);
if(!pControl)
return FALSE;
lpButton->iBitmap = pControl->GetIndex();
lpButton->idCommand = pControl->GetID();
lpButton->fsState = GetControlState(pControl);
lpButton->dwData = pControl->GetTag();
lpButton->iString = (INT_PTR)(LPCTSTR)pControl->GetCaption();
lpButton->fsStyle = 0; // Unsupported;
return TRUE;
}
LRESULT CXTPPopupBarEx::OnGetButtonInfo(WPARAM wParam, LPARAM lParam)
{
LPTBBUTTONINFO lpInfo = (LPTBBUTTONINFO)lParam;
CXTPControl * pControl = GetControls()->FindControl(xtpControlButton, ( int)wParam, FALSE, FALSE);
if(!pControl)
return -1;
if(lpInfo->dwMask & TBIF_STATE)
lpInfo->fsState = GetControlState(pControl);
return pControl->GetID();
}
|
I hope it will be just as useful to somebody else who decides to use custom tooltips like VXPLib in their projects 
Regards,
Vitaly Tomilov
|