Subject |
Author |
Date |
|
Anna Kraus
|
Sep 28, 2010 - 11:12 AM
|
I have a toolbar of type CExtToolControlBar that contains buttons of type CExtBarButton. I would like to display a popup menu when the user right clicks on a button. How do I capture the right click so that I can create and display the popup menu?
|
|
Anna Kraus
|
Sep 28, 2010 - 1:16 PM
|
Thanks for your help. I was incorrect in my original post. My toolbar is of type CExtTabbedToolControlBarFlat. I have made the changes that you suggested but OnRButtonDown does not seem to get called. What am I missing? Here is what I have added: BEGIN_MESSAGE_MAP(CanXTabTBMain, CExtTabbedToolControlBarFlat)
ON_WM_RBUTTONDOWN ()
END_MESSAGE_MAP()
void
CanXTabTBMain::OnRButtonDown (UINT nFlags, CPoint point)
{
// display popup menu
CExtTabbedToolControlBarFlat::OnRButtonDown (nFlags, point);
} Thanks for your help.
|
|
Technical Support
|
Sep 29, 2010 - 9:03 AM
|
The solution is the same. But please create CExtTabbedToolControlBar::LocalNoReflectedToolBar -derived toolbar class instead of CExtToolControlBar -derived. You will also need to override CExtTabbedToolControlBar::OnBarCreateObject() virtual method and return instantiated version of your toolbar class.
|
|
Anna Kraus
|
Sep 30, 2010 - 11:56 AM
|
Thanks, your help solved my problem.
|
|
Anna Kraus
|
Sep 30, 2010 - 2:56 PM
|
I am now capturing the mouse right click but I am having trouble with the HitTest function. My code looks like: void
CanXTabTBMain::MyLocalNoReflectedToolBar::OnRButtonDown (UINT nFlags, CPoint point)
{
CExtToolControlBar * pToolBar = (CExtToolControlBar*)this;
int iHit = pToolBar->HitTest (point);
} My problem is that even when I right click while over a button the function HitTest is always returning -1. I am having trouble figuring out which button is selected. Thanks again for your help.
|
|
Anna Kraus
|
Sep 30, 2010 - 3:13 PM
|
My code is working now. I am getting the HitTest result by doing the following: int iHit = CExtToolControlBar::HitTest (point);
|
|
Technical Support
|
Sep 28, 2010 - 11:47 AM
|
Please create the CExtToolControlBar -derived class and handle the standard WM_RBUTTONDOWN message in it. The CExtToolControlBar::HitTest() method accepts mouse pointer coordinates in the client coordinate system of the CExtToolControlBar window and returns an zero-based index of the toolbar button or negative number if the mouse pointer is not over any toolbar button. The CExtToolControlBar::GetButton() returns the CExtBarButton toolbar button object by its index. The CExtBarButton::Rect() method returns the rectangular area of the toolbar button in the client coordinate system of the toolbar window. Here is example how to display context menu: <pre>CExtToolControlBar * pBar = . . . CExtBarButton * pTBB = . . . UINT nMenuResourceID = . . . bool bPopupMenuResource = . . . CRect rcBtn = pTBB->Rect(); pBar->ClientToScreen( &rcBtn ); pBar->ClientToScreen( &point ); DWORD dwTrackFlags = TPMX_OWNERDRAW_FIXED|TPMX_COMBINE_NONE|TPMX_NO_HIDE_RARELY; CExtPopupMenuWnd * pPopup = CExtPopupMenuWnd::InstantiatePopupMenu( pBar->GetSafeHwnd(), RUNTIME_CLASS(CExtPopupMenuWnd), pBar ); if( ! pPopup->LoadMenu( GetSafeHwnd(), nMenuResourceID, bPopupMenuResource, true ) ) return . . . if( ! pPopup->TrackPopupMenu( dwTrackFlags, point.x, point.y ) ) return . . . </code>
|
|
Anna Kraus
|
Nov 25, 2010 - 12:29 PM
|
I am able to capture the right clicks on menu buttons that are in the CExtToolControlBar and display the appropriate popup menu. Thank you for all of your help. I have some toolbars that have more buttons that can be displayed on the screen if the user’s screen is not very wide. For this case there is a bar that is displayed at the right end of the toolbar with a down arrow. If the user clicks on this arrow another window is displayed with the missing menu icons. How can I capture the right clicks when the user clicks on one of these?
|
|
Technical Support
|
Nov 26, 2010 - 6:29 AM
|
The CExtPopupBaseWnd::g_nMsgTranslateMouseClickEvent registered message allows you to intercept menu clicks. The pointer to the CExtPopupBaseWnd::TranslateMouseClickEventData_t data structure is used as a WPARAM message parameter. The m_nFlags property of this data structure contains the WM_MOUSE*** message number.
|
|
Anna Kraus
|
Nov 29, 2010 - 3:09 PM
|
I have added the following to my message_map: ON_REGISTERED_MESSAGE (CExtPopupBaseWnd::g_nMsgTranslateMouseClickEvent, OnMsgTranslateMouseClickEvent) but I am still not able to capture the right clicks. What am I doing wrong and/or missing?
|
|
Technical Support
|
Dec 1, 2010 - 12:16 PM
|
Here is the test code which demonstrates how to catch mouse button clicks over menu items:
LRESULT CMainFrame::OnMsgTranslateMouseClickEvent(WPARAM wParam, LPARAM lParam)
{
ASSERT_VALID( this ); wParam; lParam;
#ifdef _DEBUG
CExtPopupBaseWnd::TranslateMouseClickEventData_t * pData = (CExtPopupBaseWnd::TranslateMouseClickEventData_t*)wParam;
ASSERT( pData != NULL );
if( pData->m_nFlags == WM_LBUTTONDOWN )
afxDump << "WM_LBUTTONDOWN\r\n";
else
if( pData->m_nFlags == WM_MBUTTONDOWN )
afxDump << "WM_MBUTTONDOWN\r\n";
else
if( pData->m_nFlags == WM_RBUTTONDOWN )
afxDump << "WM_RBUTTONDOWN\r\n";
#endif // _DEBUG
return 0L;
}
|
|
Anna Kraus
|
Nov 25, 2010 - 1:19 PM
|
Also, how do I test when the user right clicks in the right end of the toolbar with the down arrow? I have noticed that the call to HitTest in this area always returns the value 28 and the CmdID is 4294967230
|
|
Technical Support
|
Nov 26, 2010 - 7:04 AM
|
The CExtToolControlBar::HitTest() method returns a toolbar button index. The CExtToolControlBar::GetButton() method returns a pointer to a toolbar button object by its index. If it’s the CExtBarContentExpandButton type of object, you hit-tested the toolbar’s chevron button.
|
|
Anna Kraus
|
Nov 22, 2010 - 5:10 PM
|
I have implemented the above code and my popup menu displays. My problem is that the items in the popup are all disabled. How do I enable the menu items in the popup menu?
|
|
Technical Support
|
Nov 23, 2010 - 4:30 AM
|
Menu items are controlled by the MFC’s command handling/updating mechanism. If you add a command handler for your menu item, it will be enabled automatically.
|