forked from BellCrow/GettingInShapes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowClass.cpp
46 lines (38 loc) · 996 Bytes
/
WindowClass.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
#include "WindowClass.h"
#include "Window.h"
#include <exception>
#include <ostream>
#include "ErrorTranslator.h"
#include <strstream>
HINSTANCE WindowClass::hInst;
WindowClass WindowClass::instance;
const char* WindowClass::GetWindowClassName() noexcept
{
return wndClassName;
}
HINSTANCE WindowClass::GetInstance() noexcept
{
return hInst;
}
WindowClass::WindowClass()
{
hInst = GetModuleHandle(nullptr);
WNDCLASSEX wndClass = { 0 };
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.style = CS_OWNDC;
wndClass.hInstance = GetInstance();
wndClass.lpfnWndProc = Window::InitialMessageHandler;
wndClass.lpszClassName = GetWindowClassName();
if (RegisterClassEx(&wndClass) == 0)
{
std::strstream str;
str << "Error registering windowclass" << std::endl << ErrorTranslator::TranslateError(GetLastError());
throw std::exception(str.str());
}
}
WindowClass::~WindowClass() noexcept
{
UnregisterClass(wndClassName, hInst);
}