Troubles displaying a popup menu dynamically

Damian Powell
Oct 18 1999, 2:00 am   show options
Newsgroups: microsoft.public.vc.mfc
From: Damian Powell <damian_pow@my-deja.com> – Find messages by this author
Date: 1999/10/18
Subject: CMenu::TrackPopupMenu – strange behaviour.
Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse

Hello everyone,

I’m using the following code to display a popup-menu from a CDialog
derrived object but it doesn’t seem to work correctly.

When the menu is displayed, it appears as a thin-ish vertical line with
no text. However, the highlight does move as I move the mouse down the
menu and the correct menu items are selected from the various positions.

Can anyone tell me what I am doing wrong?

void CRs232ClientDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
CDialog::OnRButtonDown(nFlags, point);
ClientToScreen(&point);
CMenu menu;
menu.LoadMenu(IDR_MENU1);
menu.TrackPopupMenu (
TPM_LEFTALIGN|TPM_LEFTBUTTON,
point.x,
point.y,
this
);

 

}

Thanks in advance,
Damian.
Sent via Deja.com http://www.deja.com/
Before you buy.

Douglas Peterson
Oct 18 1999, 2:00 am   show options
Newsgroups: microsoft.public.vc.mfc
From: Douglas Peterson <douglas.peter@nospam.telex.com> – Find messages by this author
Date: 1999/10/18
Subject: Re: CMenu::TrackPopupMenu – strange behaviour.
Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse

There may be an “appropriate” solution, I don’t know, but this works:

Create your menu (IDR_MENU1) with a single popup menu item (sub-menu)
and put the “real” popup as items in this sub.  Then get the menu like
this:

menu.LoadMenu(IDR_MENU1);
CMenu* pPopup = menu.GetSubMenu(0);
pPopup->TrackPopupMenu(…)

 

– Show quoted text –

 

 

Bob Moore
Oct 18 1999, 2:00 am   show options
Newsgroups: microsoft.public.vc.mfc
From: Bob Moore <b@mvps.org> – Find messages by this author
Date: 1999/10/18
Subject: Re: CMenu::TrackPopupMenu – strange behaviour.
Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse

 

On Mon, 18 Oct 1999 15:42:39 GMT, Damian Powell wrote:
>When the menu is displayed, it appears as a thin-ish vertical line with
>no text. However, the highlight does move as I move the mouse down the
>menu and the correct menu items are selected from the various positions.

You’ve loaded a bar menu rather than a popup.

Leave a Reply

Your email address will not be published. Required fields are marked *