Solved

Multiple dialogs one class

Posted on 1998-06-16
6
218 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

832 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