MFC dialog window segmentation / resolution

  • This paper test environments vs2013!
  • Finally, operating results are as follows:


First, the new projects: Project name: MySplitterDlg, other keep the default option.
Second, create a dialog class
Each record type CMyFormView0 and CMyFormView1 , category group selected from the CDialog , must choose the CFormView .
Class Wizard -> Add Class (MFC category):


Third, the
increase WM_CREATE message response function OnCreate

By "Class Guide" "CMySpliterDlgDlg (not select a different class) add class message WM_CREATE response function:


Fourth, edit OnCreate

After adding a message function OnCreate, edit its contents as follows:

int CMySplitterDlgDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDialogEx::OnCreate(lpCreateStruct) == -1)
        return -1;

    // TODO:  在此添加您专用的创建代码
    // Because the CFRameWnd needs a window class, we will create a new one. I just copied the sample from MSDN Help.
    // When using it in your project, you may keep CS_VREDRAW and CS_HREDRAW and then throw the other three parameters.
    //需要注册窗口类
    CString strMyClass = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW, 
                   ::LoadCursor(NULL, IDC_ARROW),    (HBRUSH) ::GetStockObject(WHITE_BRUSH),  
                  ::LoadIcon(NULL, IDI_APPLICATION));

    The window with the Create Frame // "the this" The parent AS
    m_pMyFrame new new = the CFrameWnd;
    m_pMyFrame-> the Create (strMyClass, _T ( ""), the WS_CHILD, CRect (0,0,300,300), the this);
    m_pMyFrame-> the ShowWindow (SW_SHOW) ;

    // and the finally, with Splitter the Create the Frame the aS parent
    m_cSplitter.CreateStatic (m_pMyFrame,. 1, 2); // segmentation of the view window in Frame 1 × 2, row two is
    m_cSplitter.CreateView (0, 0, RUNTIME_CLASS (CMyFormView0), CSize (100,100), NULL); // a first row
    m_cSplitter.CreateView (0,1, RUNTIME_CLASS (CMyFormView1) , CSize (100,100), NULL); // first row two

    return 0;
}

Fifth, add variable CFrameWnd    

Variables used in the above procedure m_pMyFrame, it is necessary to add the class CMySplitterDlgDlg

public:
         CFrameWnd *m_pMyFrame;

Six, in order to prevent memory leaks, add onDestroy () in

if (m_pMyFrame) delete m_pMyFrame;

Seven, add headers Dialog 

Further, the above procedure is also used class CMyFormView0 3.3 Summary and created CMyFormView1, it is necessary to add it in the header file MySplitterDlgDlg.cpp.

#include "MyFormView0.h"
#include "MyFormView1.h"

Eight, add variable CSplitterWnd

When the use of the window is divided into CSplitterWnd class (see above OnCreate function), it is necessary to add the class CMySplitterDlgDlg

CSplitterWnd m_cSplitter;

Nine, news editor OnSize

Added message function after OnSize, editing its contents as follows:

:: CMySplitterDlgDlg the OnSize void (UINT nType, int CX, CY int)
{
    CDialogEx the OnSize :: (nType, CX, CY);

    // the TODO: Add message handler code here
    CRect CRect;
    the GetWindowRect (& CRect);
    while ScreenToClient ( CRect &);
    m_pMyFrame-> the MoveWindow (& CRect);
    m_pMyFrame-> the ShowWindow (SW_SHOW);
}

Ten, run the program



Published 117 original articles · won praise 4 · views 80000 +

Guess you like

Origin blog.csdn.net/qq_36266449/article/details/78194665