[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

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(nFlags, point);
0
pipe
Asked:
pipe
  • 6
  • 4
1 Solution
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

Try this out.

CMenu menu;
menu.LoadMenu(IDR_MAINFRAME);

CMenu *popup = NULL;
popup = menu.GetSubMenu(0);
popup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, this, NULL);

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
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

U can map the WM_CONTEXTMENU message to Ur CFormView class and put the abouve code.

Cheers,
VinExpert
0
 
pipeAuthor Commented:
Eeek. Still have the problem and now the menu doe snot appear in the correct place.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Vinayak KumbarSr Program ManagerCommented:
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
0
 
pipeAuthor Commented:
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_GRAPHPOPUP);
 
      // Pop the menu up
      menu.TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x,
            point.y, this, NULL);
      
}
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,
Where is GetSubMenu()?. I told to put that. It will solve Ur Problem.

VinExpert
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

If it has only one menu item, then also do the GetSubMenu(0). It is needed for TrackPopupMenu().

Try it out.
VinExpert
0
 
pipeAuthor Commented:
Im sorry, I forgot to tell you that GetSubMenu was returning NULL and wouldl crash it. So I took it out.
0
 
pipeAuthor Commented:
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.
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

So u got Ur problem solved. Good luck.

Regards,

VinExpert
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now