13#pragma warning(disable: 6387)
14#pragma warning(disable: 4312)
16#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
36 if (message == WM_SIZE)
44 resizableComponent->
resize(LOWORD(lparam), HIWORD(lparam));
64 single->setLocalizationKey(localizationKeys.front());
68 for (string_view localizationKey : localizationKeys)
70 multi->addLocalizationKey(localizationKey);
78 windowName(windowName),
80 desiredWidth(settings.width),
81 desiredHeight(settings.height),
84 id(parent ?
GUIFramework::get().generateId(windowName) : NULL),
85 backgroundColor(RGB(255, 255, 255)),
86 textColor(RGB(0, 0, 0))
88 WNDCLASSEXW classStruct = {};
90 const unordered_map<string, HMODULE, localization::utility::StringViewHash, localization::utility::StringViewEqual>& modules =
GUIFramework::get().
getModules();
91 const HMODULE* findedModule =
nullptr;
93 for (
const auto& [moduleName, module] : modules)
95 if (GetClassInfoExW(module,
className.data(), &classStruct))
97 findedModule = &
module;
105 if (windowFunctionName.size())
107 WNDPROC windowFunction =
reinterpret_cast<WNDPROC
>(GetProcAddress(
nullptr, format(
"{}WindowFunction", windowFunctionName).data()));
114 classStruct.cbSize =
sizeof(WNDCLASSEXW);
115 classStruct.lpszClassName =
className.data();
117 classStruct.hCursor = LoadCursorW(
nullptr, IDC_ARROW);
118 classStruct.lpfnWndProc = windowFunction;
119 classStruct.hbrBackground =
reinterpret_cast<HBRUSH
>(COLOR_WINDOW);
121 if (smallIconResource)
123 if (moduleName.size())
125 if (
auto it = modules.find(moduleName); it != modules.end())
131 throw runtime_error(format(
"Can't load small icon resource for {}", moduleName));
140 if (largeIconResources)
142 if (moduleName.size())
144 if (
auto it = modules.find(moduleName); it != modules.end())
150 throw runtime_error(format(
"Can't load large icon resource for {}", moduleName));
159 RegisterClassExW(&classStruct);
166 classStruct.lpszClassName,
168 static_cast<DWORD
>(
styles.getStyles()) |
static_cast<DWORD
>(settings.
styles.
getStyles()) | (
parent ? WS_CHILDWINDOW | WS_BORDER : WS_OVERLAPPEDWINDOW),
174 reinterpret_cast<HMENU
>(
id),
195 topLevelWindow = topLevelWindow->
getParent();
201 ShowWindow(
handle, SW_SHOW);
225 bool result = DestroyWindow(
handle);
231 parentComposite->removeChild(
this);
240 bool result = PostMessageW(
handle, WM_CLOSE, NULL, NULL);
246 parentComposite->removeChild(
this);
255 EnableWindow(
handle,
true);
260 EnableWindow(
handle,
false);
265 return IsWindowEnabled(
handle);
275 return SendMessageW(
handle, message, wparam, lparam);
302 InvalidateRect(
handle,
nullptr,
true);
309 InvalidateRect(
handle,
nullptr,
true);
346 GetClientRect(
handle, &sizes);
348 return static_cast<uint16_t
>(sizes.right - sizes.left);
355 GetClientRect(
handle, &sizes);
357 return static_cast<uint16_t
>(sizes.bottom - sizes.top);
364 GetWindowRect(
handle, &coordinates);
366 MapWindowPoints(HWND_DESKTOP,
parent ?
parent->
getHandle() : HWND_DESKTOP,
reinterpret_cast<POINT*
>(&coordinates), 2);
403 using json::utility::jsonObject;
404 using json::utility::appendArray;
406 uint32_t codepage = ISerializable::getCodepage();
407 json::JSONBuilder builder(codepage);
409 jsonObject structure;
410 vector<jsonObject> backgroundColorJSON;
411 vector<jsonObject> textColorJSON;
412 vector<jsonObject> localizationKeys;
415 appendArray(
static_cast<int64_t
>(GetRValue(
backgroundColor)), backgroundColorJSON);
416 appendArray(
static_cast<int64_t
>(GetGValue(
backgroundColor)), backgroundColorJSON);
417 appendArray(
static_cast<int64_t
>(GetBValue(
backgroundColor)), backgroundColorJSON);
419 appendArray(
static_cast<int64_t
>(GetRValue(
textColor)), textColorJSON);
420 appendArray(
static_cast<int64_t
>(GetGValue(
textColor)), textColorJSON);
421 appendArray(
static_cast<int64_t
>(GetBValue(
textColor)), textColorJSON);
425 structure.data.push_back({
"hash"s, this->
getHash() });
427 structure.data.push_back({
"desiredX"s,
desiredX });
428 structure.data.push_back({
"desiredY"s,
desiredY });
430 structure.data.push_back({
"desiredWidth"s,
static_cast<uint64_t
>(
desiredWidth) });
431 structure.data.push_back({
"desiredHeight"s,
static_cast<uint64_t
>(
desiredHeight) });
433 structure.data.push_back({
"backgroundColor"s, move(backgroundColorJSON) });
434 structure.data.push_back({
"textColor"s, move(textColorJSON) });
441 structure.data.push_back({
"styles"s,
styles->getStyles() });
443 structure.data.push_back({
"extendedStyles"s,
styles->getExtendedStyles() });
447 appendArray(single->getLocalizationKey(), localizationKeys);
451 for (
const string& localizationKey : multiple->getLocalizationKeys())
453 appendArray(localizationKey, localizationKeys);
457 if (localizationKeys.size())
459 structure.data.push_back({
"localizationKeys"s, move(localizationKeys) });
478 catch (
const exception&)
std::unique_ptr< T > smartPointerType
Compatible smart pointer type.
Base class for all windows, controls, etc.
uint16_t getDesiredHeight() const
void setDesiredHeight(uint16_t desiredHeight)
std::wstring_view getWindowName() const
virtual void setLocalizationKeys(interfaces::ITextLocalized *localized, const std::vector< std::string > &localizationKeys)
Override for custom localization.
void setDesiredWidth(uint16_t desiredWidth)
bool asyncDestroyComponent()
uint16_t getDesiredWidth() const
void setDesiredY(int desiredY)
virtual LRESULT windowMessagesHandle(HWND handle, UINT message, WPARAM wparam, LPARAM lparam, bool &isUsed)
const std::wstring className
virtual size_t getHash() const =0
Used as key in creators.
COLORREF getTextColor() const
virtual json::JSONBuilder getStructure() const override
LRESULT handleMessages(HWND handle, UINT message, WPARAM wparam, LPARAM lparam, bool &isUsed)
virtual void setTextColor(uint8_t red, uint8_t green, uint8_t blue)
virtual LRESULT preWindowMessagesHandle(HWND handle, UINT message, WPARAM wparam, LPARAM lparam, bool &isUsed)
uint16_t getActualHeight() const
RECT getActualCoordinates() const
const std::wstring windowName
const smartPointerType< interfaces::IStyles > & getStyles() const
BaseComponent(std::wstring_view className, std::wstring_view windowName, const utility::ComponentSettings &settings, const interfaces::IStyles &styles, BaseComposite *parent=nullptr, std::string_view windowFunctionName="", std::string_view moduleName="", uint16_t smallIconResource=NULL, uint16_t largeIconResource=NULL)
static void runFunctionAsync(const std::function< void()> &callable, const std::function< void()> &callback=nullptr) noexcept
Add task to thread pool.
BaseComponent * getParent() const
COLORREF getBackgroundColor() const
virtual void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue)
uint16_t getActualWidth() const
void setDesiredX(int desiredX)
smartPointerType< interfaces::IStyles > styles
LRESULT sendRawMessage(UINT message, WPARAM wparam, LPARAM lparam)
SendMessage WinAPI wrapper.
std::wstring_view getClassName() const
Base class for all windows that has children windows.
Singleton with GUIFramework settings and some functionality.
const std::unordered_map< std::string, HMODULE, localization::utility::StringViewHash, localization::utility::StringViewEqual > & getModules() const
Get all loaded modules.
std::unique_ptr< threading::Future > addTask(const std::function< void()> &task, const std::function< void()> &callback=nullptr)
Add task to thread pool. Thread safe method.
static GUIFramework & get()
Singleton instance access.
Can't find CREATE_DEFAULT_WINDOW_FUNCTION macro for specific window.
Change localization of combo boxes, list views, tab controls, etc.
Provides resize, setBlockResize, getBlockResize methods.
virtual void resize(uint16_t width, uint16_t height)
Resize component.
virtual bool getBlockResize() const final
Change localization of buttons, edit controls, etc.
Provides styles for other classes.
virtual LONG_PTR getStyles() const final
virtual LONG_PTR getExtendedStyles() const final
Provides changing localization in component by calling GUIFramework::changeLocalization.
virtual bool updateLocalizationEvent()=0
Provides setText and getText methods.
virtual std::wstring getText() const final
Get text from control.
constexpr uint32_t initTopLevelWindowPointer
WPARAM contains BaseComposite*.
const uint16_t largeIconHeight
const uint16_t smallIconWidth
const uint16_t smallIconHeight
const uint16_t largeIconWidth
HMODULE getCurrentModule()
Get handle to current executable.
smartPointerType< T > make_smart_pointer(Args &&... args)
Make function with current build configuration compatibility.
string to_string(wstring_view stringToConvert, uint32_t codepage)
All settings for windows.
interfaces::IStyles styles
std::vector< std::string > localizationKeys