GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Aug-2004, 09:19
gavrile gavrile is offline
New Member
 
Join Date: Aug 2004
Posts: 11
gavrile is on a distinguished road

Popup menu


Hi,
I'm trying to open a popup menu using mouse right click.
I'm using the following code to do so but the menu returnes as null.
The code:
CMenu menu;
menu.LoadMenu(IDR_MENU);
CMenu *pPopup = menu.GetSubMenu(0);
ASSERT(pPopup);

pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, 20, 20, AfxGetMainWnd());

"pPopup" always returnes as null.
Any explanations?
Thanks,
Gabi
  #2  
Old 11-Aug-2004, 09:42
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Quote:
Originally Posted by gavrile
CMenu menu;
menu.LoadMenu(IDR_MENU);
CMenu *pPopup = menu.GetSubMenu(0);
ASSERT(pPopup);

pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, 20, 20, AfxGetMainWnd());


try changing this:

pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, 20, 20,this);
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #3  
Old 11-Aug-2004, 09:45
gavrile gavrile is offline
New Member
 
Join Date: Aug 2004
Posts: 11
gavrile is on a distinguished road
Thanks for the reply.
My problem occurs earlier. I get the null after the line:
CMenu *pPopup = menu.GetSubMenu(0);

Gabi
  #4  
Old 11-Aug-2004, 09:55
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Quote:
Originally Posted by gavrile
Thanks for the reply.
My problem occurs earlier. I get the null after the line:
CMenu *pPopup = menu.GetSubMenu(0);

Gabi

well then the code is fine in my view, the problem might be when u create the menu in the resource, check this guidline when creating the menu:

Quote:
When you create the menu, add all of the menu items in the first drop down on the menu.
Open the menu properties and select the pop-up checkbox on the properties page for the first menu item.
Don't select the "view as popup" option when you right click on the menu.

__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #5  
Old 11-Aug-2004, 23:48
gavrile gavrile is offline
New Member
 
Join Date: Aug 2004
Posts: 11
gavrile is on a distinguished road
What do you mean by: "add all of the menu items in the first drop down on the menu"?
If I have the following menu Items: "one", "two", "three" and so on.
Do I put "one" at the head of the first drop down, Define it as popup menu (which means it does not have id) and put "two", "three" under it as non popup menus?
Thanks,
Gabi
  #6  
Old 12-Aug-2004, 01:09
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Quote:
Originally Posted by gavrile
What do you mean by: "add all of the menu items in the first drop down on the menu"?
If I have the following menu Items: "one", "two", "three" and so on.
Do I put "one" at the head of the first drop down, Define it as popup menu (which means it does not have id) and put "two", "three" under it as non popup menus?
Thanks,
Gabi

Here is a picture shows how to do it:
Attached Images
File Type: jpg menuPic.jpg (29.0 KB, 116 views)
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #7  
Old 12-Aug-2004, 01:15
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 890
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by gavrile
What do you mean by: "add all of the menu items in the first drop down on the menu"?
If I have the following menu Items: "one", "two", "three" and so on.
Do I put "one" at the head of the first drop down, Define it as popup menu (which means it does not have id) and put "two", "three" under it as non popup menus?
Thanks,
Gabi

Nope.
You should put something else at the top of the menu - for example "Numbers" - this will be with the "Pop-up" option selected, and put "one", "two", "three" in this drop-down == "add all of the menu items in the first drop down on the menu"

It probably returns NULL because "one" is a normal item inside the popup.
Suppose you set the ID of the "one" item to IDC_ONE:
Code:
if ( Menu.GetMenuItemID(0) == IDC_ONE || (UINT)Menu.GetSafeHmenu() == IDC_ONE ) { AfxMessageBox("Normal menu item (non-popup)"); }

If you get the message box, it means you did it wrong 8-) (the code checks if you set the first item to non-poup).

Regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #8  
Old 12-Aug-2004, 01:19
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 890
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Oooups, sorry Max Payne, when I began replying, I didn't see your post (the page didn't refresh).

The picture is realy worth a thousand words
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #9  
Old 12-Aug-2004, 01:50
gavrile gavrile is offline
New Member
 
Join Date: Aug 2004
Posts: 11
gavrile is on a distinguished road
Thanks Max Payne and LucyWiz,
This solves my problem.
Gabi
 
 

Recent GIDBlogWelcome to Baghdad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
is that possible to create a popup that... stevewatt88 Web Design Forum 3 02-Sep-2004 10:14
javascript menu dopee Web Design Forum 7 30-Jul-2004 23:22
how to block the popup adverts / destroyads on msn messenger for free jrobbio Computer Software Forum - Windows 2 27-Jun-2004 20:26
Great way to disable flash rightclick menu BobbyDouglas Web Design Forum 0 02-Sep-2003 18:23
top menu bar trouble chalaska Web Design Forum 3 18-Jul-2002 21:11

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:23.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.