1

我正在尝试向 SDI 应用程序添加多个(实际上是 3 个)视图,并让用户选择女巫视图将根据他的选择加载:

IMG

我在官方 MS 文档中遵循了本教程。因此,创建了三个类:CAdminView CAssistantView CBiblioView 和一个与对话框框架相关联的身份验证类。

我的问题是:

1)如何编辑这三个视图类(图形)?

2)第一次我想只显示身份验证对话框窗口,怎么做?

* I tried to change m_pMainWnd->ShowWindow(SW_SHOW);

  by m_pMainWnd->ShowWindow(SW_HIDE); but no expected result

3)我希望根据参数加载视图,这是我添加到 InitInstance 函数中的:

                CView* pActiveView = ((CFrameWnd*) m_pMainWnd)->GetActiveView();
                m_BiblioView = (CView*) new CBiblioView;
                m_AdminView = (CView*) new CAdminView;
                m_AssistantView = (CView*) new CAssistantView;
                CDocument* pCurrentDoc = ((CFrameWnd*)m_pMainWnd)->GetActiveDocument();

                // Initialize a CCreateContext to point to the active document.
                // With this context, the new view is added to the document
                // when the view is created in CView::OnCreate().
                CCreateContext newContext;
                newContext.m_pNewViewClass = NULL;
                newContext.m_pNewDocTemplate = NULL;
                newContext.m_pLastView = NULL;
                newContext.m_pCurrentFrame = NULL;
                newContext.m_pCurrentDoc = pCurrentDoc;

                // The ID of the initial active view is AFX_IDW_PANE_FIRST.
                // Incrementing this value by one for additional views works
                // in the standard document/view case but the technique cannot
                // be extended for the CSplitterWnd case.
                UINT viewID = AFX_IDW_PANE_FIRST + 1;
                CRect rect(0, 0, 0, 0); // Gets resized later.

                // Create the new view. In this example, the view persists for
                // the life of the application. The application automatically
                // deletes the view when the application is closed.
                m_AdminView->Create(NULL, "Fenetre Administrarteur", WS_CHILD, rect, m_pMainWnd, viewID, &newContext);
                m_AssistantView->Create(NULL, "Fenetre Assistant", WS_CHILD, rect, m_pMainWnd, viewID, &newContext);
                m_BiblioView->Create(NULL, "Fenetre Bibliothecaire ", WS_CHILD, rect, m_pMainWnd, viewID, &newContext);
                // When a document template creates a view, the WM_INITIALUPDATE
                // message is sent automatically. However, this code must
                // explicitly send the message, as follows.
                m_AdminView->SendMessage(WM_INITIALUPDATE, 0, 0);
                m_AssistantView->SendMessage(WM_INITIALUPDATE, 0, 0);
                m_BiblioView->SendMessage(WM_INITIALUPDATE, 0, 0);

这是我的开关功能:

CView* CMiniProjetApp::SwitchView(int Code ) //1 : Admi / 2 : Biblio / 3 : Assistant
{
   CView* pActiveView =((CFrameWnd*) m_pMainWnd)->GetActiveView();

   CView* pNewView= NULL;
   switch(Code){

   case 1 : pNewView= m_AdminView; break;
   case 2 : pNewView= m_BiblioView; break;
   case 3 : pNewView= m_AssistantView; break;
   }

   // Exchange view window IDs so RecalcLayout() works.
   #ifndef _WIN32
   UINT temp = ::GetWindowWord(pActiveView->m_hWnd, GWW_ID);
   ::SetWindowWord(pActiveView->m_hWnd, GWW_ID, ::GetWindowWord(pNewView->m_hWnd, GWW_ID));
   ::SetWindowWord(pNewView->m_hWnd, GWW_ID, temp);
   #else
   UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID);
   ::SetWindowLong(pActiveView->m_hWnd, GWL_ID, ::GetWindowLong(pNewView->m_hWnd, GWL_ID));
   ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);
   #endif

   pActiveView->ShowWindow(SW_HIDE);
   pNewView->ShowWindow(SW_SHOW);
   ((CFrameWnd*) m_pMainWnd)->SetActiveView(pNewView);
   ((CFrameWnd*) m_pMainWnd)->RecalcLayout();
   pNewView->Invalidate();
   return pActiveView;
}

任何错误通知??!!

*请帮我 !

谢谢 。

4

1 回答 1

0

显示和隐藏窗口是正确的方法。但是您也需要将视图设置为活动状态。您可以在此 MSDN 示例VSSWAP32中找到所需的工作代码。

文章中显示了切换和隐藏其他视图所需的代码。

于 2013-12-08T14:08:26.360 回答