Search code examples
mfccdialogcview

CDialog to CView


So I've an MFC based application, which is primarily derived from CDialog, with some controls etc.

For certain reasons, it needs to be hosted in another application, using a container class, which is based on CView.

So there has to be some way...of hosting this thing, made using CDialog, inside a container class, which expects the thing as a CView.

The container class is closed to me. It will expect a CView, but I can modify the dialog based application.

Is there an easy way to migrate over from CDialog based to CView based, and what would I need to look at, please. I'm not very skilled with MFC, and the question might sound vague, but it's what I have.

Any help would be appreciated...Thanks.


Solution

  • You can use a CFormView. That is a view supporting dialog resource templates.

    The problematic code is loading and commiting the data into and from the CFormView. Views are usually controlled by a CDocument, that calls UpdateAllViews with some hints.

    Your dialog functions for OnOK, OnCancel and OnInitDalog must be changed to fit into the Doc/View architecture.

    • Move the OnInitDialog code into OnInitialUpdate, but be aware that in an SDI application OnInitialUpdate might be called more than once.
    • OnOK and OnCancel must be solved by some calls and functions from the document.