⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splitterwndex.cpp

📁 UHF RFID Reader Program
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//============================================================================
//
// Filename:         splitterWndEx.cpp
// Description:      Implementation of a splitter class that can have 2 panes
//                   with multiple different views
//
//============================================================================

// Required headers
#include "stdafx.h"
#include "SplitterWndEx.h"

//----------------------------------------------------------------------------
//
// Function:         CSplitterWndEx::CSplitterWndEx
//
// Description:      Class constructor function
//
// Scope:            public
//
// Parameters:
//    None
//
// Return Values:
//    N/A
//
// Remarks:
//    None
//
//----------------------------------------------------------------------------
CSplitterWndEx::CSplitterWndEx()
{
	// Initialize members
	m_eDirection = Unknown;
	m_pSubSplitter[0] = NULL;
	m_pSubSplitter[1] = NULL;
	m_fPaneVisible[0] = TRUE;
	m_fPaneVisible[1] = TRUE;
}

//----------------------------------------------------------------------------
//
// Function:         CSplitterWndEx::~CSplitterWndEx
//
// Description:      Class destructor function
//
// Scope:            public
//
// Parameters:
//    None
//
// Return Values:
//    N/A
//
// Remarks:
//    None
//
//----------------------------------------------------------------------------
CSplitterWndEx::~CSplitterWndEx()
{
	if (m_pSubSplitter[0] != NULL)
		delete m_pSubSplitter[0];
	if (m_pSubSplitter[1] != NULL)
		delete m_pSubSplitter[1];
}

//----------------------------------------------------------------------------
//
// Function:         CSplitterWndEx::Create
//
// Description:      Creates the splitter window
//
// Scope:            public
//
// Parameters:
//    [in] CWnd *pParent                  Pointer to the parent window
//    [in] CCreateContext *pContext       Pointer to the context in which to
//                                        create the splitter
//    [in] ESplitDirection eDirection     Direction to split the window
//    [in] int iChildID                   Child window ID
//
// Return Values:
//    BOOL                 TRUE on success or FALSE on failure
//
// Remarks:
//    None
//
//----------------------------------------------------------------------------
BOOL CSplitterWndEx::Create(CWnd *pParent, CCreateContext *pContext, 
							ESplitDirection eDirection, int iChildID)
{
	// Vertical split
	int iRows, iCols;
	if (eDirection == Vertical)
	{
		m_eDirection = Vertical;
		iRows = 1;
		iCols = 2;
	}

	// Horizontal split
	else if (eDirection == Horizontal)
	{
		m_eDirection = Horizontal;
		iRows = 2;
		iCols = 1;
	}

	// Create the split window
	if (!CreateStatic(pParent, iRows, iCols, WS_CHILD | WS_VISIBLE | WS_BORDER,
		iChildID))
	{
		return FALSE;
	}
	return TRUE;
}

//----------------------------------------------------------------------------
//
// Function:         CSplitterWndEx::IsPaneHidden
//
// Description:      Determines if the given pane is hidden or not
//
// Scope:            public
//
// Parameters:
//    [in] ESplitPane ePane               Pane to check
//
// Return Values:
//    BOOL                 TRUE if the pane is hidden or FALSE if not
//
// Remarks:
//    If the window is split horizontally, the split pane must be Top or
//    Bottom.  If split vertically, the pane must be Left or Right.
//
//----------------------------------------------------------------------------
BOOL CSplitterWndEx::IsPaneHidden(ESplitPane ePane)
{
	if (m_eDirection == Horizontal)
	{
		ASSERT((ePane == Top || ePane == Bottom));
		if (ePane == Top && m_fPaneVisible[0])
			return FALSE;
		else if (ePane == Bottom && m_fPaneVisible[1])
			return FALSE;
	}
	else if (m_eDirection == Vertical)
	{
		ASSERT((ePane == Left || ePane == Right));
		if (ePane == Left && m_fPaneVisible[0])
			return FALSE;
		else if (ePane == Right && m_fPaneVisible[1])
			return FALSE;
	}
	return TRUE;
}

//----------------------------------------------------------------------------
//
// Function:         CSplitterWndEx::ShowPane
//
// Description:      Shows or hides the given pane
//
// Scope:            public
//
// Parameters:
//    [in] ESplitPane ePane      Pane to show/hide
//    [in] BOOL fShow            Show the pane
//
// Return Values:
//    None
//
// Remarks:
//    If the window is split horizontally, the split pane must be Top or
//    Bottom.  If split vertically, the pane must be Left or Right.
//
//----------------------------------------------------------------------------
void CSplitterWndEx::ShowPane(ESplitPane ePane, BOOL fShow)
{
	// Make sure a proper pane was passed
	int iIndex;
	if (m_eDirection == Horizontal)
	{
		ASSERT((ePane == Top || ePane == Bottom));
		if (ePane == Top)
			iIndex = 0;
		else
			iIndex = 1;
	}
	else if (m_eDirection == Vertical)
	{
		ASSERT((ePane == Left || ePane == Right));
		if (ePane == Left)
			iIndex = 0;
		else
			iIndex = 1;
	}

	// If the pane's visibility is changing, make sure to update the layout
	if (m_fPaneVisible[iIndex] != fShow)
	{
		if (!fShow)
			HidePane(ePane);
		else
			ShowPane(ePane);
		m_fPaneVisible[iIndex] = fShow;
	}
}

//----------------------------------------------------------------------------
//
// Function:         CSplitterWndEx::GetPaneSubSplitter
//
// Description:      Returns the CSplitterWndEx pointer for the given pane
//
// Scope:            public
//
// Parameters:
//    [in] ESplitPane ePane               Pane to get
//
// Return Values:
//    CSplitterWndEx *     A pointer to the sub-splitter window on success
//                         or a NULL pointer if there is no sub-splitter or
//                         an error occurs
//
// Remarks:
//    If the window is split horizontally, the split pane must be Top or
//    Bottom.  If split vertically, the pane must be Left or Right.
//
//----------------------------------------------------------------------------
CSplitterWndEx *CSplitterWndEx::GetPaneSubSplitter(ESplitPane ePane)
{
	if (m_eDirection == Horizontal)
	{
		ASSERT((ePane == Top || ePane == Bottom));
		if (ePane == Top)
			return m_pSubSplitter[0];
		else
			return m_pSubSplitter[1];
	}
	else if (m_eDirection == Vertical)
	{
		ASSERT((ePane == Left || ePane == Right));
		if (ePane == Left)
			return m_pSubSplitter[0];
		else
			return m_pSubSplitter[1];
	}
	return NULL;
}

//----------------------------------------------------------------------------
//
// Function:         CSplitterWndEx::GetPaneViews
//
// Description:      Gets the list of available views for the given pane
//
// Scope:            public
//
// Parameters:
//    [in] ESplitPane ePane               Pane to get
//
// Return Values:
//    CViewList *          A pointer to the available views list on success or
//                         NULL on failure
//
// Remarks:
//    If the window is split horizontally, the split pane must be Top or
//    Bottom.  If split vertically, the pane must be Left or Right.
//
//----------------------------------------------------------------------------
CViewList *CSplitterWndEx::GetPaneViews(ESplitPane ePane)
{
	if (m_eDirection == Horizontal)
	{
		ASSERT((ePane == Top || ePane == Bottom));
		if (ePane == Top)
			return &m_listViews[0];
		else
			return &m_listViews[1];
	}
	else if (m_eDirection == Vertical)
	{
		ASSERT((ePane == Left || ePane == Right));
		if (ePane == Left)
			return &m_listViews[0];
		else
			return &m_listViews[1];
	}
	return NULL;
}

//----------------------------------------------------------------------------
//
// Function:         CSplitterWndEx::AddView
//
// Description:      Adds a new view to a splitter pane by calling the
//                   CreateView API
//
// Scope:            public
//
// Parameters:
//    [in] ESplitPane ePane               Pane to add the view to
//    [in] CRuntimeClass *pViewClass      The CView-derived class to add
//    [in] CSize size                     Initial window size
//    [in] CCreateContext *pContext       Pointer to the context in which to
//                                        create the window
//
// Return Values:
//    BOOL                 TRUE on success or false on failure
//
// Remarks:
//    If the window is split horizontally, the split pane must be Top or
//    Bottom.  If split vertically, the pane must be Left or Right.
//
//----------------------------------------------------------------------------
BOOL CSplitterWndEx::AddView(ESplitPane ePane, CRuntimeClass *pViewClass,
							 CSize size, CCreateContext *pContext)
{
	// Make sure a proper pane was passed
	int iViewsIndex = -1;
	if (m_eDirection == Horizontal)
	{
		ASSERT((ePane == Top || ePane == Bottom));
		if (ePane == Top)
			iViewsIndex = 0;
		else
			iViewsIndex = 1;
	}
	else if (m_eDirection == Vertical)
	{
		ASSERT((ePane == Left || ePane == Right));
		if (ePane == Left)
			iViewsIndex = 0;
		else
			iViewsIndex = 1;
	}

	// Find out which row/column we're adding the view to
	int iRow, iCol;
	PaneToRowCol(ePane, iRow, iCol);

	// Hide the current view of the pane if there is a view attached already
	if (GetDlgItem(IdFromRowCol(iRow, iCol)))
		HideView(iRow, iCol);

	// Create the new view
	if (!CreateView(iRow, iCol, pViewClass, size, pContext))
		return FALSE;

	// Store the new view
	CWnd *pWnd = GetPane(iRow, iCol);
	m_listViews[iViewsIndex].push_back(pWnd);

	// Show the window
	ShowView(iRow, iCol, pWnd);
	RedrawWindow();
	return TRUE;
}

//----------------------------------------------------------------------------
//
// Function:         CSplitterWndEx::SwitchView
//
// Description:      Switches the active view in one of the splitter panes
//
// Scope:            public
//
// Parameters:
//    [in] ESplitPane ePane      Pane to switch the view in
//    [in] UINT uiViewIndex      The index of the view to switch to
//
// Return Values:
//    BOOL                 TRUE on success or false on failure
//
// Remarks:
//    If the window is split horizontally, the split pane must be Top or
//    Bottom.  If split vertically, the pane must be Left or Right.
//
//----------------------------------------------------------------------------
BOOL CSplitterWndEx::SwitchView(ESplitPane ePane, UINT uiViewIndex)
{
	// Make sure a proper pane was passed
	int iIndex = -1;
	if (m_eDirection == Horizontal)
	{
		ASSERT((ePane == Top || ePane == Bottom));
		if (ePane == Top)
			iIndex = 0;
		else
			iIndex = 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -