xref: /MusicPlayer2/MusicPlayer2/FlacEncodeCfgDlg.cpp (revision efa1d0897b9345534278c9698b4ed576dd1e4e24)
1 // FlacEncodeCfgDlg.cpp: 实现文件
2 //
3 
4 #include "stdafx.h"
5 #include "MusicPlayer2.h"
6 #include "FlacEncodeCfgDlg.h"
7 
8 
9 // CFlacEncodeCfgDlg 对话框
10 
IMPLEMENT_DYNAMIC(CFlacEncodeCfgDlg,CDialog)11 IMPLEMENT_DYNAMIC(CFlacEncodeCfgDlg, CDialog)
12 
13 CFlacEncodeCfgDlg::CFlacEncodeCfgDlg(CWnd* pParent /*=nullptr*/)
14     : CBaseDialog(IDD_FLAC_ENCODE_CFG_DIALOG, pParent)
15 {
16 
17 }
18 
~CFlacEncodeCfgDlg()19 CFlacEncodeCfgDlg::~CFlacEncodeCfgDlg()
20 {
21 }
22 
GetDialogName() const23 CString CFlacEncodeCfgDlg::GetDialogName() const
24 {
25     return CString();
26 }
27 
InitializeControls()28 bool CFlacEncodeCfgDlg::InitializeControls()
29 {
30     wstring temp;
31     temp = theApp.m_str_table.LoadText(L"TITLE_ENCODE_OPT_FLAC");
32     SetWindowTextW(temp.c_str());
33     temp = theApp.m_str_table.LoadText(L"TXT_ENCODE_OPT_FLAC_CMP_LEVEL");
34     SetDlgItemTextW(IDC_TXT_ENCODE_OPT_FLAC_CMP_LEVEL_STATIC, temp.c_str());
35     // IDC_SLIDER1
36     // IDC_COMP_LEVEL_STATIC
37     temp = theApp.m_str_table.LoadText(L"TXT_ENCODE_OPT_FLAC_CMP_LEVEL_LOW");
38     SetDlgItemTextW(IDC_TXT_ENCODE_OPT_FLAC_CMP_LEVEL_LOW_STATIC, temp.c_str());
39     temp = theApp.m_str_table.LoadText(L"TXT_ENCODE_OPT_FLAC_CMP_LEVEL_HIGH");
40     SetDlgItemTextW(IDC_TXT_ENCODE_OPT_FLAC_CMP_LEVEL_HIGH_STATIC, temp.c_str());
41     temp = theApp.m_str_table.LoadText(L"TXT_ENCODE_OPT_FLAC_SPECIFY_PARA");
42     SetDlgItemTextW(IDC_SPECIFY_PARA_CHECK, temp.c_str());
43     // IDC_EDIT1
44     // IDOK
45     // IDCANCEL
46 
47     RepositionTextBasedControls({
48         { CtrlTextInfo::L1, IDC_SPECIFY_PARA_CHECK, CtrlTextInfo::W16 },
49         { CtrlTextInfo::C0, IDC_EDIT1 }
50         }, CtrlTextInfo::W128);
51     RepositionTextBasedControls({
52         { CtrlTextInfo::R1, IDOK, CtrlTextInfo::W32 },
53         { CtrlTextInfo::R2, IDCANCEL, CtrlTextInfo::W32 }
54         });
55     return true;
56 }
57 
DoDataExchange(CDataExchange * pDX)58 void CFlacEncodeCfgDlg::DoDataExchange(CDataExchange* pDX)
59 {
60     CBaseDialog::DoDataExchange(pDX);
61     DDX_Control(pDX, IDC_SLIDER1, m_comp_level_slider);
62 }
63 
SetInfoText()64 void CFlacEncodeCfgDlg::SetInfoText()
65 {
66     wstring comp_level = std::to_wstring(m_encode_para.compression_level);
67     SetDlgItemTextW(IDC_COMP_LEVEL_STATIC, comp_level.c_str());
68 
69     //设置编码参数
70     if (!m_encode_para.user_define_para)
71         m_encode_para.cmd_para = L"-" + comp_level;
72     SetDlgItemTextW(IDC_EDIT1, m_encode_para.cmd_para.c_str());
73 }
74 
EnableControl()75 void CFlacEncodeCfgDlg::EnableControl()
76 {
77     EnableDlgCtrl(IDC_SLIDER1, !m_encode_para.user_define_para);
78     EnableDlgCtrl(IDC_EDIT1, m_encode_para.user_define_para);
79 }
80 
81 
BEGIN_MESSAGE_MAP(CFlacEncodeCfgDlg,CBaseDialog)82 BEGIN_MESSAGE_MAP(CFlacEncodeCfgDlg, CBaseDialog)
83     ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER1, &CFlacEncodeCfgDlg::OnNMCustomdrawSlider1)
84     ON_BN_CLICKED(IDC_SPECIFY_PARA_CHECK, &CFlacEncodeCfgDlg::OnBnClickedSpecifyParaCheck)
85 END_MESSAGE_MAP()
86 
87 
88 // CFlacEncodeCfgDlg 消息处理程序
89 
90 
91 BOOL CFlacEncodeCfgDlg::OnInitDialog()
92 {
93     CBaseDialog::OnInitDialog();
94 
95     // TODO:  在此添加额外的初始化
96     m_comp_level_slider.SetRange(0, 8);
97     m_comp_level_slider.SetPos(m_encode_para.compression_level);
98     SetInfoText();
99     CheckDlgButton(IDC_SPECIFY_PARA_CHECK, m_encode_para.user_define_para);
100     EnableControl();
101 
102     return TRUE;  // return TRUE unless you set the focus to a control
103                   // 异常: OCX 属性页应返回 FALSE
104 }
105 
106 
OnNMCustomdrawSlider1(NMHDR * pNMHDR,LRESULT * pResult)107 void CFlacEncodeCfgDlg::OnNMCustomdrawSlider1(NMHDR* pNMHDR, LRESULT* pResult)
108 {
109     LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
110     // TODO: 在此添加控件通知处理程序代码
111     m_encode_para.compression_level = m_comp_level_slider.GetPos();
112     SetInfoText();
113     *pResult = 0;
114 }
115 
116 
OnBnClickedSpecifyParaCheck()117 void CFlacEncodeCfgDlg::OnBnClickedSpecifyParaCheck()
118 {
119     // TODO: 在此添加控件通知处理程序代码
120     m_encode_para.user_define_para = (IsDlgButtonChecked(IDC_SPECIFY_PARA_CHECK) != 0);
121     SetInfoText();
122     EnableControl();
123 }
124 
125 
OnOK()126 void CFlacEncodeCfgDlg::OnOK()
127 {
128     // TODO: 在此添加专用代码和/或调用基类
129     CString str;
130     GetDlgItemText(IDC_EDIT1, str);
131     m_encode_para.cmd_para = str;
132 
133     CBaseDialog::OnOK();
134 }
135