pipe
asked on
Trouble with popup menu
I use the code below to popup a menu i have, however, only the very left side of it shows, about 10 pixels in width. Is there something Im doing worng on my menu?
Thanks,
jer
HMENU hMenu; // Menu Handle
CMenu mMenu; // Graph popup menu
// Get the menu for the popup from the resource file
mMenu.LoadMenu( IDR_GRAPHPOPUP );
hMenu = mMenu.GetSafeHmenu();
if( !hMenu ){
return;
}
// Convert the mouse point to screen coordinates since that is what
// TrackPopup expects.
::ClientToScreen( GetSafeHwnd(), (LPPOINT)&point );
// Draw and track the "floating" popup
TrackPopupMenuEx( hMenu, NULL, point.x,
point.y, GetSafeHwnd(), NULL );
// Destroy the menu since were are done with it.
DestroyMenu( hMenu );
CFormView::OnRButtonDown(n Flags, point);
Thanks,
jer
HMENU hMenu; // Menu Handle
CMenu mMenu; // Graph popup menu
// Get the menu for the popup from the resource file
mMenu.LoadMenu( IDR_GRAPHPOPUP );
hMenu = mMenu.GetSafeHmenu();
if( !hMenu ){
return;
}
// Convert the mouse point to screen coordinates since that is what
// TrackPopup expects.
::ClientToScreen( GetSafeHwnd(), (LPPOINT)&point );
// Draw and track the "floating" popup
TrackPopupMenuEx( hMenu, NULL, point.x,
point.y, GetSafeHwnd(), NULL );
// Destroy the menu since were are done with it.
DestroyMenu( hMenu );
CFormView::OnRButtonDown(n
Hi,
U can map the WM_CONTEXTMENU message to Ur CFormView class and put the abouve code.
Cheers,
VinExpert
U can map the WM_CONTEXTMENU message to Ur CFormView class and put the abouve code.
Cheers,
VinExpert
ASKER
Eeek. Still have the problem and now the menu doe snot appear in the correct place.
Hi,
If u still want to continue with Ur own code
here is the modified code and put it in OnContextMenu() function
HMENU hMenu; // Menu Handle
CMenu mMenu; // Graph popup menu
// Get the menu for the popup from the resource file
mMenu.LoadMenu( IDR_MENU1 );
hMenu = mMenu.GetSafeHmenu();
hMenu = ::GetSubMenu(hMenu, 0);
if( !hMenu )
{
return;
}
// Draw and track the "floating" popup
TrackPopupMenuEx( hMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, this->GetSafeHwnd(), NULL );
// Destroy the menu since were are done with it.
DestroyMenu( hMenu );
I have removed ClientToScreen Convertion and added GetSubMenu(). Try it out.
VinExpert
If u still want to continue with Ur own code
here is the modified code and put it in OnContextMenu() function
HMENU hMenu; // Menu Handle
CMenu mMenu; // Graph popup menu
// Get the menu for the popup from the resource file
mMenu.LoadMenu( IDR_MENU1 );
hMenu = mMenu.GetSafeHmenu();
hMenu = ::GetSubMenu(hMenu, 0);
if( !hMenu )
{
return;
}
// Draw and track the "floating" popup
TrackPopupMenuEx( hMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, this->GetSafeHwnd(), NULL );
// Destroy the menu since were are done with it.
DestroyMenu( hMenu );
I have removed ClientToScreen Convertion and added GetSubMenu(). Try it out.
VinExpert
ASKER
Almost there maybe??? It is back in the correct place now, but stil most of the menu never gets drawn. only a few pixels wide.
This is exactlly what I have:
void CMyappView::OnContextMenu( CWnd* pWnd, CPoint point){
// The graph menu
CMenu menu;
// Load the menu.
menu.LoadMenu(IDR_GRAPHPOP UP);
// Pop the menu up
menu.TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x,
point.y, this, NULL);
}
This is exactlly what I have:
void CMyappView::OnContextMenu(
// The graph menu
CMenu menu;
// Load the menu.
menu.LoadMenu(IDR_GRAPHPOP
// Pop the menu up
menu.TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x,
point.y, this, NULL);
}
Hi,
Where is GetSubMenu()?. I told to put that. It will solve Ur Problem.
VinExpert
Where is GetSubMenu()?. I told to put that. It will solve Ur Problem.
VinExpert
Hi,
If it has only one menu item, then also do the GetSubMenu(0). It is needed for TrackPopupMenu().
Try it out.
VinExpert
If it has only one menu item, then also do the GetSubMenu(0). It is needed for TrackPopupMenu().
Try it out.
VinExpert
ASKER
Im sorry, I forgot to tell you that GetSubMenu was returning NULL and wouldl crash it. So I took it out.
ASKER
Ok, I got it now. My menu used to have only one Menu(nothing to the right).
Im not sure if I understand it, but I made it pop out to the right one, then started my menu there. If that is how you have to build your menu then I did not know that. If you submit again I will give you your points. Thanks.
Im not sure if I understand it, but I made it pop out to the right one, then started my menu there. If that is how you have to build your menu then I did not know that. If you submit again I will give you your points. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this out.
CMenu menu;
menu.LoadMenu(IDR_MAINFRAM
CMenu *popup = NULL;
popup = menu.GetSubMenu(0);
popup->TrackPopupMenu(TPM_
here IDR_MAINFRAME can be any menu from resource editor.
U need not do ClientToScreen()... The above code is working file.
Hope it solves Ur Problem
VinExpert