Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Deleting menus on exit...

SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
I'm working on an application that creates its main menu using "CreateMenu()" before the window is created. This way I can stay away from VS2005's bloated resource files. The thing is, when I close out the program, I want to know that all of my resources are freed to avoid memory-leaks, but I am not sure if I am freeing the menu properly or not. I am using "DeleteMenu()" to attempt to delete the entire menu and sub-menus in one quick, easy call. The MSDN says that "DeleteMenu()" will do this, but I am not sure whether or not I am calling it correctly to do so.
[code]
//See if the menu needs freeing
if(this->hMainMenu != 0)
DeleteMenu(this->hMainMenu, 0, MF_BYPOSITION);
[/code]
That is in the class method for cleaning up my prorgam. I am assuming that specifying position zero will delete everything from that position on. Is this correct?

*EDIT*

After a few hours of searching I found out that to free a menu, you must call "DestroyMenu(HMENU)". This takes care of all items on the menu, but not sub-menus. You should destroy all sub-menus first, then the parent menu.

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
Sign In or Register to comment.