2013-12-08 31 views
1
添加多个浏览到VC++ 2010 SDI

我想多(实际上3)意见添加到SDI应用程序,给用户选择女巫视图将根据他的选择是负载:使用MFC

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)I期望根据参数加载视图,这是我加入的InitInstance funnction:

   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; 
} 

任何错误通知?? !!

*请帮帮我!

谢谢。

+0

写入16位Windows兼容代码的荣誉! – IInspectable

回答

0

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

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