简体   繁体   English

C ++ MFC MDI在创建时更改子窗口变量

[英]C++ MFC MDI change child window variables on creation

I have an MDI application where a dialog is called when the OnFileNew() function (processed by the theApp object) is called. 我有一个MDI应用程序,其中在调用OnFileNew()函数(由theApp对象处理OnFileNew()时会调用一个对话框。 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. 该对话框允许用户为某些变量设置值,然后将这些值传递给调用->CreateNewChild()函数时创建的CChildFrame对象。

How do I pass these variables onto the CChildFrame object that is created by the ->CreateNewChild() function? 如何将这些变量传递到由->CreateNewChild()函数创建的CChildFrame对象上?

EDIT: In response to an answer I got, here are the results for using ->Create() vs ->CreateNewChild() . 编辑:作为对我的回答,这是使用->Create() vs- ->CreateNewChild()

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

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

How do I get the tabbed windows shown in the first link with the function declarations described in the second link? 如何获得第一个链接中显示的选项卡式窗口以及第二个链接中描述的函数声明?

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. 从CMultiDocTemplate派生一个类以添加其他数据成员,然后将指向派生文档模板类的指针添加到CWinApp派生的应用程序类。 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. 除完成操作外,以通常的方式初始化文档模板,将新文档模板对象保存到应用程序类中的指针。

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). 现在,在CreateNewChild函数中,不必调用CWinApp :: OnFileNew,而只需从当前帧获取数据,然后在调用OpenDocumentFile(NULL)之前将其分配给应用程序类中保存的文档模板中的数据成员。 You can clear the data members when OpenDocumentFile returns. 您可以在OpenDocumentFile返回时清除数据成员。

The document template will in turn create the child frame and pass the doc template in the create context. 文档模板将依次创建子框架,并在创建上下文中传递doc模板。 To get the create context in the child frame, you can either override CChildFrame::OnCreateClient, or read the create structure in OnCreate: 要在子框架中获取创建上下文,可以覆盖CChildFrame :: OnCreateClient或在OnCreate中读取创建结构:

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

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. 基本上,您将从CMultiDocTemplate :: OpenDocumentFile复制代码,并添加代码以从主框架的活动文档中获取初始化数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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