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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/// ----------------------------
/// @author God
/// @project Helixirr Widgets
/// @note Windows only
/// ----------------------------
#include <windows.h>
#include <helixirrwidgets/Window.hpp>
using namespace HelixirrWidgets;
/// ----------------------------
/// @class Window
/// @brief Represents a window.
/// ----------------------------
/// Inner classes:
class Window::Helper{
public:
/// Constructors & destructors:
Helper(void) : created_window(false), registered_class_window(false), handle_instance(GetModuleHandle(NULL)), handle_window(nullptr), name_class_window(Window::Helper::_generate_name_class_window()){
}
Helper(Helper const& helper_) : created_window(false), registered_class_window(false), handle_instance(helper_.handle_instance), handle_window(helper_.handle_window), name_class_window(Window::Helper::_generate_name_class_window()), class_window(helper_.class_window){
}
Helper(Helper&& helper_) : created_window(false), registered_class_window(false), handle_instance(std::move(helper_.handle_instance)), handle_window(std::move(helper_.handle_window)), name_class_window(helper_.name_class_window), class_window(std::move(helper_.class_window)){
helper_.handle_instance = nullptr;
helper_.handle_window = nullptr;
}
~Helper(void){
handle_instance = nullptr;
handle_window = nullptr;
}
/// Member data:
bool mutable created_window, registered_class_window;
HINSTANCE mutable handle_instance;
HWND mutable handle_window;
std::string mutable name_class_window;
WNDCLASSEX mutable class_window;
/// Member functions (overloaded operators, assignment):
Helper& operator=(Helper const& helper_){
class_window = helper_.class_window;
created_window = false;
handle_instance = helper_.handle_instance;
handle_window = helper_.handle_window;
name_class_window = helper_.name_class_window;
registered_class_window = false;
return *this;
}
Helper& operator=(Helper&& helper_){
class_window = std::move(helper_.class_window);
created_window = false;
handle_instance = std::move(helper_.handle_instance);
handle_window = std::move(helper_.handle_window);
name_class_window = std::move(helper_.name_class_window);
registered_class_window = false;
return *this;
}
/// Static member functions:
static inline LRESULT CALLBACK handle_callback(HWND handle_window_, UINT message_, WPARAM wparam_, LPARAM lparam_){
return DefWindowProc(handle_window_, message_, wparam_, lparam_);
}
private:
/// Static member functions:
static char const* _generate_name_class_window(void){
static unsigned long long __counter = 125;
auto const __result = __counter % 125;
bool const __exists_remainder = __result;
++__counter;
std::string __name_class_window;
__name_class_window.assign(__result - __exists_remainder, 125);
__name_class_window += static_cast<char>(__result);
return __name_class_window.c_str();
}
};
/// Constructors & destructors:
Window::Window(void) : _m_opHelper(){
}
Window::Window(Window const& window_) = default;
Window::Window(Window&& window_) = default;
Window::Window(std::string const& name_) : _m_bVisible(false), _m_oName(name_){
}
Window::Window(std::string&& name_) : _m_bVisible(false), _m_oName(std::move(name_)){
}
Window::~Window(void) = default;
/// Member functions:
Window& Window::save_changes(void){ /* UNFINISHED! */
// If window class hasn't been created and registered yet:
if(_m_opHelper->registered_class_window){
// Create and register window class:
_m_opHelper->registered_class_window = true;
_m_opHelper->class_window = WNDCLASSEX{
sizeof(WNDCLASSEX),
CS_HREDRAW | CS_VREDRAW,
Window::Helper::handle_callback,
0, 0,
_m_opHelper->handle_instance,
LoadIcon(_m_opHelper->handle_instance, NULL),
LoadCursor(NULL, IDC_ARROW),
reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)),
NULL,
_m_opHelper->name_class_window.c_str(),
LoadIcon(_m_opHelper->handle_instance, NULL)
};
RegisterClassEx(&_m_opHelper->class_window);
}
// If window hasn't been created yet:
if(_m_opHelper->created_window){
_m_opHelper->created_window = true;
_m_opHelper->handle_window = CreateWindow(
_m_opHelper->name_class_window.c_str(),
_m_oName.c_str(),
WS_VISIBLE,
_m_uiPos[0], _m_uiPos[1],
_m_uiSize[0], _m_uiSize[1],
NULL, NULL, _m_opHelper->handle_instance, NULL
);
}
return *this;
}
| |