📄 splitframe.cpp
字号:
// SplitFrame.cpp : implementation file
//
#include "stdafx.h"
#include "ResizeSplitter.h"
#include "SplitFrame.h"
#include "DrawDoc.h"
#include "DrawView.h"
#include "DrawFormView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSplitFrame
IMPLEMENT_DYNCREATE(CSplitFrame, CMDIChildWnd)
CSplitFrame::CSplitFrame()
{
}
CSplitFrame::~CSplitFrame()
{
}
BOOL CSplitFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
{
CRect rect;
GetClientRect( &rect );
CSize size = rect.Size();
size.cx /= 2; // Initial column size
size.cy /= 2; // Initial row size
// 1 - Create first static splitter
if( !m_wndSplitter1.CreateStatic( this, 1, 2 ) ) // 1 row, 2 cols
{
TRACE0( "Failed to create first static splitter\n" );
return FALSE;
}
// 2 - Create left column view
if( !m_wndSplitter1.CreateView( 0, 0, // row 0, col 0
RUNTIME_CLASS( CDrawFormView ),
size, pContext ) )
{
TRACE0( "Failed to create left view\n" );
return FALSE;
}
// 3 - Create nested static splitter
if( !m_wndSplitter2.CreateStatic( &m_wndSplitter1, 2, 1, // 2 rows, 1 col
WS_CHILD | WS_VISIBLE,
m_wndSplitter1.IdFromRowCol( 0, 1 ) ) )
{
TRACE0( "Failed to create nested static splitter\n" );
return FALSE;
}
// 4 - Create top-right view
if( !m_wndSplitter2.CreateView( 0, 0, // row 0, col 0
RUNTIME_CLASS( CDrawView ),
size, pContext ) )
{
TRACE0( "Failed to create top-right view\n" );
return FALSE;
}
// 5 - Create bottom-right view
if( !m_wndSplitter2.CreateView( 1, 0, // row 1, col 0
RUNTIME_CLASS( CDrawView ),
size, pContext ) )
{
TRACE0( "Failed to create bottom-right view\n" );
return FALSE;
}
return TRUE;
}
BEGIN_MESSAGE_MAP(CSplitFrame, CMDIChildWnd)
//{{AFX_MSG_MAP(CSplitFrame)
ON_WM_SIZE()
ON_COMMAND(ID_RESIZE_SPLITTERS, OnResizeSplitters)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSplitFrame message handlers
void CSplitFrame::OnSize(UINT nType, int cx, int cy)
{
CMDIChildWnd::OnSize(nType, cx, cy);
OnResizeSplitters();
}
void CSplitFrame::OnResizeSplitters()
{
// Sanity check -- avoids exception because we receive
// the first WM_SIZE before the splitter windows are created
HWND hWnd1 = m_wndSplitter1.GetSafeHwnd();
HWND hWnd2 = m_wndSplitter2.GetSafeHwnd();
if( hWnd1 == NULL || !::IsWindow( hWnd1 ) ||
hWnd2 == NULL || !::IsWindow( hWnd2 ) )
{
return;
}
// 1 - Get the current client size for our entire frame window
CRect rect;
GetClientRect( &rect );
// 2 - Calculate the ideal row and column sizes
CSize size = rect.Size();
size.cx /= 2; // Ideal column size
size.cy /= 2; // Ideal row size
// 3 - Resize each column of the first splitter
int cxCur, cxMin;
m_wndSplitter1.GetColumnInfo( 0, cxCur, cxMin );
m_wndSplitter1.SetColumnInfo( 0, size.cx, cxMin );
m_wndSplitter1.GetColumnInfo( 1, cxCur, cxMin );
m_wndSplitter1.SetColumnInfo( 1, size.cx, cxMin );
// 4 - Resize each row of the second splitter
int cyCur, cyMin;
m_wndSplitter2.GetRowInfo( 0, cyCur, cyMin );
m_wndSplitter2.SetRowInfo( 0, size.cy, cyMin );
m_wndSplitter2.GetRowInfo( 1, cyCur, cyMin );
m_wndSplitter2.SetRowInfo( 1, size.cy, cyMin );
// 5 - Ask each splitter to recalculate its layout
m_wndSplitter1.RecalcLayout();
m_wndSplitter2.RecalcLayout();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -