-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomControl.cpp
More file actions
122 lines (102 loc) · 2.85 KB
/
CustomControl.cpp
File metadata and controls
122 lines (102 loc) · 2.85 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// CustomControl.cpp: implementation of the CustomControl class.
//
//////////////////////////////////////////////////////////////////////
#include "CustomControl.h"
//////////////////////////////////////////////////////////////////////
// Statics
//////////////////////////////////////////////////////////////////////
LRESULT CALLBACK CustomControl::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CustomControl *pView = 0;
if( uMsg == WM_NCCREATE )
{
pView = reinterpret_cast<CustomControl *>( ((LPCREATESTRUCT)lParam)->lpCreateParams );
if (pView)
pView->hWnd = hWnd;
::SetWindowLong(hWnd, GWL_USERDATA, reinterpret_cast<long>( pView ));
}
else
{
pView = reinterpret_cast<CustomControl *>( ::GetWindowLong(hWnd, GWL_USERDATA) );
}
if (pView)
return pView->ObjectProc(uMsg, wParam, lParam);
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CustomControl::CustomControl()
{
this->hBackgroundColor = NULL;
this->hCursor = NULL;
this->hIcon = NULL;
this->hSmallIcon = NULL;
}
CustomControl::~CustomControl()
{
}
BOOL CustomControl::InitCustomControl()
{
WNDCLASSEX wsex;
if (!::GetClassInfoEx(::GetModuleHandle(NULL), this->strControlClass, &wsex))
{
wsex.hbrBackground = this->hBackgroundColor;
wsex.hCursor = this->hCursor;
wsex.hIcon = this->hIcon;
wsex.hIconSm = this->hSmallIcon;
wsex.lpszClassName = this->strControlClass;
wsex.cbClsExtra = 0;
wsex.cbSize = sizeof(wsex);
wsex.cbWndExtra = 0;
wsex.hInstance = ::GetModuleHandle(NULL);
wsex.lpfnWndProc = (WNDPROC)WindowProc;
wsex.lpszMenuName = NULL;
wsex.style = CS_HREDRAW | CS_VREDRAW;
return ::RegisterClassEx(&wsex);
}
return TRUE;
}
BOOL CustomControl::Create(HWND hParent, DWORD dwId, DWORD style, DWORD exStyle)
{
if (style != 0)
this->dwStyle = style;
if (exStyle != 0)
this->dwExStyle = exStyle;
this->hParent = hParent;
this->dwId = dwId;
if (InitCustomControl())
{
this->hWnd = ::CreateWindowEx( this->dwExStyle,
this->strControlClass,
this->strTitle,
this->dwStyle,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
this->hParent,
(HMENU) this->dwId,
GetModuleHandle(NULL),
this);
if (this->hWnd)
{
::ShowWindow(this->hWnd, SW_SHOW);
::UpdateWindow(this->hWnd);
return TRUE;
}
else
{
AddError("CustomControl::Create() - Aan maken van de window is niet gelukt");
}
}
else
{
AddError("CustomControl::Create() - Registreren van de windowclass is niet gelukt");
}
return FALSE;
}
LRESULT CustomControl::ObjectProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(this->hWnd, uMsg, wParam, lParam);
}