April 19, 2024, 11:33:04 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


attach / detach methods question

Started by Haim, October 17, 2006, 12:50:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haim

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


Ionic Wind Support Team

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.
Ionic Wind Support Team

Haim

Thanks,

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

Haim



sapero

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.

Haim

Thanks Paul and Sapero for solving the Detach() mistery for me   :)

Haim