aboutsummaryrefslogtreecommitdiff
path: root/src/win/gui/WindowClass.cpp
blob: a033d091e9515080d8ab3ea12700ab0965133f65 (plain)
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
#include "cru/win/gui/WindowClass.hpp"

#include "cru/win/gui/Exception.hpp"

namespace cru::platform::gui::win {
WindowClass::WindowClass(std::wstring name, WNDPROC window_proc,
                         HINSTANCE h_instance)
    : name_(std::move(name)) {
  WNDCLASSEXW window_class;
  window_class.cbSize = sizeof(WNDCLASSEXW);

  window_class.style = CS_HREDRAW | CS_VREDRAW;
  window_class.lpfnWndProc = window_proc;
  window_class.cbClsExtra = 0;
  window_class.cbWndExtra = 0;
  window_class.hInstance = h_instance;
  window_class.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  window_class.hCursor = LoadCursor(NULL, IDC_ARROW);
  window_class.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
  window_class.lpszMenuName = NULL;
  window_class.lpszClassName = name_.c_str();
  window_class.hIconSm = NULL;

  atom_ = ::RegisterClassExW(&window_class);
  if (atom_ == 0)
    throw Win32Error(::GetLastError(), "Failed to create window class.");
}
}  // namespace cru::platform::gui::win