Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6945615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:27:33+00:00 2026-05-27T13:27:33+00:00

I have a SDI MFC application which CMainFrame class is derived from CFrameWndEx. The

  • 0

I have a SDI MFC application which CMainFrame class is derived from CFrameWndEx.
The app uses the CSingleDocument template for connecting Document/View/Frame.

I need to have another window with the contents of a View related to the same document of the view of the Main Window.
Is it correct to have another instance of the CMainFrame as a secondary window?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:27:34+00:00Added an answer on May 27, 2026 at 1:27 pm

    After some approaches I came to a solution:

    1st:

    Have two CMainFrame instances on the App, where the second has a boolean field to indicate it is one or other. This boolean allowed me to skip the creation of everthing creation only on the second, because I only want it to be a rectangle with the view. I’ve added a special public constructor that to CMainFrame that always puts the referred boolean to true.

        CMainFrame *pSecondFrame = new CMainFrame(TRUE /*dumb*/);
    

    It worked, but it was very slow. The view of the first MainFrame was completely unusable due to its lack of speed.

    2nd:

    Have a CSecondFrame that is also derived from CFrameWndEx and has almost nothing on its body. As IDR_MAINFRAME has nothing, I can expect to do LoadFrame(IDR_MAINFRAME) and have an almost empty frame on the App.

        CSecondFrame *pSecondFrame = new CSecondFrame();
    

    It worked, but it was very slow. The view of the first MainFrame was completely unusable due to its lack of speed.

    For both 1st and 2nd approaches, I had to add a new CreateContext, as I can not reuse the mainframe View:

    if (!pSecondFrame->LoadFrame(IDR_MAINFRAME))
        return FALSE;
    
    CMainFrame* pMainFrame=(CMainFrame*)::AfxGetMainWnd();
    if (!pMainFrame)
            return FALSE;
    
    CMyView* pView=(CMyView*)(pMainFrame->GetActiveView());
    if (!pView)
        return FALSE;
    
    CCreateContext context;
    
    context.m_pCurrentDoc=pMainFrame->GetActiveDocument();
    context.m_pNewViewClass= RUNTIME_CLASS(CMyView);
    context.m_pLastView= pView;
    context.m_pCurrentFrame = pSecondFrame;
    
    pSecondFrame->CreateView(&context);
    

    3rd:

    At the beginning of the InitInstance function I have the Document Template:

    So lets play with its CreateNewFrame method:
    POSITION pos= pDocTemplate->GetFirstDocPosition();

                //pFrameTemp attribution
    
        CFrameWnd* pSecondFrame= pDocTemplate->CreateNewFrame(pDocTemplate->GetNextDoc(pos),pFrameTemp);
    

    I tried different things for the pFrameTemp: NULL, a CMainFrame, CSecondFrame. Everytime I got a frame that is carbon-copy of the main and I dont’t want this.

    For the CMainFrame and CSecondFrame cases I tried to explicity call their Create( …) functions, which fail,so they don’t even pass on their OnCreate(…) method.
    Instead of this I also tried to do a LoadFrame(IDR_MAINFRAME) for both cases. Now I will have three frames: The Main, the Second, which is carbon-copy of the main, and the one created with LoadFrame, which is totally blank.

    4th:
    After seeing that he CreateNewFrame method creates a new Frame based on the frame it has on the template and not the one that is passed in its parameter, I decided to try create addicionally another template:

    CSingleDocTemplate* pSecondDocTemplate;
    pSecondDocTemplate2 = new CSingleDocTemplate(
        MenuID,
        RUNTIME_CLASS(CMyDoc),
        RUNTIME_CLASS(CSecondFrame),//only the frame differs
        RUNTIME_CLASS(CMyView));
    AddDocTemplate(pSecondDocTemplate);
    
    POSITION pos= pDocTemplate->GetFirstDocPosition();
    CFrameWnd* pSecondFrame=pSecondDocTemplate->CreateNewFrame(pDocTemplate->GetNextDoc(pos), NULL);
    

    Notice that I am giving the doc of the first template as parameter, not the second, to CreateNewFrame.
    This is the only solution I tested that works and doesn’t slow down operations in the view.

    It seems I need, for every solution I presented to do

     pSecondFrame->ShowWindow(SW_SHOW);
    

    for getting the window visible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a MFC SDI application, and the view is derived from CFormView,
I have an MFC sdi app that uses a splitter window to contain a
I have an SDI application written in MFC. The frame is divided into 1
I have a simple SDI app which works pretty well. Lately I decided to
I have a WTL 8.0 SDI application for Windows Mobile 5. In this contrived
I have tried to make the fullscreen feature of a SDI application with splitter
In a MFC SDI application containing a single CView , I pass the output
I have an MFC dialog application that I am using as the front end
In Single Document Interface (SDI) or Multiple Document Interface (MDI) MFC application, I created
I currently have an SDI application that is build with Delphi 7, I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.