VC Design Segmentation View General Creation Framework

xiaoxiao2021-04-08  374

At present, the application development of the split view is very popular, and the split view technology is a technology that displays multiple views simultaneously under the same frame window. Using a split view, you can give users more information amounts in a short time, so that the user interface is more friendly, enhancing the operability of the software. This article proposes a generic creation framework for split views.

1. Segment view creation framework

The creation of the split view is generally divided into two steps: one is to create a split form; then handle messages such as mouse and keyboard.

1) Create a split form

The MFC provides segmentation form class CSPLitterWnd, which provides a lot of members functions for split form operations, each divided form being a CSPLitterWnd object. The framework proposed in this paper is to inherit a sub-class cfixSplitterWnd from CSPLitterWnd from CSPLitterWnd, then each split form is a CFIXSPLITTERWD object, so it only needs to be rewritten after CfixSplitterWnd will be enhanced. Segment the function of the form. (This rewrite will be put forward later)

The most important function of creating a split form is the oncreateclient function of the main frame class, which will call when you created in the main frame, this article will create a split form displayed as follows:

figure 1

It can be implemented as follows:

// member variable declaration CFixSplitterWnd m_wndSplitterH; // for laterally cutting CFixSplitterWnd m_wndSplitterV; // for longitudinal cutting BOOL m_bCreateSplitter; // implementation of split form BOOL CMainFrame :: OnCreateClient (LPCREATESTRUCT lpcs, CCreateContext * pContext) {// for mixing the entire main frame segmented view BOOL bResult = m_wndSplitterV.CreateStatic (this, 1,2); ASSERT (bResult); m_wndSplitterH.CreateStatic (& m_wndSplitterV, 4,1, WS_CHILD | WS_VISIBLE, m_wndSplitterV.IdFromRowCol (0,1)); // create corresponding to each sub-window view m_wndSplitterV.CreateView sheets (0,0, RUNTIME_CLASS (CSceneView), CSize (600,600), pContext); m_wndSplitterH.CreateView (0,0, RUNTIME_CLASS (CPitchView), CSize (100,100), pContext); m_wndSplitterH.CreateView (1,0, RUNTIME_CLASS (CYawView), CSize (100,100), pContext); m_wndSplitterH.CreateView (2,0, RUNTIME_CLASS (CRollView), CSize (100,100), pContext); m_wndSplitterH.CreateView (3 , 0, runtime_class (ccontrolview), CSIZE (100, 100), PCONText); // Setting the initial size of the pane M_WndSplitterv.setrowinfo (0, Ideal_RawHeight, 0); m_bcreatesplitter = true; // Activation SceneView makes it accept command message m_wndsplitterv.setactivepane (0, 0, null); Return BRESULT;} // Main frame form size changes, adjust the corresponding form size VOID CMA inFrame :: OnSize (UINT nType, int cx, int cy) {CMDIFrameWnd :: OnSize (nType, cx, cy); CRect rect; GetClientRect (rect); if (m_bCreateSplitter) {m_wndSplitterV.SetColumnInfo (0, rect.Width ( ) * 3/4, 10); m_wndsplitterv.setColumnInfo (1, Rect.width () * 1/4, 10); m_wndsplitterh.setrowinfo (0, Rect.Height () / 6, 10) ;m_Wndsplitterh.setrowinfo (1 Rect.height () / 6, 10); m_wndsplitterh.setrowinfo (2, Rect.Height () / 6, 10) ;m_wndsplitterh.setrowinfo (3 ,Rect.height()/2, 10 ); }m_wndsplitterv.reclayout (); m_wndsplitterh.RecLayout ();} Note the second parameter in m_wndsplitterh.createView, this parameter corresponds to the split form and the corresponding view class.

The segmentation form shown in Figure 1 can be created by the program code described above, and since each segmentation form is a cfixSplitterWnd object, you can complete your own specific application by rewriting the virtual function or message processing function of the cfixSplitterWnd class. achieve. (Note that if you need a split form that customs specific properties, you must derive your own split form category and cannot be MFC's CSPLitterWnd class.) Here we need to split the form to change its size with the mouse, all The size of the pane is certain and cannot be changed at runtime. So you must add the following code in the implementation of the CFixSplitterWnd class: void cfixsplitterWnd :: OnMousemove (uint nflags, cpoint point) {cwnd :: onmousemove (nflags, points); // Prevent the mouse drag shape // csplitterWnd :: ONMOMOVE NFLAGS, POINT; // The mouse will drag the shape in the form boundary.

At this point, the segmentation form has been created, and the message needs to be processed in the split form.

2) Split Form Processing Message

Handling messages in a split form and a general document view model processing message is approximately the same, but it also has its own special. Specifically, since each segmentation form has been associated with the specific view class, it is possible to proceed directly to the corresponding view class when the message needs to be processed in each segmentation form; in addition, between the multi-view Switching results in changes between target focus, which affects execution of commands related to the view in the menu. For example, in the segmentation form shown in Figure 1, there is a "start" command must be a focus to execute when the CSCENEVIEW view is executed, otherwise the command should not be executed (ie the menu is gray), it can be implemented First click on the mouse, determine if it is within the csceneview view, if it is, it is allowed, otherwise it is not allowed.

2. in conclusion

Creating a framework through the split view proposed in this article, you can meet the needs of complex control of the view, I hope this article can give you a sense of inspiration, so you can create a more perfect split view application.

转载请注明原文地址:https://www.9cbs.com/read-132779.html

New Post(0)