Solved

Tracking a control in a dialog window

Posted on 2000-03-06
3
249 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
Comment Utility
I figured this would be an easy question but no one has answered it.

Please.
0
 

Expert Comment

by:longjian
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Looking for a specific application/software 2 91
List out all word 7 219
substring method in java 1 79
scoreUp challenge 14 47
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

772 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