Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CMenu Appending Question

Status
Not open for further replies.

ronnyjljr

IS-IT--Management
Nov 23, 2003
249
US
Hello there,

I am creating a right click menu for my app and I am having trouble with the second parameter on CMenu::AppendMenu(). This parameter is the function id?

I have the following code working...
Code:
[blue]
 CMenu myMenu;
 POINT pos;
 GetCursorPos(&pos);

 myMenu.CreatePopupMenu();
 myMenu.AppendMenu(MF_STRING,ID_APP_EXIT, (LPCTSTR)"E&xit");
 myMenu.TrackPopupMenu(TPM_RIGHTALIGN,pos.x,pos.y,this);
[/blue]


I have a function called OnBnClickedButton1(), I want to add an entry to the menu so I call this function. I know it goes something like this...

Code:
[blue]

myMenu.AppendMenu(MF_STRING,[red]????????[/red], (LPCTSTR)"Add Key");

[/blue]

The second parameter is of type: UINT_PTR

Could someone please explain what I need to place in the code to execute my OnBnClickedButton1() function?


I know it was a long post, I just wanted to be clear.

Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
The second parameter is of type: UINT_PTR

Ehhh, no. It's an UINT.


MSDN said:
BOOL AppendMenu( UINT nFlags, UINT nIDNewItem = 0, LPCTSTR lpszNewItem = NULL );

nIDNewItem

Specifies either the command ID of the new menu item or, if nFlags is set to MF_POPUP, the menu handle (HMENU) of a pop-up menu. The nIDNewItem parameter is ignored (not needed) if nFlags is set to MF_SEPARATOR.


/Per
[sub]
www.perfnurt.se[/sub]
 
To associate the function with the call to your function OnBnClickedButton1 you can add a handler for the menu item using the wizard by double-click the menu item in the resource dialog.
From that handler you can call directly your member function OnBnClickedButton1.

You can do this manually by adding an entry in the parent window message map, but it is not so straightforward

I guess it is better to make the action a separate function and call it from the button pressed and from the tracking popup item handler. This will give some independence of thwe 2 implelementations while using the common part.

e.g.

void MyClass::OnBnClicketButton1()
{
//call worker function here
}

void MyClass::OnTrackItemHandler() //add with wizard
{
//call worker function here
}

Hope I was making myself clear,


s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Hi Guys,


Thanks for the responses, I already had a message map set up for when the button was clicked so I figured out I could use that.

I ended up figuring out that if you place the id of the button it sends the message :p

Code:
[blue]
	myMenu.AppendMenu(MF_STRING,IDC_BUTTON1,(LPCTSTR)"Add Key");

[/blue]

Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top