10
10
template <class T >
11
11
class BaseWindow
12
12
{
13
+
13
14
public:
15
+ enum StatusCode {
16
+ Null,
17
+ Initializing,
18
+ InitiailizationFailed,
19
+ Running,
20
+ Closing
21
+ };
22
+
14
23
static LRESULT CALLBACK sWindowProc (HWND, UINT, WPARAM, LPARAM);
15
24
static const bool FULL_SCREEN;
16
25
static const bool VSYNC_ENABLED;
17
26
static const float SCREEN_DEPTH;
18
27
static const float SCREEN_NEAR;
19
28
20
- BaseWindow () : mWnd (NULL ) {}
29
+ BaseWindow (HINSTANCE hInstance)
30
+ : mWnd (NULL )
31
+ , mhInstance(hInstance)
32
+ , mStatusCode (StatusCode::Null)
33
+ {}
34
+ virtual ~BaseWindow () {}
21
35
bool Create (
22
- PCWSTR lpWindowName,
36
+ LPCWSTR lpWindowName,
23
37
DWORD dwStyle,
24
38
int & width,
25
39
int & height,
@@ -31,18 +45,16 @@ class BaseWindow
31
45
);
32
46
HWND getHwnd ()const { return mWnd ; }
33
47
34
-
35
-
36
-
37
48
protected:
38
49
void ShutdownWindows ();
39
50
virtual LRESULT HandMessage (UINT uMSG, WPARAM wParam, LPARAM lParam) = 0;
40
- virtual PCWSTR ClassName () const = 0;
51
+ virtual LPCWSTR ClassName () const = 0;
41
52
42
53
HWND mWnd ;
54
+ HINSTANCE mhInstance;
55
+ StatusCode mStatusCode ;
43
56
44
57
private:
45
-
46
58
};
47
59
48
60
@@ -62,7 +74,7 @@ const float BaseWindow<T>::SCREEN_NEAR = 0.1f;
62
74
63
75
template <class T >
64
76
bool BaseWindow<T>::Create(
65
- PCWSTR lpWindowName,
77
+ LPCWSTR lpWindowName,
66
78
DWORD dwStyle,
67
79
int & width,
68
80
int & height,
@@ -72,14 +84,36 @@ bool BaseWindow<T>::Create(
72
84
HWND hWndParent /* = 0*/ ,
73
85
HMENU hMenu /* = 0*/ )
74
86
{
87
+ mStatusCode = Initializing;
75
88
DEVMODE dmScreenSetting;
76
89
77
- WNDCLASS wc = { 0 };
90
+ // This will hold the class we created
91
+ WNDCLASSEX wc = { 0 };
92
+
93
+ // First fill in the window class structure
94
+ wc.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
95
+ // The size, in bytes, of this structure. Set this member to sizeof(WNDCLASSEX). Be sure to set this member before calling the GetClassInfoEx function.
96
+ // The parameter MUST be correct, if not will due window class class cannot be created because the parameter is invalid.
97
+ wc.cbSize = sizeof (WNDCLASSEX);
78
98
wc.lpfnWndProc = T::sWindowProc ;
79
99
wc.hInstance = GetModuleHandle (NULL );
80
100
wc.lpszClassName = ClassName ();
81
-
82
- RegisterClass (&wc);
101
+ wc.hbrBackground = (HBRUSH)GetStockObject (BLACK_BRUSH);
102
+ // wc.hIcon = LoadIcon(mhInstance, L"ScaffoldLogo");
103
+ // wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
104
+ // wc.hIconSm = LoadIcon(mhInstance, L"ScaffoldLogo");
105
+ // wc.hIconSm = LoadIcon(nullptr, IDI_APPLICATION);
106
+
107
+ // If the function succeeds, the return value is a class atom that uniquely identifies the class being registered.
108
+ // This atom can only be used by the CreateWindow, CreateWindowEx, GetClassInfo, GetClassInfoEx, FindWindow, FindWindowEx,
109
+ // and UnregisterClass functions and the IActiveIMMap::FilterClientWindows method.
110
+ // If the function fails, the return value is zero.
111
+ ATOM classAtom = RegisterClassEx (&wc);
112
+ if (classAtom == 0 )
113
+ {
114
+ mStatusCode = StatusCode::InitiailizationFailed;
115
+ return false ;
116
+ }
83
117
84
118
width = GetSystemMetrics (SM_CXSCREEN);
85
119
height = GetSystemMetrics (SM_CYSCREEN);
@@ -121,7 +155,8 @@ bool BaseWindow<T>::Create(
121
155
this
122
156
);
123
157
if (!mWnd )
124
- {
158
+ {
159
+ mStatusCode = StatusCode::InitiailizationFailed;
125
160
return false ;
126
161
}
127
162
ShowWindow (mWnd , SW_SHOW);
@@ -156,6 +191,7 @@ void BaseWindow<T>::ShutdownWindows()
156
191
template <class T >
157
192
LRESULT BaseWindow<T>::sWindowProc (HWND hwnd, UINT uMSG, WPARAM wParam, LPARAM lParam)
158
193
{
194
+
159
195
static T* pThis = NULL ;
160
196
161
197
if (uMSG == WM_NCCREATE)
0 commit comments