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

📄 layout.cpp

📁 windows的snmp api源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

//************************************************************************
// CLayout::CLayout
//
// Constructor for CLayout. This class is used to layout the items on
// the CEventTrapDialog when it is changed from the large extended view to
// the small main view.  This class also handles resizing the CEventTrapDialog.
//
// Parameters:
//      None.
//
// Returns:
//      Nothing.
//************************************************************************
CLayout::CLayout()
{
    m_pdlg = NULL;
}


//************************************************************************
// CLayout::Initialize
//
// Take a snapshot of various initial attributes of the dialog and its
// items. These attributes are used later to constrain the size of the
// dialog and so on.  
//
// This makes it possible to set certain characteristics of the dialog
// in the resource editor so that they do not need to be hard-coded here.
//
// Parameters:
//      CEventTrapDlg* pdlg
//          Pointer to the dialog that needs to be laid out, resized
//          and so on.
//
// Returns:
//      Nothing.
//
//***********************************************************************
void CLayout::Initialize(CEventTrapDlg* pdlg)
{
    ASSERT(m_pdlg == NULL);
    m_pdlg = pdlg;

    // Dialog layout stuff
	CRect rcWindow;
	pdlg->GetWindowRect(&rcWindow);

	CRect rcClient;
	pdlg->GetClientRect(&rcClient);


	CRect rcEventList;	
	pdlg->m_lcEvents.GetWindowRect(&rcEventList);
	pdlg->ScreenToClient(&rcEventList);
	

	m_sizeMainViewInitial.cx = rcClient.right;
	m_sizeMainViewInitial.cy = 	rcEventList.bottom + CY_MARGIN;


	m_sizeExtendedViewInitial.cx = rcClient.right;
	m_sizeExtendedViewInitial.cy = rcClient.bottom;

	m_cyMainView = 0;
	m_cyExtendedView = 0;
}


//*************************************************************************
// CLayout::ResizeMainLayout
//
// This method resizes and repositions the dialog components that appear
// int the small dialog layout.
//
// Parameters:
//      CMainLayout& layoutMain
//          The layout information for the small (main) layout.
//
// Returns:
//      Nothing.
//
//*************************************************************************
void CLayout::ResizeMainLayout(CMainLayout& layoutMain)
{
	m_pdlg->m_btnConfigTypeBox.MoveWindow(&layoutMain.m_rcConfigTypeBox, TRUE);
	m_pdlg->m_btnConfigTypeCustom.MoveWindow(&layoutMain.m_rcConfigCustomButton, TRUE);
	m_pdlg->m_btnConfigTypeDefault.MoveWindow(&layoutMain.m_rcConfigDefaultButton, TRUE);
    
	m_pdlg->m_btnOK.MoveWindow(&layoutMain.m_rcOKButton, TRUE);
	m_pdlg->m_btnCancel.MoveWindow(&layoutMain.m_rcCancelButton, TRUE);
    m_pdlg->m_btnApply.MoveWindow(&layoutMain.m_rcApplyButton, TRUE);
	m_pdlg->m_btnProps.MoveWindow(&layoutMain.m_rcPropertiesButton, TRUE);
	m_pdlg->m_btnSettings.MoveWindow(&layoutMain.m_rcSettingsButton, TRUE);
	m_pdlg->m_btnExport.MoveWindow(&layoutMain.m_rcExportButton, TRUE);
	m_pdlg->m_btnView.MoveWindow(&layoutMain.m_rcViewButton, TRUE);
	m_pdlg->m_lcEvents.MoveWindow(&layoutMain.m_rcListView, TRUE);
}



//*************************************************************************
// CLayout::ResizeExtendedLayout
//
// This method resizes and repositions the dialog components that appear
// int the large (extended) dialog layout.
//
// Parameters:
//      CExtendedLayout& layoutExtended
//          The layout information for the large (extended) layout.
//
// Returns:
//      Nothing.
//
//*************************************************************************
void CLayout::ResizeExtendedLayout(CExtendedLayout& layoutExtended)
{
	m_pdlg->m_btnAdd.MoveWindow(&layoutExtended.m_rcAddButton, TRUE);
	m_pdlg->m_btnRemove.MoveWindow(&layoutExtended.m_rcRemoveButton, TRUE);
	m_pdlg->m_btnFind.MoveWindow(&layoutExtended.m_rcFindButton, TRUE);
	m_pdlg->m_statLabel1.MoveWindow(&layoutExtended.m_rcLabel1, TRUE);
	m_pdlg->m_statLabel2.MoveWindow(&layoutExtended.m_rcLabel2, TRUE);
	m_pdlg->m_tcSource.MoveWindow(&layoutExtended.m_rcTreeView, TRUE);
	m_pdlg->m_lcSource.MoveWindow(&layoutExtended.m_rcListView, TRUE);
}




//*************************************************************************
// CLayout::LayoutAndRedraw
//
// This lays out the size and position of each component on the dialog and
// then redraws the dialog according to the new layout.
//
// Parameters:
//      BOOL bExtendedView
//          TRUE if the layout should be for the large (extended) view of
//          the dialog, FALSE if the layout should be for the small (main)
//          view of the dialog.
//
//      int cx
//          The desired width of the dialog in screen units.
//
//      int cy
//          The desired height of the dialog in screen units.
//
// Returns:
//      Nothing.
//
//*************************************************************************
void CLayout::LayoutAndRedraw(BOOL bExtendedView, int cx, int cy)
{	
	// If the user sizes the window smaller than its original size, then
	// the window will begin to obscure what is already there rather than
	// try to make things smaller.  This avoids the problems that would 
	// occur if buttons and other controls overlapped each other.
	BOOL bLayoutWidth = TRUE;
	BOOL bLayoutHeight = TRUE;

	if (bExtendedView) {
        // Limit the minimum size of the extended view
		if (cx < m_sizeExtendedViewInitial.cx) {
			cx = m_sizeExtendedViewInitial.cx;
			bLayoutWidth = FALSE;
		}

		if (cy < m_sizeExtendedViewInitial.cy) {
			cy = m_sizeExtendedViewInitial.cy;
			bLayoutHeight = FALSE;
		}
		m_cyExtendedView = cy;
	}
	else {
        // Limit the minimum size for the small (main) view
		if (cx < m_sizeMainViewInitial.cx) {
			cx = m_sizeMainViewInitial.cx;
			bLayoutWidth = FALSE;
		}

		if (cy < m_sizeMainViewInitial.cy) {
			cy = m_sizeMainViewInitial.cy;
			bLayoutHeight = FALSE;
		}
		m_cyMainView = cy;
	}



	CDlgMetrics metrics(m_pdlg);
	CMainLayout layoutMain;
	CExtendedLayout layoutExtended;
	CRect rcMain;
	CRect rcExtended;

	int cyMain = cy;
	if (bExtendedView) {
        // For the extended view, half the space if given to the components that
        // appear on the small (main) layout, and the extended components get 
        // half the space.  Thus, the dialog is split horizontally at the half-way
        // point for the extended view.
		cyMain = cy / 2;
		rcMain.SetRect(0, 0, cx, cy / 2);
		layoutMain.Create(metrics, rcMain);
		ResizeMainLayout(layoutMain);

        // The extended component rectangle's top is at the half-way point. The bottom
        // is at the bottom of the dialog.
		rcExtended.SetRect(0, cy / 2, cx, cy);
		layoutExtended.Create(metrics, rcExtended);
		ResizeExtendedLayout(layoutExtended);
	}
	else {
        // For the small (main) view, use the entire dialog.
		rcMain.SetRect(0, 0, cx, cy);
		layoutMain.Create(metrics, rcMain);
		ResizeMainLayout(layoutMain);
	}
		

	// Redraw the entire client area to fix things up since much
	// of the stuff in the client has moved around.
	CRect rcClient;
	m_pdlg->GetClientRect(&rcClient);
	m_pdlg->InvalidateRect(&rcClient);
	
}


//**************************************************************
// CLayout::LayoutView
//
// This method lays out the position and size of the CEventTrap
// dialog and the items that appear on it.
//
// Parameters:
//      BOOL bExtendedView
//          TRUE if this is a request to layout the extended (large)
//          view of the dialog.  FALSE if this is a request to layout
//          the small (main) view of the dialog.
//
// Returns:
//      Nothing.
//**************************************************************
void CLayout::LayoutView(BOOL bExtendedView)
{
	CRect rcWindow;
	m_pdlg->GetWindowRect(&rcWindow);

	CRect rcClient;
	m_pdlg->GetClientRect(&rcClient);
	m_pdlg->ClientToScreen(&rcClient);

    // cx and cy are the width and height of the dialog in client units
    // respectively.  The code below will calculate new values for cx and
    // cy to reflect the change from extended view to small (main) view
    // or vice-versa.
	int cx = rcClient.Width();
	int cy = rcClient.Height();
	int cxInitial = cx;
	int cyInitial = cy;

    // Compute the margins that intervene between the client
    // rectangle and window rectangle.
	int cxLeftMargin = rcClient.left - rcWindow.left;
	int cyTopMargin = rcClient.top - rcWindow.top;
	int cxRightMargin = rcWindow.right - rcClient.right;
	int cyBottomMargin = rcWindow.bottom - rcClient.bottom;


	CRect rc;
	m_pdlg->GetClientRect(&rc);
	
	if (bExtendedView) {
        // Control comes here if we are changing from the small main view
        // to the larger extended view.  This causes the dialog to flip 
        // back to the previous size of the extended view.  However this
        // is constrained to a minimum of the original dialog size.

        // Save the current height of the main view so that we can flip
        // back to it later.  Assume that the new height will be the
        // height of the extended view when it was flipped the last time.
		m_cyMainView = cy;
		cy = m_cyExtendedView;		

        // Constrain the height so that the mimimum height is what it
        // the initial height was for the extended view.
		if (cx < m_sizeExtendedViewInitial.cx) {
			cx = m_sizeExtendedViewInitial.cx;
		}

		if (cy < m_sizeExtendedViewInitial.cy) {
			cy = m_sizeExtendedViewInitial.cy;
		}


        // The extended view should never be smaller than the main view.
        // This check is necessary when the user resizes the window and
        // then flips the view.
        if (cy < m_cyMainView) {
            cy = m_cyMainView;
        }


		
		rc.SetRect(0, 0, cx, cy);

        // Check to see if the size changed, if not then do nothing.
        // Otherwise, resize the window.
		if ((cxInitial != cx) || (cyInitial != cy)) {			
			m_pdlg->ClientToScreen(&rc);
			rc.left -= cxLeftMargin;
			rc.top -= cyTopMargin;
			rc.right += cxRightMargin;
			rc.bottom += cyBottomMargin;
			m_pdlg->MoveWindow(&rc, TRUE);
		}
		else {
			LayoutAndRedraw(bExtendedView, cx, cy);
		}
	}

    // The main view should never be taller than the extended view.  This may
    // check is necessary if the user resized the window and then flipped to the
    // other view.
    if (m_cyMainView > m_cyExtendedView) {
        m_cyMainView = m_cyExtendedView;
    }

    // Show or hide the items in the extended portion of the dialog.
	ShowExtendedView(bExtendedView);


	if (!bExtendedView) {
		// This used to be an extended view, now we need to
		// go back to just the main view.

		// Save the current extended view height and then flip back to the
        // previously saved main (small) view height.
		m_cyExtendedView = cy;
		cy = m_cyMainView;

        // Constrain the size to be at least as large as the initial size for
        // the main (small) view.		
		if (cx < m_sizeMainViewInitial.cx) {
			cx = m_sizeMainViewInitial.cx;
		}
		if (cy < m_sizeMainViewInitial.cy) {
			cy = m_sizeMainViewInitial.cy;
		}


        // Resize the dialog only if the computed size is different
        // from the current size. Moving the window to resize it will automatically
        // cause it to be layed out correctly.
		if ((cxInitial != cx) || (cyInitial != cy)) {
			rc.SetRect(0, 0, cx, cy);
			m_pdlg->ClientToScreen(&rc);
			rc.left -= cxLeftMargin;
			rc.top -= cyTopMargin;
			rc.right += cxRightMargin;
			rc.bottom += cyBottomMargin;
			m_pdlg->MoveWindow(&rc, TRUE);
		}
		else {
			LayoutAndRedraw(bExtendedView, cx, cy);
		}
	}
}


//**************************************************************
// CLayout::ShowExtendedView
//
// This method shows or hides the dialog items that make up the
// extended portion of the dialog.
//
// Parameters:
//      BOOL bShowExtendedItems
//          TRUE if the extended items should be shown, false if
//          they should be hidden.
//
// Returns:
//      Nothing.
//**************************************************************
void CLayout::ShowExtendedView(BOOL bShowExtendedItems)
{
	m_pdlg->m_btnRemove.ShowWindow(bShowExtendedItems);
	m_pdlg->m_btnAdd.ShowWindow(bShowExtendedItems);
	m_pdlg->m_btnFind.ShowWindow(bShowExtendedItems);
	m_pdlg->m_lcSource.ShowWindow(bShowExtendedItems);
	m_pdlg->m_tcSource.ShowWindow(bShowExtendedItems);
	m_pdlg->m_statLabel1.ShowWindow(bShowExtendedItems);
	m_pdlg->m_statLabel2.ShowWindow(bShowExtendedItems);
}

⌨️ 快捷键说明

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