📄 splitdialog.cpp
字号:
// SplitDialog.cpp : implementation file
//
#include "stdafx.h"
#include "SplitDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSplitDialog dialog
CSplitDialog::CSplitDialog(CWnd* pParent /*=NULL*/)
: CDialog(nIDTemplate, pParent)
{
}
CSplitDialog::CSplitDialog(UINT nIDTemplate, CWnd* pParent /*=NULL*/)
: CDialog(nIDTemplate, pParent)
{
//{{AFX_DATA_INIT(CSplitDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pMainPane = NULL;
m_bMovingSplitter = FALSE;
m_movingPane = NULL;
}
CSplitDialog::~CSplitDialog()
{
//free memory create with new...
if (m_pMainPane)
delete m_pMainPane;
CDialog::~CDialog();
}
void CSplitDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSplitDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSplitDialog, CDialog)
//{{AFX_MSG_MAP(CSplitDialog)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
ON_WM_SIZING()
ON_WM_SIZE()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSplitDialog message handlers
//
//Need to call this function after all the controls have been added
//
void CSplitDialog::Initialize()
{
m_pMainPane->MovePane();
}
void CSplitDialog::OnSizing( UINT nSide, LPRECT lpRect)
{
//when we're sizing we have to make sure we don't
//let the user resize smaller than the minimum values
if (m_pMainPane) {
int minheight = m_pMainPane->GetMinHeight() + m_OffsetRect.bottom + m_OffsetRect.top;
if ((lpRect->bottom - lpRect->top) < minheight) {
switch(nSide) {
case WMSZ_BOTTOM:
case WMSZ_BOTTOMLEFT:
case WMSZ_BOTTOMRIGHT:
lpRect->bottom = lpRect->top + minheight;
break;
case WMSZ_TOP:
case WMSZ_TOPLEFT:
case WMSZ_TOPRIGHT:
lpRect->top = lpRect->bottom - minheight;
break;
}
}
int minwidth = m_pMainPane->GetMinWidth() + m_OffsetRect.left + m_OffsetRect.right;
if ((lpRect->right - lpRect->left) < minwidth) {
switch(nSide) {
case WMSZ_BOTTOMLEFT:
case WMSZ_TOPLEFT:
case WMSZ_LEFT:
lpRect->left = lpRect->right - minwidth;
break;
case WMSZ_BOTTOMRIGHT:
case WMSZ_TOPRIGHT:
case WMSZ_RIGHT:
lpRect->right = lpRect->left + minwidth;
break;
}
}
}
CDialog::OnSizing(nSide,lpRect);
}
void CSplitDialog::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
//when the dialog has been sized, resize the contents
if (m_pMainPane) m_pMainPane->MovePane(
cx - (m_OffsetRect.right + m_OffsetRect.left),
cy - (m_OffsetRect.bottom + m_OffsetRect.top));
}
void CSplitDialog::OnMouseMove(UINT nFlags, CPoint point)
{
//CClientDC dc(this);
//dc.DPtoLP(&point);
char *cur;
CPane *pPane;
//check if the point is on any splitter...
if (m_pMainPane && (cur = m_pMainPane->IsPointInSplitter(point,&pPane)))
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(cur)));
// if we're moving the splitter, resize everything for that specific splitter
if (m_bMovingSplitter) {
m_movingPane->MoveSplitter(point);
}
CDialog::OnMouseMove(nFlags, point);
}
void CSplitDialog::OnLButtonDown(UINT nFlags, CPoint point)
{
//CClientDC dc( this );
//dc.DPtoLP(&point);
char *cur;
// If the point is over the splitter ...
if (m_pMainPane && (cur = m_pMainPane->IsPointInSplitter(point,&m_movingPane)))
{
// ... capture the mouse, change the cursor and set the moving splitter flag
SetCapture();
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(cur)));
m_bMovingSplitter = TRUE;
}
CDialog::OnLButtonDown(nFlags, point);
}
void CSplitDialog::OnLButtonUp(UINT nFlags, CPoint point)
{
if (m_bMovingSplitter) {
CClientDC dc( this );
dc.DPtoLP( &point );
// Reset the moving splitter flag
m_bMovingSplitter = FALSE;
//resize the panes
m_movingPane->MoveSplitter(point);
// Release the mouse
ReleaseCapture();
}
CDialog::OnLButtonUp(nFlags, point);
}
//
//This function will create a pain in the given parent pane.
//if no parent pane is given then the created pain will be
//set as the main one.
//
//nWhich sepecifies which pane we are creating, pass 1 to
//create the left/top panes or 2 to create the right/bottom panes
//
//nSplitType will specify the type of the split, this can be
//CPane::HORIZONTAL or CPane:VERTICAL
//bSizeableControls表示在2控件间是否有可移动的分隔条
CPane *CSplitDialog::CreatePane(int nSplitType, CPane *pParent, int nWhich, BOOL bSizeableControls)
{
CPane *pPane = new CPane;
pPane->m_nSplitType = nSplitType;
pPane->m_bSizeableControls = bSizeableControls;
if (pParent) {
if (nWhich == 1) {
pParent->m_nLeftType = CPane::PT_PANE;
pParent->left.pPane = pPane;
pPane->m_bLeftVisible = TRUE;
} else if (nWhich == 2) {
pParent->m_nRightType = CPane::PT_PANE;
pParent->right.pPane = pPane;
pPane->m_bRightVisible = TRUE;
}
//m_pMainPane->MovePane();
} else {
CRect rect;
GetClientRect(&rect);
m_OffsetRect.left = 0;
m_OffsetRect.right = 0;
m_OffsetRect.bottom = 0;
m_OffsetRect.top = 0;
pPane->MovePane(rect.left, rect.top, rect.Width(), rect.Height());
m_pMainPane = pPane;
}
return pPane;
}
//This almost works like CreatePane but instead of embedding
//a pane inside another pane, it embeds the given Cwnd in the left/right
//of the given pane...
//minWidth/minHeight specify the minimum dimensions of the CWnd while resizing
//Width/Height specify the original dimensions
BOOL CSplitDialog::SetPaneWnd(CPane *pPane, CWnd *pWnd, int nWhich,int minWidth, int minHeight, int Width, int Height)
{
if (Width!=0 && Height!=0)
::MoveWindow(pWnd->m_hWnd,0,0,Width,Height,TRUE);
if (nWhich == 1) {
pPane->m_nLeftType = CPane::PT_WINDOW;
pPane->left.pWnd = pWnd;
pPane->m_nLeftMinWidth = minWidth;
pPane->m_nLeftMinHeight = minHeight;
pPane->m_bLeftVisible = TRUE;
} else if (nWhich == 2) {
pPane->m_nRightType = CPane::PT_WINDOW;
pPane->right.pWnd = pWnd;
pPane->m_nRightMinWidth = minWidth;
pPane->m_nRightMinHeight = minHeight;
pPane->m_bRightVisible = TRUE;
}
//m_pMainPane->MovePane();
return TRUE;
}
//设置显示/隐藏面板pane
BOOL CSplitDialog::ShowPane(CPane *pPane, BOOL bShow,int nWhich)
{
switch(nWhich) {
case 1: //hide left
pPane->ShowLeft(bShow);
break;
case 2: //hide right
pPane->ShowRight(bShow);
break;
}
//resize everything...
m_pMainPane->MovePane();
return TRUE;
}
//This will set the Main pane's rectangle to the given one
void CSplitDialog::SetMainRect(RECT rect)
{
if (!m_pMainPane) return;
RECT clrect;
GetClientRect(&clrect);
m_OffsetRect.left = rect.left;
m_OffsetRect.top = rect.top;
m_OffsetRect.bottom = clrect.bottom - rect.bottom;
m_OffsetRect.right = clrect.right - rect.right;
m_pMainPane->MovePane(rect.left,rect.top,rect.right - rect.left,rect.bottom - rect.top);
}
//just another form of the first one...
void CSplitDialog::SetMainRect(int X, int Y, int nWidth, int nHeight)
{
RECT rect;
rect.left = X;
rect.top = Y;
rect.right = rect.left + nWidth;
rect.bottom = rect.top + nHeight;
SetMainRect(rect);
}
//设置Dialog顶部空白区
void CSplitDialog::SetTopOffset(int topOffset)
{
RECT rect;
rect.top = topOffset;
rect.bottom = m_pMainPane->m_nHeight + rect.top;
rect.left = m_pMainPane->m_Y;
rect.right = m_pMainPane->m_nWidth + rect.left;
SetMainRect(rect);
}
//设置Dialog左边空白区
void CSplitDialog::SetLeftOffset(int leftOffset)
{
RECT rect;
rect.top = m_pMainPane->m_X;
rect.bottom = m_pMainPane->m_nHeight + rect.top;
rect.left = leftOffset;
rect.right = m_pMainPane->m_nWidth + rect.left;
SetMainRect(rect);
}
//设置Dialog右边空白区
void CSplitDialog::SetRightOffset(int rightOffset)
{
RECT rect,clrect;
GetClientRect(&clrect);
rect.top = m_pMainPane->m_X;
rect.bottom = m_pMainPane->m_nHeight + rect.top;
rect.left = m_pMainPane->m_Y;
rect.right = clrect.right - rightOffset;
SetMainRect(rect);
}
//设置Dialog底部空白区
void CSplitDialog::SetBottomOffset(int bottomOffset)
{
RECT rect,clrect;
GetClientRect(&clrect);
rect.top = m_pMainPane->m_X;
rect.bottom = clrect.bottom - bottomOffset;
rect.left = m_pMainPane->m_Y;
rect.right = m_pMainPane->m_nWidth + rect.left;
SetMainRect(rect);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -