IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Haim on October 17, 2006, 12:50:32 AM

Title: attach / detach methods question
Post by: Haim on October 17, 2006, 12:50:32 AM
Can somebody please explain the methods attach() and detach(), that are part of Cmenu and Cimagelist classes in Aurora?
I know how to use them to return the handle of an object, but I do not understand why a special method is required for that, instead of accessing the handle as a member variable of the class.

Haim

Title: Re: attach / detach methods question
Post by: Ionic Wind Support Team on October 17, 2006, 01:38:41 AM
You detach a handle so the class doesn't free it when it goes out of scope.  If you have a CMenu instance in a subroutine then the destructor of CMenu is called when the subroutine exits.  That destructor frees the handle making it invalid.  Detaching gives you the ownership of the handle.
Title: Re: attach / detach methods question
Post by: Haim on October 17, 2006, 02:00:28 AM
Thanks,

Does this mean that handle is duplicated? Can the same menu be "detached" several times for usage with more than on window?  ???

Haim


Title: Re: attach / detach methods question
Post by: sapero on October 17, 2006, 03:26:23 AM
A menu can be attached to any number of windows, but if you destroy one window, the menu will be destroyed in all other windows too, since you use same handle for all windows.
After CMenu.Detach() the internal class HMENU variable is set to zero, so the destructor does not call DestroyMenu(), and you cannot detach it again.
CMenu.Attach() you can use for any menu if you want to work with menu using a class instead api, but remember to detach the handle before destroying the CMenu class if you want the handle to be valid longer than CMenu.
Title: Re: attach / detach methods question
Post by: Haim on October 17, 2006, 06:43:50 AM
Thanks Paul and Sapero for solving the Detach() mistery for me   :)

Haim