Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Tracking a control in a dialog window

How do I track a dynamically created control in a dialog window.
I create a dialog and its controls from a DLOG resource. However  I need to add a
another control depending on a certain criteria. I am currently using
DialogSelect() and a switch() statement to handle the dialog. My problem
is when I create a new control how do I track the control if I
don't know the controls item number? I have included a brief summary of the code below:


myDialog = GetNewDialog(kMainDialog, wStorage, (DialogPtr)-1);
theControl = NewControl(myDialog, &menuRect, "\paPopUpMenu", popupTitleLeftJust, 128, 0, popupMenuProc, 0);


before calling

DialogSelect(&gEventRecord, &hitWindow, &itemHit);

if( hitWindow == myDialog) {
      switch(itemHit) {
                  case item1:
                  
                        break;
                  
                  case item2:
            
                        break;
                  
            
            
            }
}
0
gail_p
Asked:
gail_p
1 Solution
 
gail_pAuthor Commented:
I figured this would be an easy question but no one has answered it.

Please.
0
 
longjianCommented:
Maybe you can set an item not to your contorl when you create it:

SetDialogItem(myDialog,yourItemNo,btnCtrl,(Handle)theControl,&menuRect)
0
 
Alex CuryloCommented:
Heh. Maybe you should just email me directly when you put a new question up :)

Anyway, this is indeed an easy question -- controls you create don't have an item number. It is possible to fool around with the item list in memory, but that's quite unsupported and I don't recommend you bother.

The correct thing to do is to keep track of "theControl", although I recommend you name it more distinctively, like "createdPopup" or something, and then instead of calling DialogSelect() right off, you'll have to manage your windows a bit more intensively. I don't know how complicated your windows are, but the general thrust will be something like this:

if (gEventRecord.what == mouseDown)
   {
   WindowPtr whichWindow;
   short part = FindWindow(gEventRecord.where, &whichWindow);
   if ((part == inContent) && (whichWindow == myDialog))
      {
      Control whichControl;
      Point localPt = gEventRecord.where;
      GlobalToLocal(&localPt);
      if (FindControl(localPt, myDialog, &whichControl) && (whichControl == createdPopup))
         {
         // do whatever you want here; you'll definitely want to start out with
         // TrackControl() and case on its result.
         }
      }

Note that it is probably much easier to put the extra control in the DITL resource and hide it if you don't want it than it is to create an extra control like this, given that you have to do all the control tracking the point of the Dialog Manager is to do for you when you add controls on your own.
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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now