// CMainContainer.cpp: 实现文件 // #include "stdafx.h" #include "BoounionPLC.h" #include "Common.h" #include "CMainContainer.h" #include "afxdialogex.h" // CMainContainer 对话框 IMPLEMENT_DYNAMIC(CMainContainer, CDialogEx) CMainContainer::CMainContainer(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_MAIN_CONTAINER, pParent) { m_crBkgnd = MAIN_CONTAINER_BACKGROUND; m_hbrBkgnd = nullptr; m_pBottomWnd = nullptr; m_nBottomWndHeight = 0; } CMainContainer::~CMainContainer() { } void CMainContainer::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CMainContainer, CDialogEx) ON_WM_CTLCOLOR() ON_WM_DESTROY() ON_WM_SIZE() END_MESSAGE_MAP() // CMainContainer 消息处理程序 void CMainContainer::SetBottomWnd(CWnd* pWnd, int nHeight) { m_pBottomWnd = pWnd; m_nBottomWndHeight = nHeight; } BOOL CMainContainer::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: 在此添加额外的初始化 return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } HBRUSH CMainContainer::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_STATIC) { pDC->SetBkColor(m_crBkgnd); } if (m_hbrBkgnd == nullptr) { m_hbrBkgnd = CreateSolidBrush(m_crBkgnd); } return m_hbrBkgnd; } void CMainContainer::OnDestroy() { CDialogEx::OnDestroy(); if (m_hbrBkgnd != nullptr) { ::DeleteObject(m_hbrBkgnd); } } void CMainContainer::OnSize(UINT nType, int cx, int cy) { CDialogEx::OnSize(nType, cx, cy); Resize(); } void CMainContainer::Resize() { CRect rcClient, rcChild; GetClientRect(&rcClient); rcChild = rcClient; if (m_pBottomWnd != nullptr && m_nBottomWndHeight > 0) { rcChild.bottom -= m_nBottomWndHeight; } // 先取得子窗口数量 int count = 0; CWnd* pClild = FindWindowEx(m_hWnd, NULL, NULL, NULL); while (pClild != nullptr) { count++; pClild = FindWindowEx(m_hWnd, pClild->m_hWnd, NULL, NULL); } pClild = FindWindowEx(m_hWnd, NULL, NULL, NULL); while (pClild != nullptr) { if (pClild != m_pBottomWnd) { pClild->MoveWindow(&rcChild); } else if (m_pBottomWnd != nullptr) { m_pBottomWnd->MoveWindow(0, rcChild.bottom, rcClient.Width(), rcClient.bottom - rcChild.bottom); } if (::GetProp(pClild->GetSafeHwnd(), "Home") == (HANDLE)1) { pClild->ShowWindow(count == 1 ? SW_SHOW : SW_HIDE); } else { pClild->ShowWindow(SW_SHOW); } pClild = FindWindowEx(m_hWnd, pClild->m_hWnd, NULL, NULL); } }