dwp090598
asked on
Menu Resource
I creating multiple windows each containing the same System 7 pop-up menu control, I append several menu items to the menu when creating window. If I Dispose or Close the window the appended menu items disappear in all of the windows. Apparently when I DisposeWindow or CloseWindow (tried both) a window it disposes the menu? How can I prevents this?
I wonder what would happen if you set the ControlList member of the window record to zero just prior to disposing of it. I would think it would not be able to dispose the controls on the window. But then you would have a bunch of control handle memory leaks. If you do this, you would need to copy the control handles somewhere and dispose of them yourself at some point.
I think boonstra has the best solution and the safest.
I think boonstra has the best solution and the safest.
ASKER
After adding the above code I am getting illegal token error - never seen this before
Not sure what you mean by this - is it a compile error or an execution error? By private email I've sent the test code I used to generate my answer.
ASKER
the error was a compile error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The code does work and I accept boonstra's answer.
The solution is to clone the popup for each window. The following code is skanky, but it works:
static ControlHandle DupPopUpControl(short controlID,
short newControlID, short newMenuID, WindowPtr wind) {
ControlHandle controlHdl;
Handle hdl;
MenuHandle mHandle;
short mID;
/* get control resource */
hdl = GetResource('CNTL',control
/* extract menu ID from control resource */
mID = *(short *)(*hdl+14);
/* copy MENU resource */
mHandle = (MenuHandle)GetResource('M
(**mHandle).menuID = newMenuID;
DetachResource((Handle)mHa
AddResource((Handle)mHandl
/* copy CNTL resource with new MENU ID */
DetachResource((Handle)hdl
*(short *)(*hdl+14) = newMenuID;
AddResource((Handle)hdl,'C
/* finally, attached the cloned control to the window */
controlHdl = GetNewControl(newControlID
return controlHdl;
}
/* assume CNTL 128 is the popup control you want to clone */
/* 301, 3001, 302, 3002 are arbitrary, but they must be different for each window and unique from other CNTL and MENU items in your resource file */
controlHdl = DupPopUpControl(128,301,30
mHandle = (**((PopupPrivateData **)((**controlHdl).contrlD
AppendMenu(mHandle,"\pAdde
controlHdl = DupPopUpControl(128,302,30
mHandle = (**((PopupPrivateData **)((**controlHdl).contrlD
AppendMenu(mHandle,"\pAdde