MFC question

Started by
2 comments, last by felisandria 19 years, 8 months ago
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.
I'm a newbie, please don't hurt me!
Advertisement
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

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
I'm a newbie, please don't hurt me!
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
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~

This topic is closed to new replies.

Advertisement