C ++ MFC MDI更改子窗口变量创建时 [英] C++ MFC MDI change child window variables on creation

查看:1006
本文介绍了C ++ MFC MDI更改子窗口变量创建时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MDI应用程序,当 OnFileNew()函数(由 theApp 对象)被调用。这个对话框允许用户为某些变量设置值,然后需要传递给 - > CreateNewChild时创建的 CChildFrame 对象()

I have an MDI application where a dialog is called when the OnFileNew() function (processed by the theApp object) is called. This dialog allows the user to set values to some variables that then need to be passed on to the CChildFrame object that is created when the ->CreateNewChild() function is called.

如何将这些变量传递到 CChildFrame - > CreateNewChild()函数创建的对象?

How do I pass these variables onto the CChildFrame object that is created by the ->CreateNewChild() function?

编辑:
对于我得到的答案,下面是使用 - > Create() vs - > CreateNewChild()

链接: CMainFrame * pFrame; - pFrame-> CreateNewChild()

Link: CMainFrame *pFrame; - pFrame->CreateNewChild()

链接: CChildFrame * childFrame; - childFrame-> Create()

Link: CChildFrame *childFrame; - childFrame->Create()

推荐答案

如何获得第一个链接中显示的标签窗口?通过自定义文档模板传递数据。从CMultiDocTemplate派生类以添加其他数据成员,然后将指向您的派生文档模板类的指针添加到CWinApp派生的应用程序类中。

You can pass the data via a customized document template. Derive a class from CMultiDocTemplate to add additional data members, then add a pointer to your derived document template class to your CWinApp-derived app class. Initialize your document template in the usual way, except when you finish, save the new document template object to the pointer in your app class.

现在,在CreateNewChild函数中,改为使用新的文档模板对象调用CWinApp :: OnFileNew,可以从当前帧中获取数据,然后在保存在app类中的文档模板中分配给数据成员,然后调用OpenDocumentFile(NULL)。您可以在OpenDocumentFile返回时清除数据成员。

Now in your CreateNewChild function, instead of calling CWinApp::OnFileNew, you can just get the data from the current frame, then assign to the data member in the document template saved in the app class, before calling OpenDocumentFile(NULL). You can clear the data members when OpenDocumentFile returns.

文档模板将依次创建子框架并在创建上下文中传递文档模板。要在子框架中获取创建上下文,可以覆盖CChildFrame :: OnCreateClient,或者读取OnCreate中的创建结构:

The document template will in turn create the child frame and pass the doc template in the create context. To get the create context in the child frame, you can either override CChildFrame::OnCreateClient, or read the create structure in OnCreate:

MDICREATESTRUCT * pMDICreateStruct=(MDICREATESTRUCT * )lpCreateStruct->lpCreateParams;
CCreateContext *pCreateContext=(CCreateContext *)pMDICreateStruct->lParam;

您还可以将数据传递到新文档,而不是传递文档模板中的初始化数据。您将基本上从CMultiDocTemplate :: OpenDocumentFile复制代码,并添加代码以从主框架的活动文档获取初始化数据。

Instead of passing the initialization data in the document template, you could also pass data to the new document. You will basically copy the code from CMultiDocTemplate::OpenDocumentFile and add the code to get the initialization data from the active document of the main frame.

这篇关于C ++ MFC MDI更改子窗口变量创建时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆