?
Solved

Multiple dialogs one class

Posted on 1998-06-16
6
Medium Priority
?
237 Views
Last Modified: 2012-05-07
I have a series of dialog boxes that are used to request general information from the user.  I would like to create a single "Utilities" class that encompasses all of these dialogs.  Can a single class contain multiple dialogs?  If so, how would an external class access an individual dialog contained in this "Utilities" class?
0
Comment
Question by:jerm
[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
  • 2
  • 2
  • 2
6 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1166006
I suspect that what you really want is inheritance, not containment (encompass).  

Can you explain what it is you want to achieve?  and then I'll see I fi can help you make the right choice.  

It wouldn't hurt to post some code, or you can e-mail it to me (if there is too much to post) at nietod@theshop.net.
0
 

Author Comment

by:jerm
ID: 1166007
I want to achieve a single class that can be called upon to provide different dialogs for use in one application.  For example class CUtilDlgs which contains a modal dialog to request an index number, a modal dialog to request a search string and a modal dialog to display the results of a function.  I would be able to create a single class variable (i.e. CUtilDlgs utils) which then provides access to these three dialogs.  For example:
utils.DoModal(RequestIndex)
utils.DoModal(RequestSearchString)
utils.DoModal(DisplayResults)

I hope this explains my predicament sufficiently
0
 
LVL 22

Accepted Solution

by:
nietod earned 60 total points
ID: 1166008
I'm not sure I see an advantage to doing it that way.  

But you can create a new class that has three (or more) members that are the different dialogs you want to support, like.

class CUtilDlgs
{
   CIndexDlg IndexDlg;
   CSearchDlg SearchDlg;
   CDisplayDlg DisplayDlg;
}

Then the different DoModal functions can access the different dialog members.

Is that the type of thing you are looking for?  I can't see any reason for it, except that it groups the dialogs together.  That way if one is created the others are created, and perhaps the containing class will have other data that is used by all three.

Does this help?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 10

Expert Comment

by:RONSLOW
ID: 1166009
I see no advantage in having a single class to do this.

Is is that you don't like creating a dialog variable, doing DoModal etc for each one, and just want to create a 'utils' object that can access each type of dialog?

If so, why not add a static memeber to each dialog class that does the work for you .. eg.

class CRequestIndex : public CDialog {
  ...
public:
  static bool Do(int& index) {
    CRequestIndex dlg;
    book ok = IDOK == dlg.DoModal();
    if (ok) index = dlg.m_index;
    return ok;
  }
};

class CRequestSearchString : public CDialog {
  ...
public:
  static bool Do(CString& string) {
    CRequestSearchString dlg;
    book ok = IDOK == dlg.DoModal();
    if (ok) string = dlg.m_string;
    return ok;
  }
};

etc.

Then the calling program would just say
  int index;
  CString string;
  CRequestIndex::Do(index);
  CReuestSearchResults::Do(string);

Now you don't need to manage the dialog varaible, DoModal'ing , checking the return code and getting the data yourself .. this is all done for you in the static routine and is called in a single line.

Let me know if this is an appropriate solution for you.  If so you may want to reopen the question for further discussion.

0
 

Author Comment

by:jerm
ID: 1166010
I guess the answer is that for each dialog, there must be a unique class associated with it.  Actually that make me feel better.  At least I know I am not going crazy when I keep failing at this venture.  I will try the suggestion posted by Ronslow.  I like the idea of a simple compact statement that displays a dialog and returns the values I need.

Thanks to all of you for your ideas again.

Until next time
jerm
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1166011
The autograder has struck again !!

Looks like my suggestion either didn't get tried, or didn't work, or jerm didn't bother to get back and award the points appropriately.

0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

762 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