-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathWAS_CustomControl.cpp
More file actions
97 lines (79 loc) · 2.05 KB
/
WAS_CustomControl.cpp
File metadata and controls
97 lines (79 loc) · 2.05 KB
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
#include "WAS_CustomControl.hpp"
#include "NE_Debug.hpp"
#include <vector>
#include <algorithm>
namespace WAS
{
class StaticWindowRegistrator
{
public:
StaticWindowRegistrator () :
classNames ()
{
}
~StaticWindowRegistrator ()
{
for (const std::wstring& className : classNames) {
bool unregResult = UnregisterClass (className.c_str (), NULL);
if (DBGERROR (!unregResult)) {
continue;
}
}
classNames.clear ();
}
bool RegisterWindowClass (WNDPROC windowProc, LPCWSTR className)
{
if (std::find (classNames.begin (), classNames.end (), className) != classNames.end ()) {
return true;
}
WNDCLASSEX windowClass;
ZeroMemory (&windowClass, sizeof (WNDCLASSEX));
windowClass.cbSize = sizeof (WNDCLASSEX);
windowClass.style = CS_DBLCLKS;
windowClass.lpfnWndProc = windowProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = NULL;
windowClass.hCursor = LoadCursor (NULL, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH) COLOR_WINDOW;
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = className;
ATOM atom = RegisterClassEx (&windowClass);
if (DBGERROR (atom == 0)) {
return false;
}
classNames.push_back (className);
return true;
}
private:
std::vector<std::wstring> classNames;
};
static StaticWindowRegistrator windowRegistrator;
CustomControl::CustomControl () :
windowClassName (),
windowHandle (NULL)
{
}
CustomControl::~CustomControl ()
{
}
bool CustomControl::Init (HWND parentHandle, WNDPROC windowProc, LPCWSTR className, LPVOID lParam)
{
bool windowRegistered = windowRegistrator.RegisterWindowClass (windowProc, className);
if (DBGERROR (!windowRegistered)) {
return false;
};
windowClassName = className;
windowHandle = CreateWindowEx (
0, windowClassName.c_str (), L"", WS_CHILD | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parentHandle, NULL, NULL, lParam
);
ShowWindow (windowHandle, SW_SHOW);
UpdateWindow (windowHandle);
return true;
}
HWND CustomControl::GetWindowHandle () const
{
return windowHandle;
}
}