Did you try MF_BYPOSITION instead of MF_BYCOMMAND? I don't think that -1 is
going to be a good command.
Scott McPhillips [MVP] wrote:
Here's a little example that works.
No, it got access violation;-)
here is what happens (i added UINT B to see the results in debug....)
CMenu menu;
UINT B = 2;
ClientToScreen(&point);
B = menu.CreateMenu(); // B is 1
B = menu.InsertMenu(-1,MF_BYCOMMAND,1,"test1"); // B is 1
B = menu.InsertMenu(-1,MF_SEPARATOR,2,""); // B is 1
B = menu.InsertMenu(-1,MF_BYCOMMAND,3,"test2"); // B is 1
B = menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN, point.x,
point.y, this);
// B is 1, menu is displayed with width ~ 0;
CMenu Menu;
B = Menu.CreatePopupMenu(); // B is 1
B = Menu.AppendMenu(0, 3, "Zoom"); // B is 1
B = Menu.AppendMenu(MF_SEPARATOR, 0, ""); // B is 1
B = Menu.AppendMenu(0, 4, "Cancel"); // B is 1
CFrameWnd* pFW = GetParentFrame(); // pFW is 0!;
if (pFW != 0) {pFW->ActivateFrame();}
ClientToScreen(&point);
B = Menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x-8,
point.y-8, AfxGetMainWnd());
// menu is displayed correctly "somewhere"