#include "stdafx.h" #include "CHMPropertyPage.h" IMPLEMENT_DYNAMIC(CHMPropertyPage, CDialogEx) CHMPropertyPage::CHMPropertyPage(UINT nID, CWnd* pPage) : CDialogEx(nID, pPage) { } CHMPropertyPage::~CHMPropertyPage() { } void CHMPropertyPage::OnApply() { } void CHMPropertyPage::OnCreateBtns() { } CButton* CHMPropertyPage::CreateBtn(const char* name, int w, int h, const UINT id) { std::string key = std::string(name); auto it = m_btns.find(key); if (it != m_btns.end()) { return it->second; } CButton* pBtn = new CButton(); pBtn->Create(name, WS_CHILD, CRect(0, 0, w, h), GetParent(), id); // 使用默认GUI字体 HFONT hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT); if (hFont != nullptr) { pBtn->SetFont(CFont::FromHandle(hFont), FALSE); } ::SetProp(pBtn->GetSafeHwnd(), _T("BTN_ORDER"), (HANDLE)(INT_PTR)m_btnOrderSeq++); m_btns[key] = pBtn; return pBtn; } CButton* CHMPropertyPage::GetBtnByName(const char* name) { auto it = m_btns.find(std::string(name)); if (it != m_btns.end()) { return it->second; } return nullptr; } std::map& CHMPropertyPage::getBtns() { return m_btns; } BEGIN_MESSAGE_MAP(CHMPropertyPage, CDialogEx) ON_WM_DESTROY() END_MESSAGE_MAP() void CHMPropertyPage::OnDestroy() { CDialogEx::OnDestroy(); for (auto& kv : m_btns) { CButton* btn = kv.second; if (btn != nullptr) { if (::IsWindow(btn->GetSafeHwnd())) { ::RemoveProp(btn->GetSafeHwnd(), _T("BTN_ORDER")); } if (::IsWindow(btn->GetSafeHwnd())) { btn->DestroyWindow(); } delete btn; } } m_btns.clear(); }