-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomEdit.cpp
79 lines (79 loc) · 5.41 KB
/
CustomEdit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// CustomEdit.cpp
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Copyright (c) 2019-2024 Adrian Maurer. All rights reserved.
// Distributed under the MIT software license (http://www.opensource.org/licenses/mit-license.php).
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "pch.h"
#include "framework.h"
#include "CustomEdit.h"
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// CCustomEdit
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// CCustomEdit - MESSAGE MAP FUNCTIONS
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CCustomEdit, CEdit)
ON_WM_KEYDOWN()
ON_WM_CHAR()
ON_WM_CONTEXTMENU()
END_MESSAGE_MAP()
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void CCustomEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (!isLocked())
{
if (nChar == 'A' && HIWORD(::GetKeyState(VK_CONTROL))) SetSel(0, -1);
else CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void CCustomEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (!isLocked()) CEdit::OnChar(nChar, nRepCnt, nFlags);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void CCustomEdit::OnContextMenu(CWnd* pWnd, CPoint pnt)
{
if (!isLocked()) CEdit::OnContextMenu(pWnd, pnt);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// CTextEdit
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// CTextEdit - ELEMENT FUNCTIONS
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void CTextEdit::setText(const std::wstring& t, const bool che)
{
if (!che)
{
changeHandlerEnabled = false;
SetWindowTextW(t.data());
changeHandlerEnabled = true;
}
else
{
SetWindowTextW(t.data());
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
std::wstring CTextEdit::getText() const
{
CString t;
GetWindowTextW(t);
return t.GetString();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// CTextEdit - MESSAGE MAP FUNCTIONS
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CTextEdit, CCustomEdit)
ON_CONTROL_REFLECT_EX(EN_CHANGE, &CTextEdit::OnEnChange)
END_MESSAGE_MAP()
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BOOL CTextEdit::OnEnChange()
{
return !changeHandlerEnabled;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------