Link to home
Start Free TrialLog in
Avatar of jerm
jerm

asked on

Multiple dialogs one class

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?
Avatar of nietod
nietod

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.
Avatar of jerm

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

Avatar of jerm

ASKER

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
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.