Sign in to follow this  

MFC question

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm learning MFC and am getting the hang of it. But there is one question I can't seem to solve. From the book I'm reading, the applications they create are very simple. I'm building applications without Appwizard. I have a CMainWindow containing a CChildWindow (where everything is rendered). I would like to know how to render different screens to the CChildWindow. For example, when user clicks a button, I want the app to show a couple buttons/edit boxes/list boxes to allow him to enter information. Then when he clicks another button, I want that stuff to disappear and instead show something else, like a picture or a chart, etc. Then when he clicks the first button again, I want the old stuff to show up again. I have been thinking about this and came up with two solutions: 1) Create states in my program and depending on the state, have p_mMnWnd point to the the appropriate CWnd* window. 2) Again, have states and redraw the window depending on the states. Both seem very inefficient. I've looked all over for more info and I'd appreciate any advice. Thanks.

Share this post


Link to post
Share on other sites
Have two CChildWindow-derived classes, one with edit/buttons, the other with pictures or whatever. Switch the CChildWinodw to the appropriate one.

Other possibility if you're forced to use only one CChildWindow: Do basically the same as above, but have two CDialog-derived classes which you insert into the CChildWindow.

Share this post


Link to post
Share on other sites
Thanks for the reply!

I suspected that's how you'd do it. But I'm still lost as to how to implement it. I create my child window in my CMainWindow constructor (similar to the OnCreate function in AppWizard). That is where I "attach" it to my CMainWindow. I don't see how I can switch between child windows in other parts of my code. Would I have to destroy one child window and create another one (using the Create function)? Or is there a function that allows you to do the switching?

Thank you

Share this post


Link to post
Share on other sites
Creating and destroying windows is a waste of cycles if you're just going to bring it up again. You can flip between windows easily using ShowWindow (for on/off) or SetWindowPos (for layer order).

You can create as many windows as you want as children of your main window. After all, controls are also windows when you get down to the bottom of it in MFC. It is, of course, up to you to keep track in your controlling window of which window is visible and what you're going to do when you click the button.

-fel

Share this post


Link to post
Share on other sites

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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