// SettingsDlg.cpp : ʵÏÖÎļþ
|
//
|
|
#include "stdafx.h"
|
#include "BondEq.h"
|
#include "SettingsDlg.h"
|
#include "afxdialogex.h"
|
|
|
// CSettingsDlg ¶Ô»°¿ò
|
|
IMPLEMENT_DYNAMIC(CSettingsDlg, CDialogEx)
|
|
CSettingsDlg::CSettingsDlg(CWnd* pParent /*=NULL*/)
|
: CDialogEx(IDD_DIALOG_SETTINGS, pParent)
|
{
|
m_crBkgnd = RGB(239, 244, 254);
|
m_pTab = nullptr;
|
m_bInit = FALSE;
|
}
|
|
CSettingsDlg::~CSettingsDlg()
|
{
|
}
|
|
void CSettingsDlg::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
}
|
|
|
BEGIN_MESSAGE_MAP(CSettingsDlg, CDialogEx)
|
ON_WM_CTLCOLOR()
|
ON_WM_DESTROY()
|
ON_WM_SIZE()
|
ON_NOTIFY(HMVERTICALTAB_SEL_CHANGED, IDC_TAB1, &CSettingsDlg::OnTabSelChanged)
|
ON_BN_CLICKED(IDC_BUTTON_APPLY, &CSettingsDlg::OnBnClickedButtonApply)
|
ON_BN_CLICKED(IDOK, &CSettingsDlg::OnBnClickedOk)
|
ON_MESSAGE(ID_MSG_PAGE_MODIFY, &CSettingsDlg::OnPageModify)
|
END_MESSAGE_MAP()
|
|
|
// CSettingsDlg ÏûÏ¢´¦Àí³ÌÐò
|
|
|
BOOL CSettingsDlg::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
|
CSetPage1* pPage1 = new CSetPage1();
|
pPage1->Create(IDD_SET_PAGE1, this);
|
|
CSetPage2* pPage2 = new CSetPage2();
|
pPage2->Create(IDD_SET_PAGE2, this);
|
|
m_pTab = CHmVerticalTab::Hook(GetDlgItem(IDC_TAB1)->m_hWnd);
|
m_pTab->SetPaddingTop(3);
|
m_pTab->SetBkgndColor(RGB(235, 235, 243));
|
m_pTab->AddItem(_T("³£¹æÉèÖÃ"), pPage1);
|
m_pTab->AddItem(_T("ɱ¶¾"), pPage2);
|
m_pTab->AddItem(_T("ʵʱ·À»¤"));
|
m_pTab->AddItem(_T("ÇåÀí¼ÓËÙ"));
|
m_pTab->AddItem(_T("©¶´ÐÞ¸´"));
|
|
ShowChildPage(0);
|
Resize();
|
m_bInit = TRUE;
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
// Òì³£: OCX ÊôÐÔÒ³Ó¦·µ»Ø FALSE
|
}
|
|
HBRUSH CSettingsDlg::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 CSettingsDlg::OnDestroy()
|
{
|
CDialogEx::OnDestroy();
|
|
for (unsigned int i = 0; i < 5; i++) {
|
CBaseSetPage* pPage = (CBaseSetPage*)m_pTab->GetContext(i);
|
if (pPage != nullptr) {
|
pPage->DestroyWindow();
|
delete pPage;
|
}
|
}
|
|
if (m_hbrBkgnd != nullptr) {
|
::DeleteObject(m_hbrBkgnd);
|
}
|
}
|
|
void CSettingsDlg::OnSize(UINT nType, int cx, int cy)
|
{
|
CDialogEx::OnSize(nType, cx, cy);
|
if (nullptr == GetDlgItem(IDC_TAB1)) return;
|
Resize();
|
}
|
|
void CSettingsDlg::Resize()
|
{
|
CWnd* pItem;
|
CRect rcClient, rcItem;
|
int x, y;
|
|
x = 1;
|
GetClientRect(&rcClient);
|
pItem = GetDlgItem(IDC_TAB1);
|
pItem->GetClientRect(&rcItem);
|
pItem->MoveWindow(x, 1, rcItem.Width(), rcClient.Height() - 2);
|
x += rcItem.Width();
|
x += 1;
|
|
pItem = GetDlgItem(IDC_BUTTON_APPLY);
|
pItem->GetWindowRect(&rcItem);
|
ScreenToClient(&rcItem);
|
y = rcItem.top - 12;
|
|
for (unsigned int i = 0; i < 5; i++) {
|
CBaseSetPage* pPage = (CBaseSetPage*)m_pTab->GetContext(i);
|
if (pPage != nullptr) {
|
pPage->MoveWindow(x, 1, rcClient.Width() - x - 1, y - 2);
|
}
|
}
|
}
|
|
void CSettingsDlg::OnTabSelChanged(NMHDR* nmhdr, LRESULT* result)
|
{
|
HMVERTICALTAB_NMHDR* pNmhdrex = (HMVERTICALTAB_NMHDR*)nmhdr;
|
ShowChildPage((unsigned int)pNmhdrex->dwData);
|
|
*result = 0;
|
}
|
|
void CSettingsDlg::ShowChildPage(unsigned int index)
|
{
|
ASSERT(0 <= index && index < 5);
|
for (unsigned int i = 0; i < 5; i++) {
|
CBaseSetPage* pPage = (CBaseSetPage*)m_pTab->GetContext(i);
|
if (pPage != nullptr) {
|
pPage->ShowWindow(i == index ? SW_SHOW : SW_HIDE);
|
}
|
|
}
|
}
|
|
void CSettingsDlg::OnBnClickedButtonApply()
|
{
|
for (unsigned int i = 0; i < 5; i++) {
|
CBaseSetPage* pPage = (CBaseSetPage*)m_pTab->GetContext(i);
|
if (pPage != nullptr) {
|
pPage->OnApply();
|
}
|
}
|
|
GetDlgItem(IDC_BUTTON_APPLY)->EnableWindow(FALSE);
|
}
|
|
void CSettingsDlg::OnBnClickedOk()
|
{
|
for (unsigned int i = 0; i < 5; i++) {
|
CBaseSetPage* pPage = (CBaseSetPage*)m_pTab->GetContext(i);
|
if (pPage != nullptr) {
|
pPage->OnApply();
|
}
|
}
|
|
CDialogEx::OnOK();
|
}
|
|
LRESULT CSettingsDlg::OnPageModify(WPARAM wParam, LPARAM lParam)
|
{
|
if (m_bInit) {
|
GetDlgItem(IDC_BUTTON_APPLY)->EnableWindow(TRUE);
|
}
|
|
return 0;
|
}
|