-
Notifications
You must be signed in to change notification settings - Fork 19
/
EditDoubleClick.cpp
101 lines (81 loc) · 2.89 KB
/
EditDoubleClick.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// sktoolslib - common files for SK tools
// Copyright (C) 2012-2013, 2020-2021 - Stefan Kueng
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#include "stdafx.h"
#include "EditDoubleClick.h"
#define PROP_OBJECT_PTR MAKEINTATOM(ga.atom)
/*
* typedefs
*/
class CGlobalAtom
{
public:
CGlobalAtom()
#ifdef _WIN64
{
atom = GlobalAddAtom(L"_EditDoubleClick_Object_Pointer64_"
L"\\{FDE85769-946B-45EF-866C-B1EA2F26B171}");
}
#else
{
atom = GlobalAddAtom(L"_EditDoubleClick_Object_Pointer_"
L"\\{FDE85769-946B-45EF-866C-B1EA2F26B171}");
}
#endif
~CGlobalAtom()
{
DeleteAtom(atom);
}
ATOM atom;
};
static CGlobalAtom ga;
/////////////////////////////////////////////////////////////////////////////
// CEditDoubleClick
CEditDoubleClick::CEditDoubleClick()
: m_ctrlId(0)
, m_pfnOrigCtlProc(nullptr)
{
}
CEditDoubleClick::~CEditDoubleClick()
{
}
BOOL CEditDoubleClick::Subclass(HWND hwndParent, UINT uiCtlId)
{
m_ctrlId = uiCtlId;
HWND hwndCtl = GetDlgItem(hwndParent, uiCtlId);
// Subclass the existing control.
m_pfnOrigCtlProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hwndCtl, GWLP_WNDPROC));
SetProp(hwndCtl, PROP_OBJECT_PTR, static_cast<HANDLE>(this));
SetWindowLongPtr(hwndCtl, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(EditCtrlWinProc));
return TRUE;
}
LRESULT CALLBACK CEditDoubleClick::EditCtrlWinProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
CEditDoubleClick *pCtrl = static_cast<CEditDoubleClick *>(GetProp(hwnd, PROP_OBJECT_PTR));
switch (message)
{
case WM_LBUTTONDBLCLK:
SendMessage(GetParent(hwnd), WM_EDITDBLCLICK, static_cast<WPARAM>(pCtrl->m_ctrlId), lParam);
break;
case WM_DESTROY:
{
SetWindowLongPtr(hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(pCtrl->m_pfnOrigCtlProc));
RemoveProp(hwnd, PROP_OBJECT_PTR);
}
break;
}
return CallWindowProc(pCtrl->m_pfnOrigCtlProc, hwnd, message,
wParam, lParam);
}