Cleaning up after calling GetSystemMenu()
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 me开发者_Python百科nu items. I don't see any mention of needing to call CloseHandle() or similar, so my current assumption is that this is not needed.
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.
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.
精彩评论