#pragma region Public Domain Code /* This code is in the public domain. You can do whatever you want with it, change it, appropriate it, relicense it, redistribute it, include it in your own libraries and applications, sell it and never mention where you've got it. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #pragma endregion // Public Domain Code #ifndef NUCLEX_GRAPHICS_DEMO_WINDOW_H #define NUCLEX_GRAPHICS_DEMO_WINDOW_H #include #include #define WIN32_LEAN_AND_MEAN #define VC_EXTRALEAN #include namespace Nuclex { namespace Graphics { namespace Demo { // ------------------------------------------------------------------------------------------- // /// Manages a window in a Windows desktop environment class Window { /// Creates a new window /// Handle of the process that owns the window /// Text that will appear in the window's title bar public: Window(HINSTANCE instanceHandle, const std::wstring &title); /// Destroys the window public: ~Window(); /// Retrieves the window's current title /// The current window title public: const std::wstring &GetTitle() const { return this->title; } /// Changes the window's title /// New title that will be assigned to the window public: void SetTitle(const std::wstring &title); /// Whether the window is currently visible /// True if the window was visible public: bool IsVisible() const { return this->isVisible; } /// Displays or hides the window /// Whether the window should be shown or hidden public: void Show(bool visible = true); /// Whether the window was requested to close /// True if the window was reuqested to close public: bool WasCloseRequested() const { return this->wasCloseRequested; } /// Resets the close request flag of the window public: void ResetCloseRequested() { this->wasCloseRequested = false; } /// Retrieves the window's window handle /// The window handle of the window public: HWND GetWindowHandle() const { return this->windowHandle; } /// Retrieves the size and position of the window's drawable area /// The absolute coordinates of the window's client area public: RECT GetViewRectangle() const; /// Changes the size of the window's drawable area /// Desired width of the drawable window area /// Desired height of the drawable window area public: void ResizeViewRectangle(std::size_t width, std::size_t height); /// Moves the window to the center of the primary screen public: void CenterOnPrimaryDisplay(); /// Processes a message sent to the window /// Handle of the window received the message /// Type of message being sent to the window /// First message-dependent parameter /// Second message-dependent parameter protected: virtual LRESULT ProcessMessage( HWND windowHandle, UINT message, WPARAM parameter1, LPARAM parameter2 ); /// Creates the window private: void createWindow(); /// Destroys the window private: void destroyWindow(); /// Registers a window class /// Handle of the application that will own the class /// /// Name of the window class that will be registered /// private: static void registerWindowClass( HINSTANCE instanceHandle, const std::wstring &windowClassName ); /// Unregisters a window class /// Handle of the application that owned the class /// /// Name of the window class that will be unregistered /// private: static void unregisterWindowClass( HINSTANCE instanceHandle, const std::wstring &windowClassName ); /// Builds an id that is unique for an instance of the class /// A unique id for the instance private: std::wstring getWindowClassName() const; /// Message procedure used to intercept messages to the game's window /// Handle of the window received the message /// Type of message being sent to the window /// First message-dependent parameter /// Second message-dependent parameter private: static LRESULT CALLBACK windowProcedure( HWND windowHandle, UINT message, WPARAM parameter1, LPARAM parameter2 ); /// Handle of the process that created the window private: HINSTANCE instanceHandle; /// Handle of the window the wrapper is managing private: HWND windowHandle; /// Title of the window private: std::wstring title; /// Whether the window is currently visible private: bool isVisible; /// Whether the window has been requested to close private: bool wasCloseRequested; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Graphics::Demo #endif // NUCLEX_GRAPHICS_DEMO_WINDOW_H