mrDarker
2025-09-12 0fb528df2c1f05ef7d52827432bd934ce6f9d8cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// 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);
    }
}