Solved

Multiple dialogs one class

Posted on 1998-06-16
6
223 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
  • 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 30 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GUI: DIalog Stacking and Popping in MS C++ 4 81
How to convert MFC APP to Win32 APP. 19 93
Dialogbox API leak? 18 98
VS2015 Redefinition errors 4 68
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 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