xref: /MusicPlayer2/MusicPlayer2/OptionsDlg.cpp (revision d520d6a4a04a2c771aa013c1b651e3c14aea9a6a)
1 // OptionsDlg.cpp : 实现文件
2 //
3 
4 #include "stdafx.h"
5 #include "MusicPlayer2.h"
6 #include "OptionsDlg.h"
7 #include "afxdialogex.h"
8 
9 
10 // COptionsDlg 对话框
11 
12 IMPLEMENT_DYNAMIC(COptionsDlg, CBaseDialog)
13 
14 COptionsDlg::COptionsDlg(CWnd* pParent /*=NULL*/)
15 	: CBaseDialog(IDD_OPTIONS_DIALOG, pParent)
16 {
17 
18 }
19 
20 COptionsDlg::~COptionsDlg()
21 {
22 }
23 
24 CString COptionsDlg::GetDialogName() const
25 {
26     return _T("OptionsDlg");
27 }
28 
29 void COptionsDlg::DoDataExchange(CDataExchange* pDX)
30 {
31 	CBaseDialog::DoDataExchange(pDX);
32 	DDX_Control(pDX, IDC_OPTIONS_TAB, m_tab);
33 }
34 
35 
36 BEGIN_MESSAGE_MAP(COptionsDlg, CBaseDialog)
37 	ON_BN_CLICKED(IDC_APPLY_BUTTON, &COptionsDlg::OnBnClickedApplyButton)
38 	ON_WM_DESTROY()
39     ON_WM_GETMINMAXINFO()
40     ON_WM_SIZE()
41 END_MESSAGE_MAP()
42 
43 
44 // COptionsDlg 消息处理程序
45 
46 
47 BOOL COptionsDlg::OnInitDialog()
48 {
49 	CBaseDialog::OnInitDialog();
50 
51 	// TODO:  在此添加额外的初始化
52 
53     SetIcon(theApp.m_icon_set.setting.GetIcon(true), FALSE);
54 
55 	//创建子对话框
56 	m_tab1_dlg.Create(IDD_LYRIC_SETTING_DIALOG);
57 	m_tab2_dlg.Create(IDD_APPEREANCE_SETTING_DLG);
58 	m_tab3_dlg.Create(IDD_DATA_SETTINGS_DIALOG);
59 	m_tab4_dlg.Create(IDD_PLAY_SETTING_DIALOG);
60 	m_media_lib_dlg.Create(IDD_MEDIA_LIB_SETTING_DIALOG);
61 	m_tab5_dlg.Create(IDD_HOT_KEY_SETTINGS_DIALOG);
62 
63 	//保存子对话框
64 	m_tab_vect.push_back(&m_tab1_dlg);
65 	m_tab_vect.push_back(&m_tab2_dlg);
66 	m_tab_vect.push_back(&m_tab3_dlg);
67 	m_tab_vect.push_back(&m_tab4_dlg);
68 	m_tab_vect.push_back(&m_media_lib_dlg);
69 	m_tab_vect.push_back(&m_tab5_dlg);
70 
71 	//获取子对话框的初始高度
72 	for (const auto* pDlg : m_tab_vect)
73 	{
74 		CRect rect;
75 		pDlg->GetWindowRect(rect);
76 		m_tab_height.push_back(rect.Height());
77 	}
78 
79 	//添加对话框
80 	m_tab.AddWindow(&m_tab1_dlg, theApp.m_str_table.LoadText(L"TITLE_OPT_LRC").c_str());
81 	m_tab.AddWindow(&m_tab2_dlg, theApp.m_str_table.LoadText(L"TITLE_OPT_APC").c_str());
82 	m_tab.AddWindow(&m_tab3_dlg, theApp.m_str_table.LoadText(L"TITLE_OPT_DATA").c_str());
83 	m_tab.AddWindow(&m_tab4_dlg, theApp.m_str_table.LoadText(L"TITLE_OPT_PLAY").c_str());
84 	m_tab.AddWindow(&m_media_lib_dlg, theApp.m_str_table.LoadText(L"TITLE_OPT_MEDIA_LIB").c_str());
85 	m_tab.AddWindow(&m_tab5_dlg, theApp.m_str_table.LoadText(L"TITLE_OPT_HOT_KEY").c_str());
86 
87     //为每个标签添加图标
88     CImageList ImageList;
89     ImageList.Create(theApp.DPI(16), theApp.DPI(16), ILC_COLOR32 | ILC_MASK, 2, 2);
90     ImageList.Add(theApp.m_icon_set.lyric.GetIcon(true));
91     ImageList.Add(theApp.m_icon_set.skin.GetIcon(true));
92     ImageList.Add(theApp.m_icon_set.setting.GetIcon(true));
93     ImageList.Add(theApp.m_icon_set.play_new.GetIcon(true));
94     ImageList.Add(theApp.m_icon_set.media_lib.GetIcon(true));
95     ImageList.Add(theApp.m_icon_set.hot_key);
96     m_tab.SetImageList(&ImageList);
97     ImageList.Detach();
98 
99     m_tab.SetItemSize(CSize(theApp.DPI(60), theApp.DPI(24)));
100     m_tab.AdjustTabWindowSize();
101 
102 	//为每个子窗口设置滚动信息
103 	for (size_t i = 0; i < m_tab_vect.size(); i++)
104 	{
105 		m_tab_vect[i]->SetScrollbarInfo(m_tab.m_tab_rect.Height(), m_tab_height[i]);
106 	}
107 
108     if (m_tab_selected < 0 || m_tab_selected >= m_tab.GetItemCount())
109         m_tab_selected = 0;
110 	m_tab.SetCurTab(m_tab_selected);
111 
112 	return TRUE;  // return TRUE unless you set the focus to a control
113 				  // 异常: OCX 属性页应返回 FALSE
114 }
115 
116 void COptionsDlg::OnOK()
117 {
118 	// TODO: 在此添加专用代码和/或调用基类
119     for (const auto& tab : m_tab_vect)
120     {
121         tab->GetDataFromUi();
122     }
123 
124 	CBaseDialog::OnOK();
125 }
126 
127 
128 void COptionsDlg::OnBnClickedApplyButton()
129 {
130 	// TODO: 在此添加控件通知处理程序代码
131     for (const auto& tab : m_tab_vect)
132     {
133         tab->GetDataFromUi();
134     }
135 
136 	::SendMessage(theApp.m_pMainWnd->GetSafeHwnd(), WM_SETTINGS_APPLIED, (WPARAM)this, 0);
137 
138     for (const auto& tab : m_tab_vect)
139     {
140         tab->ApplyDataToUi();
141     }
142 }
143 
144 
145 void COptionsDlg::OnDestroy()
146 {
147 	CBaseDialog::OnDestroy();
148 
149 	// TODO: 在此处添加消息处理程序代码
150 	m_tab_selected = m_tab.GetCurSel();
151 }
152 
153 
154 void COptionsDlg::OnSize(UINT nType, int cx, int cy)
155 {
156     CBaseDialog::OnSize(nType, cx, cy);
157     if (nType != SIZE_MINIMIZED)
158     {
159         //为每个子窗口设置滚动信息
160         for (size_t i = 0; i < m_tab_vect.size(); i++)
161         {
162             m_tab_vect[i]->ResetScroll();
163             m_tab_vect[i]->SetScrollbarInfo(m_tab.m_tab_rect.Height(), m_tab_height[i]);
164         }
165 
166     }
167 
168     // TODO: 在此处添加消息处理程序代码
169 }
170