Solved

Tracking a control in a dialog window

Posted on 2000-03-06
3
252 Views
Last Modified: 2013-12-26
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
Comment
Question by:gail_p
3 Comments
 

Author Comment

by:gail_p
ID: 2594025
I figured this would be an easy question but no one has answered it.

Please.
0
 

Expert Comment

by:longjian
ID: 2627072
Maybe you can set an item not to your contorl when you create it:

SetDialogItem(myDialog,yourItemNo,btnCtrl,(Handle)theControl,&menuRect)
0
 
LVL 4

Accepted Solution

by:
Alex Curylo earned 50 total points
ID: 2638447
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 77
maxBlock challenge 30 112
substring method in java 1 97
Hibernate methods 2 68
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now