简体   繁体   中英

MFC Project Combination: How to add a SDI application without document class to a MDI application?should I use child window?[MFC]

I'am now working with a MDI MFC app and want to add a console/command-line function to the app. The only function I want to take from QuickWin(see below) is to use its text area and the process function which captures input. If I can add it to a popup dialog or a dock bar, it will be great! And I got the src-code of a SDI Applization without Document Class like this( link:http://www.codeproject.com/.../QuickWin-... ):

My Question is: can I add the app into my MDI app, and how to deal with source or head files like: MainFrm.cpp/MainFrm.h and class like: CQuickWinApp/CQuickView?(If I can pop up a child window to implement the function, better:))

在此处输入图片说明

In QuickWin's mainframe, it has something to do with client area, which is difficule to deal with:

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
    // create splitter without views
    m_wndSplitter.CreateStatic(this, 2, 1);

    CCreateContext Context;
    Context.m_pNewViewClass = RUNTIME_CLASS(CQuickView);
    Context.m_pCurrentDoc = NULL;
    Context.m_pNewDocTemplate = NULL;
    Context.m_pLastView = NULL;
    Context.m_pCurrentFrame = this;

    // Create the Stdio QuickView
    m_pStdioView  = (CQuickView*)CreateView(&Context, AFX_IDW_PANE_FIRST);
    if (m_pStdioView == NULL)
    {
        TRACE("Failed to create QuickWin Stdio View\n");
        return FALSE;       // fail to create
    }

    // Create the Stderr QuickView
    m_pStderrView  = (CQuickView*)CreateView(&Context, AFX_IDW_PANE_FIRST);
    if (m_pStderrView == NULL)
    {
        TRACE("Failed to create QuickWin Stderr View\n");
        return FALSE;       // fail to create
    }
    m_pStderrView->SetReadOnly(TRUE);

    ShowSplitter(theApp.m_bShowSplitter);
    return TRUE;
}

in My MDI app:

The MDI app has 3 doctemplates:

//BCGPVisualStudioGUIDemo.cpp

m_pDocTemplateCpp = new CMultiDocTemplate(
    IDR_BCGDEVTYPE_CPP,
    RUNTIME_CLASS(CBCGPVisualStudioGUIDemoDoc),
    RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    RUNTIME_CLASS(CBCGPVisualStudioGUIDemoView));
AddDocTemplate (m_pDocTemplateCpp);

m_pDocTemplateWeb = new CMultiDocTemplate(
    IDR_BCGDEVTYPE_WEB,
    RUNTIME_CLASS(CBCGPVisualStudioGUIDemoDoc),
    RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    RUNTIME_CLASS(CBCGPVisualStudioGUIDemoView));
AddDocTemplate (m_pDocTemplateWeb);

m_pStartDocTemplate = new CMultiDocTemplate(
    IDR_BCGDEVTYPE0,
    RUNTIME_CLASS(CNetworkMapEditorDemoDoc),
    RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    RUNTIME_CLASS(CNetworkMapEditorDemoView));
AddDocTemplate(m_pStartDocTemplate);

The app also has some dock bars:

//MainFrm.cpp

    //------------------
    // Create config bar:
    //------------------    

if (!m_wndClassView.Create (_T("config"), this, CRect (0, 0, 200, 200),
        TRUE, 
        ID_VIEW_CLASS,
        WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
    {
        TRACE0("Failed to create Class View bar\n");
        return FALSE;      // fail to create
    }

    //------------------
    // Create output bar:
    //------------------

    if (!m_wndOutputView.Create (_T("output"), this, CRect (0, 0, 200, 100),
        TRUE, 
        ID_VIEW_OUTPUT,
        WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
    {
        TRACE0("Failed to create output bar\n");
        return FALSE;      // fail to create
    }

    //------------------
    // Create help bar:
    //------------------

    if (!m_wndDynamicHelpView.Create (_T("help"), this, CRect (0, 0, 200, 200),
        TRUE, 
        ID_VIEW_DYNAMICHELP,
        WS_CHILD | WS_VISIBLE | CBRS_RIGHT | CBRS_FLOAT_MULTI))
    {
        TRACE0("Failed to create Dynamic Help Bar\n");
        return FALSE;       // fail to create
    }

    //------------------
    // Create watch bar:
    //------------------

    if (!m_wndWatchBar.Create (_T("watch"), this, CRect (0, 0, 300, 100),
        TRUE, 
        ID_VIEW_WATCH,
        WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
    {
        TRACE0("Failed to create watch bar\n");
        return FALSE;      // fail to create
    }

    //------------------
    // Create property bar:
    //------------------

    if (!m_wndPropertiesBar.Create (_T("property"), this, CRect (0, 0, 300, 200),
        TRUE, 
        ID_VIEW_PROPERTIES,
        WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))
    {
        TRACE0("Failed to create Properties Bar\n");
        return FALSE;       // fail to create
    }

Can I add the QuickWin app's text function into my app's dock bar or into a doctemplate or just a popup window?

All you need to integrate the functionality of QuickWin into your application are 3 textboxes (one for stdin, stdout and stderr) and the following classes from the Quickwin project:

  • CRedirect
  • CRedir
  • CParamDlg (only optical fluff, not essential)

The CRedirect-class manages the creation of the new process as well as the redirection of stdin/stdout/stderr (in combination with CRedir).

You have to modify CRedir::OnChildWrite and -Started and -Terminate to fit your needs. These methods actually write the content to the view/textbox/whatever. It is helpful to look at CMainFrame::OnCopyData and CQuickView::Append on how this can be done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM