GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
BaseSeparateWindow.cpp
Go to the documentation of this file.
2
3#include "GUIFramework.h"
4
8
9using namespace std;
10
11namespace gui_framework
12{
13 BaseSeparateWindow::BaseSeparateWindow(const wstring& className, const wstring& titleName, const utility::ComponentSettings& settings, const string& windowFunctionName, bool maximize, bool minimize, const string& moduleName, uint16_t smallIconResource, uint16_t largeIconResource) :
15 (
16 className,
17 titleName,
18 settings,
19 styles::SeparateWindowStyles(maximize, minimize),
20 nullptr,
21 windowFunctionName,
22 moduleName,
23 smallIconResource,
24 largeIconResource
25 ),
26 ICloseable(handle),
27 IResizableComponent
28 (
29 handle,
30 nullptr
31 ),
32 largeIcon(nullptr),
33 smallIcon(nullptr)
34 {
35
36 }
37
44
51
52 void BaseSeparateWindow::setLargeIcon(const filesystem::path& pathToLargeIcon)
53 {
54 if (!filesystem::exists(pathToLargeIcon))
55 {
56 throw exceptions::FileDoesNotExist(pathToLargeIcon, __FILE__, __FUNCTION__, __LINE__);
57 }
58
59 this->pathToLargeIcon = pathToLargeIcon;
60
61 if (largeIcon)
62 {
63 DestroyIcon(largeIcon);
64
65 largeIcon = nullptr;
66 }
67
68 largeIcon = static_cast<HICON>(LoadImageW(nullptr, pathToLargeIcon.wstring().data(), IMAGE_ICON, standard_sizes::largeIconWidth, standard_sizes::largeIconHeight, LR_LOADFROMFILE));
69
70 SendMessageW(handle, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(largeIcon));
71 }
72
73 void BaseSeparateWindow::setSmallIcon(const filesystem::path& pathToSmallIcon)
74 {
75 if (!filesystem::exists(pathToSmallIcon))
76 {
77 throw exceptions::FileDoesNotExist(pathToSmallIcon, __FILE__, __FUNCTION__, __LINE__);
78 }
79
80 this->pathToSmallIcon = pathToSmallIcon;
81
82 if (smallIcon)
83 {
84 DestroyIcon(smallIcon);
85
86 smallIcon = nullptr;
87 }
88
89 smallIcon = static_cast<HICON>(LoadImageW(nullptr, pathToSmallIcon.wstring().data(), IMAGE_ICON, standard_sizes::smallIconWidth, standard_sizes::smallIconHeight, LR_LOADFROMFILE));
90
91 SendMessageW(handle, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(smallIcon));
92 }
93
94 json::JSONBuilder BaseSeparateWindow::getStructure() const
95 {
96 using json::utility::jsonObject;
97
98 json::JSONBuilder builder = BaseWindow::getStructure();
99 jsonObject& current = get<jsonObject>(builder[utility::to_string(windowName, ISerializable::getCodepage())]);
100
101 if (!pathToSmallIcon.empty())
102 {
103 current.data.push_back({ "pathToSmallIcon"s, utility::getStringFromRawPath(pathToSmallIcon) });
104 }
105
106 if (!pathToLargeIcon.empty())
107 {
108 current.data.push_back({ "pathToLargeIcon"s, utility::getStringFromRawPath(pathToLargeIcon) });
109 }
110
111 if (onCloseFunctionName.size())
112 {
113 current.data.push_back({ "onCloseFunctionName"s, onCloseFunctionName });
114 current.data.push_back({ "onCloseFunctionModuleName"s, onCloseFunctionModuleName });
115 }
116
117 return builder;
118 }
119
121 {
122 DestroyIcon(largeIcon);
123 DestroyIcon(smallIcon);
124 }
125}
const std::wstring windowName
virtual json::JSONBuilder getStructure() const override
void enableResize()
Enable resize button and window resizing.
void disableResize()
Disable resize button and window resizing.
void setSmallIcon(const std::filesystem::path &pathToSmallIcon)
Set small icon(16x16) for specific window.
BaseSeparateWindow(const std::wstring &className, const std::wstring &titleName, const utility::ComponentSettings &settings, const std::string &windowFunctionName, bool maximize=false, bool minimize=false, const std::string &moduleName="", uint16_t smallIconResource=NULL, uint16_t largeIconResource=NULL)
void setLargeIcon(const std::filesystem::path &pathToLargeIcon)
Set large icon(32x32) for specific window.
Base class for composite windows.
Definition BaseWindow.h:13
virtual json::JSONBuilder getStructure() const override
Throws by asset finding methods.
string getStringFromRawPath(const filesystem::path &pathFromRawString)
Definition Utility.cpp:124
void removeStyle(HWND handle, LONG_PTR styleToRemove)
Remove WinAPI style.
Definition Utility.cpp:31
void appendStyle(HWND handle, LONG_PTR newStyle)
Append WinAPI style.
Definition Utility.cpp:21
string to_string(wstring_view stringToConvert, uint32_t codepage)
Definition Utility.cpp:41