(急)如何在一个单文档视图上点击一个单词能响应一个消息??? 当在一个单文档视图上点击一个单词时,可以改变当前视图的内容如:当点击视图上的View One!!!之后视图变为View Two!!!象网页的那种形式,不知如何实现,请求高手指教。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你最好把你的view One 做成一个按纽 单能不能不做成button呀,我需要仅是文字 Adding Multiple Views to a Single DocumentSee AlsoDocument/View ArchitectureIn a single-document interface (SDI) application created with the Microsoft Foundation Class (MFC) Library, each document type is associated with a single view type. In some cases, it is desirable to have the ability to switch the current view of a document with a new view.Tip For additional procedures on implementing multiple views for a single document, see CDocument::AddView and the following MFC samples: ENROLL and COLLECT.You can implement this functionality by adding a new CView-derived class and additional code for switching the views dynamically to an existing MFC application.The steps are as follows:Modify the Existing Application ClassCreate and Modify the New View ClassCreate and Attach the New ViewImplement the Switching FunctionAdd Support for Switching the ViewThe remainder of this topic assumes the following:The name of the CWinApp-derived object is CMyWinApp, and CMyWinApp is declared and defined in MYWINAPP.H and MYWINAPP.CPP.CNewView is the name of the new CView-derived object, and CNewView is declared and defined in NEWVIEW.H and NEWVIEW.CPP.Modify the Existing Application ClassFor the application to switch between views, you need to modify the application class by adding member variables to store the views and a method to switch them.Add the following code to the declaration of CMyWinApp in MYWINAPP.H:CView* m_pOldView;CView* m_pNewView;CView* SwitchView( );The new member variables, m_pOldView and m_pNewView, point to the current view and the newly created one. The new method (SwitchView) switches the views when requested by the user. The body of the method is discussed later in this topic in Implement the Switching Function.The last modification to the application class requires including a new header file that defines a Windows message (WM_INITIALUPDATE) that is used in the switching function.Insert the following line in the include section of MYWINAPP.CPP:#include <AFXPRIV.H>Save your changes and continue to the next step.Create and Modify the New View ClassCreating the new view class is made easy by using the New Class command available from Class View. The only requirement for this class is that it derives from CView. Add this new class to the application. For specific information on adding a new class to the project, see Adding a Class.Once you have added the class to the project, you need to change the accessibility of some view class members.Modify NEWVIEW.H by changing the access specifier from protected to public for the constructor and destructor. This allows the class to be created and destroyed dynamically and to modify the view appearance before it is visible.Save your changes and continue to the next step.Create and Attach the New ViewTo create and attach the new view, you need to modify the InitInstance function of your application class. The modification adds new code that creates a new view object and then initializes both m_pOldView and m_pNewView with the two existing view objects.Because the new view is created within the InitInstance function, both the new and existing views persist for the lifetime of the application. However, the application could just as easily create the new view dynamically.Insert this code after the call to ProcessShellCommand:...CView* pActiveView = ((CFrameWnd*) m_pMainWnd)->GetActiveView();m_pOldView = pActiveView;m_pNewView = (CView*) new CNewView;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_pNewView->Create(NULL, "AnyWindowName", 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_pNewView->SendMessage(WM_INITIALUPDATE, 0, 0);...Save your changes and continue to the next step.Implement the Switching FunctionIn the previous step, you added code that created and initialized a new view object. The last major piece is to implement the switching method, SwitchView.At the end of the implementation file for your application class (MYWINAPP.CPP), add the following method definition:CView* CMyWinApp::SwitchView( ){CView* pActiveView =((CFrameWnd*) m_pMainWnd)->GetActiveView();CView* pNewView= NULL;if(pActiveView == m_pOldView)pNewView= m_pNewView;elsepNewView= m_pOldView;// Exchange view window IDs so RecalcLayout() works.#ifndef _WIN32UINT 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);#elseUINT 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);#endifpActiveView->ShowWindow(SW_HIDE);pNewView->ShowWindow(SW_SHOW);((CFrameWnd*) m_pMainWnd)->SetActiveView(pNewView);((CFrameWnd*) m_pMainWnd)->RecalcLayout();pNewView->Invalidate();return pActiveView;}Save your changes and continue to the next step.Add Support for Switching the ViewThe final step involves adding code that calls the SwitchView method when the application needs to switch between views. This can be done in several ways: by either adding a new menu item for the user to choose or switching the views internally when certain conditions are met.For more information on adding new menu items and command handler functions, see Handlers for Commands and Control Notifications.See AlsoDocument/View Architecture--------------------------------------------------------------------------------Send feedback to Microsoft© 2001 Microsoft Corporation. All rights reserved. 如有源程序,希望能发给我Email:[email protected] CBCGPGridView是如何实现打印的? MFC读写txt中的变量 打开DICOM图片 郁闷~关掉一个对话框,其上级对话框也跟着消失了,程序就死了?? Java虚拟机与浏览器的关系? 在底层键盘钩子WH_KEYBOARD_LL的钩子过程中怎样检测CTL+ALT+DEL组合键,大送分 windows应用程序的菜单竟然能通过xml文件配置! 如何实现DLL调用DLL? 输入问题? 请问能否保护可执行程序不被修改,如被修改则不执行或退出 请问如何在 Dialog 中,动态加载图片控件? 这个宏是什么意思?
Adding Multiple Views to a Single DocumentSee Also
Document/View Architecture
In a single-document interface (SDI) application created with the Microsoft Foundation Class (MFC) Library, each document type is associated with a single view type. In some cases, it is desirable to have the ability to switch the current view of a document with a new view.Tip For additional procedures on implementing multiple views for a single document, see CDocument::AddView and the following MFC samples: ENROLL and COLLECT.
You can implement this functionality by adding a new CView-derived class and additional code for switching the views dynamically to an existing MFC application.The steps are as follows:Modify the Existing Application Class
Create and Modify the New View Class
Create and Attach the New View
Implement the Switching Function
Add Support for Switching the View
The remainder of this topic assumes the following:The name of the CWinApp-derived object is CMyWinApp, and CMyWinApp is declared and defined in MYWINAPP.H and MYWINAPP.CPP.
CNewView is the name of the new CView-derived object, and CNewView is declared and defined in NEWVIEW.H and NEWVIEW.CPP.
Modify the Existing Application Class
For the application to switch between views, you need to modify the application class by adding member variables to store the views and a method to switch them.Add the following code to the declaration of CMyWinApp in MYWINAPP.H:CView* m_pOldView;
CView* m_pNewView;
CView* SwitchView( );
The new member variables, m_pOldView and m_pNewView, point to the current view and the newly created one. The new method (SwitchView) switches the views when requested by the user. The body of the method is discussed later in this topic in Implement the Switching Function.The last modification to the application class requires including a new header file that defines a Windows message (WM_INITIALUPDATE) that is used in the switching function.Insert the following line in the include section of MYWINAPP.CPP:#include <AFXPRIV.H>
Save your changes and continue to the next step.Create and Modify the New View Class
Creating the new view class is made easy by using the New Class command available from Class View. The only requirement for this class is that it derives from CView. Add this new class to the application. For specific information on adding a new class to the project, see Adding a Class.Once you have added the class to the project, you need to change the accessibility of some view class members.Modify NEWVIEW.H by changing the access specifier from protected to public for the constructor and destructor. This allows the class to be created and destroyed dynamically and to modify the view appearance before it is visible.Save your changes and continue to the next step.Create and Attach the New View
To create and attach the new view, you need to modify the InitInstance function of your application class. The modification adds new code that creates a new view object and then initializes both m_pOldView and m_pNewView with the two existing view objects.Because the new view is created within the InitInstance function, both the new and existing views persist for the lifetime of the application. However, the application could just as easily create the new view dynamically.Insert this code after the call to ProcessShellCommand:...
CView* pActiveView = ((CFrameWnd*) m_pMainWnd)->GetActiveView();
m_pOldView = pActiveView;
m_pNewView = (CView*) new CNewView;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_pNewView->Create(NULL, "AnyWindowName", 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_pNewView->SendMessage(WM_INITIALUPDATE, 0, 0);
...
Save your changes and continue to the next step.Implement the Switching Function
In the previous step, you added code that created and initialized a new view object. The last major piece is to implement the switching method, SwitchView.At the end of the implementation file for your application class (MYWINAPP.CPP), add the following method definition:CView* CMyWinApp::SwitchView( )
{
CView* pActiveView =
((CFrameWnd*) m_pMainWnd)->GetActiveView();CView* pNewView= NULL;
if(pActiveView == m_pOldView)
pNewView= m_pNewView;
else
pNewView= m_pOldView;// 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);
#endifpActiveView->ShowWindow(SW_HIDE);
pNewView->ShowWindow(SW_SHOW);
((CFrameWnd*) m_pMainWnd)->SetActiveView(pNewView);
((CFrameWnd*) m_pMainWnd)->RecalcLayout();
pNewView->Invalidate();
return pActiveView;
}
Save your changes and continue to the next step.Add Support for Switching the View
The final step involves adding code that calls the SwitchView method when the application needs to switch between views. This can be done in several ways: by either adding a new menu item for the user to choose or switching the views internally when certain conditions are met.For more information on adding new menu items and command handler functions, see Handlers for Commands and Control Notifications.See Also
Document/View Architecture--------------------------------------------------------------------------------Send feedback to Microsoft© 2001 Microsoft Corporation. All rights reserved.
Email:[email protected]