代码如下:
void CMainFrame::CreateNewWindow()
{
CMDIChildWnd* pActiveChild = MDIGetActive();
CDocument* pDocument;
if (pActiveChild == NULL ||
(pDocument = pActiveChild->GetActiveDocument()) == NULL)
{
TRACE0("Warning: No active document for WindowNew command.\n");
AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
return; // command failed
} // otherwise we have a new frame !
CDocTemplate* pTemplate = pDocument->GetDocTemplate();
ASSERT_VALID(pTemplate);
CFrameWnd* pFrame = pTemplate->CreateNewFrame(pDocument, pActiveChild);
if (pFrame == NULL)
{
TRACE0("Warning: failed to create new frame.\n");
return; // command failed
} pTemplate->InitialUpdateFrame(pFrame, pDocument);
}
现在我直接调用该函数没有问题,可以如新建窗口命令创建新的子窗口;
我想让它在程序运行时创建新的子窗口(可能是多个),但是MDIGetActive函数得到的pActiveChild指针值为NULL,请问各位大哥如何解决这个问题?
void CMainFrame::CreateNewWindow()
{
CMDIChildWnd* pActiveChild = MDIGetActive();
CDocument* pDocument;
if (pActiveChild == NULL ||
(pDocument = pActiveChild->GetActiveDocument()) == NULL)
{
TRACE0("Warning: No active document for WindowNew command.\n");
AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
return; // command failed
} // otherwise we have a new frame !
CDocTemplate* pTemplate = pDocument->GetDocTemplate();
ASSERT_VALID(pTemplate);
CFrameWnd* pFrame = pTemplate->CreateNewFrame(pDocument, pActiveChild);
if (pFrame == NULL)
{
TRACE0("Warning: failed to create new frame.\n");
return; // command failed
} pTemplate->InitialUpdateFrame(pFrame, pDocument);
}
现在我直接调用该函数没有问题,可以如新建窗口命令创建新的子窗口;
我想让它在程序运行时创建新的子窗口(可能是多个),但是MDIGetActive函数得到的pActiveChild指针值为NULL,请问各位大哥如何解决这个问题?
int DocLen = 3;
pDocTemplate->CloseAllDocuments(TRUE);CString strTitle = "标题";
Cex5View *pView = NULL;
POSITION posView;
CDocument* pDoc;for(int i = DocLen-1; i>=0; i--)
{
pDoc = pDocTemplate->OpenDocumentFile(NULL);
pDoc->SetTitle(strTitle);
posView = pDoc->GetFirstViewPosition();
while(posView != NULL)
{
pView = (Cex5View *)(pDoc->GetNextView(posView));
if(pView->IsKindOf(RUNTIME_CLASS(Cex5View)))
{
HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);// 设置图标
pView->GetParentFrame()->SetIcon(hIcon, FALSE);
pView->OnInitialUpdate();
}
}
}