1 #include "stdafx.h"
2 #include "MyComboBox.h"
3 #include "MusicPlayer2.h"
4
IMPLEMENT_DYNAMIC(CMyComboBox,CComboBox)5 IMPLEMENT_DYNAMIC(CMyComboBox, CComboBox)
6
7 CMyComboBox::CMyComboBox()
8 {
9 }
10
11
~CMyComboBox()12 CMyComboBox::~CMyComboBox()
13 {
14 }
15
SetReadOnly(bool read_only)16 void CMyComboBox::SetReadOnly(bool read_only)
17 {
18 CEdit* pEdit = GetEditCtrl();
19 if (pEdit != nullptr)
20 pEdit->SetReadOnly(read_only); //将Endit控件设为只读
21 m_read_only = read_only;
22 }
23
SetEditReadOnly(bool read_only)24 void CMyComboBox::SetEditReadOnly(bool read_only)
25 {
26 CEdit* pEdit = GetEditCtrl();
27 if (pEdit != nullptr)
28 pEdit->SetReadOnly(read_only); //将Endit控件设为只读
29 }
30
GetEditCtrl()31 CEdit* CMyComboBox::GetEditCtrl()
32 {
33 return (CEdit*)GetWindow(GW_CHILD);
34 }
35
GetText()36 CString CMyComboBox::GetText()
37 {
38 CString str;
39 GetWindowText(str);
40 return str;
41 }
42
ResetModified()43 void CMyComboBox::ResetModified()
44 {
45 m_modified = false;
46
47 CEdit* pEdit = GetEditCtrl();
48 if (pEdit != nullptr)
49 pEdit->SetModify(FALSE);
50
51 Invalidate(FALSE);
52 }
53
SetModify()54 void CMyComboBox::SetModify()
55 {
56 m_modified = true;
57
58 CEdit* pEdit = GetEditCtrl();
59 if (pEdit != nullptr)
60 pEdit->SetModify(TRUE);
61
62 Invalidate(FALSE);
63 }
64
SetMouseWheelEnable(bool enable)65 void CMyComboBox::SetMouseWheelEnable(bool enable)
66 {
67 m_mouse_wheel_enable = enable;
68 }
69
BEGIN_MESSAGE_MAP(CMyComboBox,CComboBox)70 BEGIN_MESSAGE_MAP(CMyComboBox, CComboBox)
71 ON_WM_CTLCOLOR()
72 ON_CONTROL_REFLECT_EX(CBN_SELCHANGE, &CMyComboBox::OnCbnSelchange)
73 ON_MESSAGE(WM_TABLET_QUERYSYSTEMGESTURESTATUS, &CMyComboBox::OnTabletQuerysystemgesturestatus)
74 END_MESSAGE_MAP()
75
76
77
78 BOOL CMyComboBox::PreTranslateMessage(MSG* pMsg)
79 {
80 // TODO: 在此添加专用代码和/或调用基类
81 if (m_read_only)
82 {
83 if (pMsg->message == WM_MOUSEWHEEL) //如果只读,则不响应鼠标滚轮消息
84 return TRUE;
85 if (pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_LBUTTONDBLCLK || pMsg->message == WM_MOUSEMOVE || pMsg->message == WM_LBUTTONUP)
86 {
87 CPoint point1 = pMsg->pt;
88 CPoint point;
89 GetCursorPos(&point);
90 //获取箭头区域的位置
91 GetWindowRect(m_arrow_rect);
92 m_arrow_rect.left = m_arrow_rect.right - theApp.DPI(18);
93 if(m_arrow_rect.PtInRect(point)) //如果鼠标指针的位置位于箭头区域,则不响应以上的鼠标消息
94 return TRUE;
95 }
96 }
97
98 //如果m_mouse_wheel_enable为false,则不响应鼠标滚轮消息
99 if (pMsg->message == WM_MOUSEWHEEL && !m_mouse_wheel_enable)
100 {
101 //将鼠标滚轮消息发送给父窗口
102 CWnd* pParent = GetParent();
103 pParent->SendMessage(WM_MOUSEWHEEL, pMsg->wParam, pMsg->lParam);
104 return true;
105 }
106
107 return CComboBox::PreTranslateMessage(pMsg);
108 }
109
110
OnCtlColor(CDC * pDC,CWnd * pWnd,UINT nCtlColor)111 HBRUSH CMyComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
112 {
113 HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
114
115 // TODO: 在此更改 DC 的任何特性
116 CEdit* pEdit = GetEditCtrl();
117 if (pEdit != nullptr)
118 {
119 DWORD style = pEdit->GetStyle();
120 bool is_read_only = ((style & ES_READONLY) != 0);
121 if ((pEdit->GetModify() || m_modified) && !is_read_only)
122 pDC->SetTextColor(theApp.m_app_setting_data.theme_color.dark1); //如果文本已修改,则显示为主题色
123 }
124
125 // TODO: 如果默认的不是所需画笔,则返回另一个画笔
126 return hbr;
127 }
128
129
OnCbnSelchange()130 BOOL CMyComboBox::OnCbnSelchange()
131 {
132 // TODO: 在此添加控件通知处理程序代码
133 m_modified = true;
134 return FALSE;
135 }
136
137
OnTabletQuerysystemgesturestatus(WPARAM wParam,LPARAM lParam)138 afx_msg LRESULT CMyComboBox::OnTabletQuerysystemgesturestatus(WPARAM wParam, LPARAM lParam)
139 {
140 return 0;
141 }
142