Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

popupmenu pops up without content

7 views
Skip to first unread message

.rhavin grobert

unread,
Apr 19, 2007, 11:29:28 AM4/19/07
to
i've tried to create a simple rightclick popup-menu. i displayes with
the correct height but all entries have a width of zero plus border :\

can someone please tell me what i missed?

thx in advance... -.rhavin;)

void CListCtrl::OnRButtonDown(UINT nFlags, CPoint point) {
CMenu menu;
ClientToScreen(&point);
menu.CreateMenu();
menu.InsertMenu(0,MF_BYCOMMAND,1,"test1");
menu.InsertMenu(0,MF_SEPARATOR,2,"");
menu.InsertMenu(0,MF_BYCOMMAND,3,"test2");
menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN, point.x, point.y,
this);
}

Tom Serface

unread,
Apr 19, 2007, 11:38:33 AM4/19/07
to
It looks like you're trying to insert the menu items before an existing item
with ID of 0, but there probably isn't one. Did you check the return code
from InsertMenu? You would also use the default MF_BYPOSITION, but I'd
put -1 for the position and just add them in order (it looks like you're
trying to do that).

Tom

".rhavin grobert" <cl...@yahoo.de> wrote in message
news:1176996568.1...@o5g2000hsb.googlegroups.com...

Scott McPhillips [MVP]

unread,
Apr 19, 2007, 12:25:27 PM4/19/07
to

Here's a little example that works.

CMenu Menu;
Menu.CreatePopupMenu();
Menu.AppendMenu(0, IDM_ZOOM, "Zoom");
Menu.AppendMenu(MF_SEPARATOR, 0, "");
Menu.AppendMenu(0, IDM_CANCEL_POPUP, "Cancel");

GetParentFrame()->ActivateFrame();
ClientToScreen(&point);
Menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON,
point.x-8, point.y-8,
AfxGetMainWnd());


--
Scott McPhillips [VC++ MVP]

.rhavin grobert

unread,
Apr 19, 2007, 12:59:57 PM4/19/07
to
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"

Tom Serface

unread,
Apr 19, 2007, 9:01:42 PM4/19/07
to
Did you try MF_BYPOSITION instead of MF_BYCOMMAND? I don't think that -1 is
going to be a good command.

Tom

".rhavin grobert" <cl...@yahoo.de> wrote in message

news:1177001997....@y80g2000hsf.googlegroups.com...

jmarc

unread,
Apr 20, 2007, 12:46:02 PM4/20/07
to
Did you try on UP button, instead
of DOWN...

jmarc..

".rhavin grobert" <cl...@yahoo.de> wrote in message

news:1176996568.1...@o5g2000hsb.googlegroups.com...

Victor

unread,
Apr 20, 2007, 4:15:00 PM4/20/07
to
Good point!
However, the best way would be handle the WM_CONTEXTMENU message.
(Although, it is not the reason of OP's problem!)

Victor

"jmarc" <jm...@incursion-voyages.com> wrote in message
news:e76Wh.10917$VF5.7447@edtnps82...

0 new messages