[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Menu Resource

Posted on 1998-12-20
7
Medium Priority
?
249 Views
Last Modified: 2013-12-26
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?
0
Comment
Question by:dwp090598
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:boonstra
ID: 1291653
You're running into the fact that DisposeWindow and CloseWindow automatically remove all controls associated with the window.  Since you've added the same control to multiple windows, closing one gets rid of the modified popup for all windows.

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',controlID);
 
  /* extract menu ID from control resource */
  mID = *(short *)(*hdl+14);

  /* copy MENU resource */
  mHandle = (MenuHandle)GetResource('MENU',mID);
  (**mHandle).menuID = newMenuID;
  DetachResource((Handle)mHandle);
  AddResource((Handle)mHandle,'MENU',newMenuID,"\p");
 
  /* copy CNTL resource with new MENU ID */
  DetachResource((Handle)hdl);
  *(short *)(*hdl+14) = newMenuID;
  AddResource((Handle)hdl,'CNTL',newControlID,"\p");
 
  /* finally, attached the cloned control to the window */
  controlHdl = GetNewControl(newControlID,wind);
  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,3001,gWindowPtr[0]);
  mHandle = (**((PopupPrivateData **)((**controlHdl).contrlData))).mHandle;
  AppendMenu(mHandle,"\pAdded Item 1");
 
  controlHdl = DupPopUpControl(128,302,3002,gWindowPtr[1]);
  mHandle = (**((PopupPrivateData **)((**controlHdl).contrlData))).mHandle;
  AppendMenu(mHandle,"\pAdded Item 2");
 

0
 

Expert Comment

by:paulsat
ID: 1291654
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.
0
 

Author Comment

by:dwp090598
ID: 1291655
After adding the above code I am getting illegal token error - never seen this before
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 3

Expert Comment

by:boonstra
ID: 1291656
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.  
0
 

Author Comment

by:dwp090598
ID: 1291657
the error was a compile error.
0
 
LVL 3

Accepted Solution

by:
boonstra earned 200 total points
ID: 1291658
dwp reported via email that the sample code dropped him into MacsBug with a hard crash in NQDEmptyRgn that I suspect (from looking at his StdLog) might be related to the Mercutio GDevice unlocking problem, but I'm not certain.  I'm unable to duplicate his crash.  In any case, he reports that: "I did resolve the problem by reloading the menu and inserting the new menu items each time I close any window containing the control. "

So, his problem is fixed.  I still think the code I posted works.  We'll see what kind of grade he gives my answer ....  :-)
0
 

Author Comment

by:dwp090598
ID: 1291659
The code does work and I accept boonstra's answer.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question