Solved

Tracking a control in a dialog window

Posted on 2000-03-06
3
254 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand data scrubbing tool 13 32
Detect CR LF to each line 12 158
Shell script to login to remote m/c and execute commands 10 78
move a line in eclipse 3 99
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 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

15 Experts available now in Live!

Get 1:1 Help Now