Howdy, Stranger!

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


Deleting menus on exit...

SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
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.
//See if the menu needs freeing
if(this->hMainMenu != 0)
DeleteMenu(this->hMainMenu, 0, MF_BYPOSITION);
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?


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.

Sign In or Register to comment.