Solved

Multiple dialogs one class

Posted on 1998-06-16
6
210 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 10

Expert Comment

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now