Sign in to follow this  
DXnut

MFC class with 2 dialogs question

Recommended Posts

DXnut    262
I am writing a DirectX mesh modeling program. Since my main window is DirectX, I want a solution that does not require me to create another window to draw the DX stuff. I need to add new dialog(s) for the creation of animation sets. I would love to be able to only create one dialog for this, but cannot figure out if it is possible to basically create an "L" shaped dialog. The design is like other modeling programs (like Maya 7). I want a dialog on the bottom of the screen that will have a slider control for controlling the animation time and playback, and a dialog on the right of the screen that will control the creation of the key frames. The user will interact with the mesh in the DX window by selecting bones, and applying rotations, translations, scaling to them. So it needs to be visible. The problem is how to manage the two dialog classes. I call one AnimationVert and the other AnimationHor (vertical and horizontal). Both are derived from CDialog. I would like to have one class control the two dialogs and send messages back to the main window for different events from both dialogs. So, I thought of two possible solutions: 1) Make a parent class that is derived from the two dialog classes (which would also make it derived from CDialog). I am not sure I can do this though, since windows will be sending the various notification messages to the two dialog classes. But if I can do this, then I could have the two dialogs call functions in that parent class (like ParentClass::Handlethismsg() ). 2) I could make a parent class and declare it as a friend class in the two dialogs. Then they could do the same thing to call functions in the parent? My understanding of object oriented design with multiple inheritance with MFC is not good enough to figure this one out. Any ideas on this? Maybe there is a better way? Thanks!

Share this post


Link to post
Share on other sites
I don't understand what you exactly want but is seems to be a job for the observer design pattern.

Each time a variable is modifed in one of your control dialog, the rendering window is notified of the change. It means that your redering window have to inherit from the observer class.

One thing that will save you later: if an MFC class inherit from another abstract class (using multiple inheritance) then it must inherit from the MFC class first:


class CFoo : public CDialog, public CObserver
{
};
// instead of
class CFoo : public CObserver, public CDialog
{
};


This is because there is a nasty c-style cast in the MFC code that may break everything - IIRC VS.NET 2003 will warn you at compile time.

Regards,

Share this post


Link to post
Share on other sites
DXnut    262
Thanks. It occurred to me after that post, that I could try #1 and make all of the functions in each of the dialog classes virtual. Then I can over-ride them in the parent class, so that I can do all the actual work in that one class. The parent class is generic.

So far it is working!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this