rtn
asked on
CMenu::GetSubMenu()
I am trying to get a popup menu to display when the right mouse button is clicked. However CMenu::GetSubMenu() seems to be returning a NULL pointer, and I don't know why!
Here is my code:-
void CMenuView::OnContextMenu(C Wnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
CMenu zooMenu;
CMenu *pPopup ;
int Test;
// Store popup point, and convert to client coordinates
// for the drawing functions
m_ptMsg = point;
ScreenToClient( &m_ptMsg );
Test = zooMenu.LoadMenu( IDR_MENUPOP );
if (Test == 0 )
{
AfxMessageBox("unsuccessfu l");
}
pPopup = zooMenu.GetSubMenu( 0 );
if (*pPopup == NULL)
{
AfxMessageBox("!");
}
else
{
AfxMessageBox("$");
pPopup->TrackPopupMenu( TPM_LEFTALIGN|TPM_RIGHTBUT TON,
point.x,
point.y,
this) ;
}
}
Thanks for your help.
Here is my code:-
void CMenuView::OnContextMenu(C
{
// TODO: Add your message handler code here
CMenu zooMenu;
CMenu *pPopup ;
int Test;
// Store popup point, and convert to client coordinates
// for the drawing functions
m_ptMsg = point;
ScreenToClient( &m_ptMsg );
Test = zooMenu.LoadMenu( IDR_MENUPOP );
if (Test == 0 )
{
AfxMessageBox("unsuccessfu
}
pPopup = zooMenu.GetSubMenu( 0 );
if (*pPopup == NULL)
{
AfxMessageBox("!");
}
else
{
AfxMessageBox("$");
pPopup->TrackPopupMenu( TPM_LEFTALIGN|TPM_RIGHTBUT
point.x,
point.y,
this) ;
}
}
Thanks for your help.
Your code seems to be right. Try putting the same code in WM_RBUTTONDOWN message handler.
This is the code I used and it seemed to work:-
CMenu menu;
VERIFY(menu.LoadMenu(IDR_P OPUP_MENU) );
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CPoint point;
GetCursorPos(&point);
pPopup->TrackPopupMenu(TPM _LEFTALIGN | TPM_LEFTBUTTON,
point.x, point.y, this);
This is the code I used and it seemed to work:-
CMenu menu;
VERIFY(menu.LoadMenu(IDR_P
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CPoint point;
GetCursorPos(&point);
pPopup->TrackPopupMenu(TPM
point.x, point.y, this);
One of the reason that you r getting NULL pointer can be that IDR_MENUPOP menu is not a popup menu. Check its style inthe resource editor. Make sure that Popup menu option is checked.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have removed the GetSubMenu() function in order to use TrackPopupMenu() directly.
pPopup = zooMenu.GetSubMenu( 0 ); is now
pPopup = &zooMenu;
Now it works apart from only a 3mm vertical strip is displayed. From this strip the menu items can be selected correctly, but the menu can not be seen properly.
Thanks for your help.
pPopup = zooMenu.GetSubMenu( 0 ); is now
pPopup = &zooMenu;
Now it works apart from only a 3mm vertical strip is displayed. From this strip the menu items can be selected correctly, but the menu can not be seen properly.
Thanks for your help.
ASKER
I have removed the GetSubMenu() function in order to use TrackPopupMenu() directly.
pPopup = zooMenu.GetSubMenu( 0 ); is now
pPopup = &zooMenu;
Now it works apart from only a 3mm vertical strip is displayed. From this strip the menu items can be selected correctly, but the menu can not be seen properly.
Thanks for your help.
pPopup = zooMenu.GetSubMenu( 0 ); is now
pPopup = &zooMenu;
Now it works apart from only a 3mm vertical strip is displayed. From this strip the menu items can be selected correctly, but the menu can not be seen properly.
Thanks for your help.
ASKER
I have removed the GetSubMenu() function in order to use TrackPopupMenu() directly.
pPopup = zooMenu.GetSubMenu( 0 ); is now
pPopup = &zooMenu;
Now it works apart from only a 3mm vertical strip is displayed. From this strip the menu items can be selected correctly, but the menu can not be seen properly.
Thanks for your help.
pPopup = zooMenu.GetSubMenu( 0 ); is now
pPopup = &zooMenu;
Now it works apart from only a 3mm vertical strip is displayed. From this strip the menu items can be selected correctly, but the menu can not be seen properly.
Thanks for your help.
ASKER