Tim
Tim

Reputation: 20360

How do I display a CFormView in a mainframe?

I created an SDI MFC app without the doc/view support. The MFC template gives me an app with a blank window (And a menu, etc)

I want to show my CFormView object on that main window. (Based on a dlg made in the gui editor)

How do I do that? CreateWindow and showwindow don't seem to be all that is needed. All the web pages I find seem to talk about MDI and other stuff that is not in my app.

Upvotes: 0

Views: 2556

Answers (1)

John Knoeller
John Knoeller

Reputation: 34148

  • Give your CFormView the WS_CHILD style
  • Create it as a MODELESS dialog with the app window as the parent window
  • resize it to fit the parent's client area, or resize the parent to fit it.

The WS_CHILD style is not a default style for a dialog template, but you can add it. this will cause the dialog to show up inside the client area of the main frame window you when create it.

You may also want to add a call to IsDialogMessage() to your message pump. This is needed get the TAB key to behave the way you expect it do in a dialog.

Edit ---- I'm not an MFC programmer, so I can only guess how you would go about this in MFC.

Presumably you still have dialog templates, so you would go into your .RC file and remove the WS_POPUP and add the WS_CHILD style to your template declaration. like this:

IDD_WHATEVER DIALOG DISCARDABLE  0, 0, 275, 217
STYLE DS_MODALFRAME | DS_3DLOOK | WS_CHILD | WS_VISIBLE
CAPTION "General"
FONT 8, "MS Sans Serif"
BEGIN
   // etc
END

Modeless dialogs are created in Win32 by using CreateDialog rather than DialogBox, in MFC by using Create() rather than DoModal().

Upvotes: 1

Related Questions