views:

49

answers:

2

I'm using Florian's wrapper class to call GetSystemMenu() to add a custom menu item to the system menu for an application.

I'm just curious as to whether there is any cleanup required for the handle returned by calling GetSystemMenu or the additional menu items. I don't see any mention of needing to call CloseHandle() or similar, so my current assumption is that this is not needed.

+1  A: 

You shouldn't have to worry about it.

Check the MSDN docs for DestroyMenu:

A menu that is assigned to a window is automatically destroyed when the application closes.

In general, Windows should destroy the menu when your form is closed, which in turn will destroy your custom menu items.

Reed Copsey
A: 

I have had a look at the wrapper and my gut feeling is this:

The handle used within SystemMenu.cs is giving me a doubt...

private IntPtr m_SysMenu = IntPtr.Zero; // Handle to the System Menu

That handle, nowhere in the code is being explicitly closed or released...which leads me to think that there should be an IDisposable implementation within the code to close/release the handle...

What do you think?

Hope this helps, Best regards, Tom.

tommieb75
Sorry to be pedantic and nit-picky...but had to post my thought on it.
tommieb75
See Reed's answer. It is probably deleted in DefWindowProc's handling of WM_NCDESTROY.
Michael
@Michael: Thanks... but can you clarify DefWindowProc in the aspect of .NET...or did you mean WndProc? (the protected override method commonly found in controls)
tommieb75