/****************************************************************************************** * Chili Direct3D Engine * * Copyright 2018 PlanetChili * * * * This file is part of Chili Direct3D Engine. * * * * Chili Direct3D Engine is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * The Chili Direct3D Engine is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with The Chili Direct3D Engine. If not, see . * ******************************************************************************************/ #pragma once #include "ChiliWin.h" #include "ChiliException.h" class Window { public: class Exception : public ChiliException { public: Exception(int line, const char* file, HRESULT hr) noexcept; const char* what() const noexcept override; virtual const char* GetType() const noexcept; static std::string TranslateErrorCode(HRESULT hr) noexcept; HRESULT GetErrorCode() const noexcept; std::string GetErrorString() const noexcept; private: HRESULT hr; }; private: // singleton manages registration/cleanup of window class class WindowClass { public: static const char* GetName() noexcept; static HINSTANCE GetInstance() noexcept; private: WindowClass() noexcept; ~WindowClass(); WindowClass(const WindowClass&) = delete; WindowClass& operator=(const WindowClass&) = delete; static constexpr const char* wndClassName = "Chili Direct3D Engine Window"; static WindowClass wndClass; HINSTANCE hInst; }; public: Window(int width, int height, const char* name); ~Window(); Window(const Window&) = delete; Window& operator=(const Window&) = delete; private: static LRESULT CALLBACK HandleMsgSetup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept; static LRESULT CALLBACK HandleMsgThunk(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept; LRESULT HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept; private: int width; int height; HWND hWnd; }; // error exception helper macro #define CHWND_EXCEPT( hr ) Window::Exception( __LINE__,__FILE__,hr ) #define CHWND_LAST_EXCEPT() Window::Exception( __LINE__,__FILE__,GetLastError() )