mfc >> CDialog design question

by Robben Mario » Tue, 27 Apr 2004 01:56:28 GMT

I've a small design question.

Suppose I want to create a dialog: CPersonDlg derived from CDialog. This
dialog allows the user to enter a name of a person (of course, in the real
world there is a lot more than the name alone). Using the resource editor, I
create a dialog with a static label ("Name") and an edit control
(IDC_NAME_EDIT) that contains the name of the person. Then, using the class
wizard, I add a member variable that is linked to the edit control (CString
m_strName). The DoDataExchange method contains a piece of code that the name
is correct (e.i. the name must not be empty).

OK, at this point I've a fully working CPersonDlg that is not coupled to any
other class, view or document. My problem is the next. Suppose, my
application keeps a list of certain persons. The user can enter a new person
(using the CPersonDlg dialog class). But, suppose that the user enters a
name that already exists. Should I extend my dialog (adding some extra code
in the DoDataExchange method) so that it checks that the name must is
unique, or should I do this validation outside the dialog. If I extend my
dialog class, CPersonDlg is tightly coupled to a document class (it's not
reusable). Maybe I should derive from CPersonDlg whose purpose is to do
extra validation using the CDocument class.

What do you think guys (and girlz). Is there a good solution for my "little"

mfc >> CDialog design question

by David Crow [MCSD] » Tue, 27 Apr 2004 02:34:21 GMT

Maybe your CPersonDlg class/dialog doesn't care about duplicates. In that
case, the owner of the CPersonDlg objects checks for duplicates once the OK
button has been clicked. On the other hand, if you checked for duplicates
before the OK button was, or even allowed to be, clicked, this makes the
CPersonDlg class/dialog less generic.


Similar Threads

1. class design/ design pattern question

2. Class Design Was: Object Design Question

On Dec 25, 5:18 pm, "JoeC" < XXXX@XXXXX.COM > wrote:
> I have a question about designing objects and programming.  What is the
> best way to design objects?  Create objects debug them and later if you
> need some new features just use inhereitance.  Often times when I
> program, I will create objects for a specific purpose for a program and
> if I need to add to it I just add the code.

And there is nothing much wrong with 'just adding the 'behaviour' to an
existing class.


That class is used by other teams, is an API, is used lotsof times
throughout your large code base(i.e. causing a massive recompile),

What you might want to try, is creating a new Class instead of just
adding to an existing one - this usually results in a very flexible

I would also favour Delegation over Inheritance.

Delegation is a Dynamic relationship between 2 objects, whereas
Inheritance is a static compile time relationship.  Static
relationships tend to make designs more inflexible.

my 2c



3. CDialog/CPropertyPage inside CDialog - Help!

4. Changing an MFC CDialog to a control inside another CDialog

Hi everyone,
In my MFC application i have a CDialog window which is shown (modal)
when clicking on a specific button. After some changes in my
application, I decided that I need the controls on that secondary
CDialog to be shown always inside the main window.
Is there a way to change the secondary CDialog derived window to a
control (like CStatic, etc) inside my main window, and not a child
Maybe changing the devired class (CDialog to CStatic)? or changing some
properties in the CDialog and calling its Create method with a specific


5. CDialog Simple Question

6. CDialog question

I have an application that is created using the CDialog 
DoModal. It establishes an ftp connection and upload files 
to a server. The problem that I seem to have is that the 
window has to have focus in order to upload the files. 
Being fairly unfamilar with this I need to figure out how 
to make sure that this process continues even if the 
window no longer has focus. Any suggestion or help is 
greatly appreciated.

Thanks in advance,

7. Question on CDialog and OnInitDialog

8. Neophyte question regarding CDialog

I have an app whose main window is created using a class derived from 
CDialog.  I want the user to be able to run the app in UI mode and in batch 
mode.  In UI mode, the dialog is displayed normally using DoModal.  In batch 
mode, I would like to still create the dialog but make it hidden.  I plan to 
issue WM_COMMAND messages to the dialog to invoke various functions already 
implemented by the app.

My problem right now is with hiding the dialog.  How can I make the dialog 
hidden before it ever gets displayed?  I looked at CWnd::PreCreateWindow but 
found out that it does not get called for CDialog-derived objects.  Calling 
CWnd::ShowWindow using SW_HIDE or CWnd::ModifyStyle using WS_VISIBLE within 
OnInitDialog proved equally ineffective.

Obviously, I can hide the window from another thread but that is cheesy 
since the user will see the dialog flash before him.