Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Tracking a control in a dialog window

Posted on 2000-03-06
3
Medium Priority
?
267 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
[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 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 200 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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