18 BaseMainWindow::Function::Function(
const string& functionName,
const string& moduleName) :
19 functionName(functionName),
20 moduleName(moduleName)
22 GUIFramework& instance = GUIFramework::get();
23 const HMODULE& module = instance.getModules().at(moduleName);
29 throw exceptions::CantFindFunctionFromModuleException(functionName, moduleName, __FILE__, __FUNCTION__, __LINE__);
35 void BaseMainWindow::onDestroyEvent()
40 void BaseMainWindow::createMarkup()
45 LRESULT BaseMainWindow::windowMessagesHandle(HWND handle, UINT message, WPARAM wparam, LPARAM lparam,
bool& isUsed)
47 LRESULT result = BaseSeparateWindow::windowMessagesHandle(handle, message, wparam, lparam, isUsed);
54 if (message == trayId)
56 switch (LOWORD(lparam))
63 if (!alwaysShowTrayIcon)
65 Shell_NotifyIconW(NIM_DELETE, &tray);
80 TrackPopupMenuEx(trayPopupMenu, TPM_CENTERALIGN, GET_X_LPARAM(wparam), GET_Y_LPARAM(wparam), this->getHandle(),
nullptr);
91 else if (message == WM_COMMAND && popupMenuItems.size())
93 uint32_t
id = LOWORD(wparam);
95 if (
auto it = ranges::find_if(popupMenuItems, [
id](
const pair<uint32_t, Function>& item) {
return item.first == id; }); it != popupMenuItems.end())
99 it->second.callable();
108 BaseMainWindow::BaseMainWindow(
const wstring& className,
const wstring& titleName,
const utility::ComponentSettings& settings,
const string& windowFunctionName, uint16_t trayIconResource,
bool alwaysShowTrayIcon,
bool maximize,
bool minimize,
const string& moduleName, uint16_t smallIconResource, uint16_t largeIconResource) :
122 trayPopupMenu(nullptr),
130 this->
initTray(trayIconResource, alwaysShowTrayIcon);
137 if (!trayIconResource)
142 this->trayIconResource = trayIconResource;
143 this->alwaysShowTrayIcon = alwaysShowTrayIcon;
146 trayPopupMenu = CreatePopupMenu();
148 tray.cbSize =
sizeof(tray);
150 tray.uFlags = NIF_MESSAGE | NIF_ICON;
151 tray.uCallbackMessage = trayId;
152 tray.uVersion = NOTIFYICON_VERSION_4;
158 if (!this->alwaysShowTrayIcon)
160 Shell_NotifyIconW(NIM_ADD, &tray);
162 Shell_NotifyIconW(NIM_SETVERSION, &tray);
175 Shell_NotifyIconW(NIM_DELETE, &tray);
181 LoadIconMetric(GetModuleHandleW(
nullptr), MAKEINTRESOURCE(trayIconResource), _LI_METRIC::LIM_LARGE, &tray.hIcon);
183 if (alwaysShowTrayIcon)
185 Shell_NotifyIconW(NIM_DELETE, &tray);
187 Shell_NotifyIconW(NIM_ADD, &tray);
189 Shell_NotifyIconW(NIM_SETVERSION, &tray);
200 uint32_t
id = popupMenuItems.emplace_back(
GUIFramework::get().generateTrayId(), onClick).first;
207 AppendMenuW(trayPopupMenu, MF_STRING,
id, text.data());
219 uint32_t
id = popupMenuItems.emplace_back(
GUIFramework::get().generateTrayId(), Function(functionName, moduleName)).first;
226 AppendMenuW(trayPopupMenu, MF_STRING,
id, text.data());
238 for (
size_t i = 0; i < popupMenuItems.size(); i++)
240 MENUITEMINFOW info = {};
242 info.cbSize =
sizeof(info);
243 info.fMask = MIIM_STRING;
245 GetMenuItemInfoW(trayPopupMenu,
static_cast<uint32_t
>(i),
true, &info);
247 if (info.dwTypeData && info.dwTypeData == text)
249 popupMenuItems.erase(popupMenuItems.begin() + i);
251 DeleteMenu(trayPopupMenu,
static_cast<uint32_t
>(i), MF_BYPOSITION);
272 using json::utility::jsonObject;
277 if (trayIconResource)
279 vector<jsonObject> items;
281 current.setInt(
"trayIconResource", trayIconResource);
283 current.setBool(
"alwaysShowTrayIcon", alwaysShowTrayIcon);
285 for (
size_t i = 0; i < popupMenuItems.size(); i++)
287 const Function& function = popupMenuItems[i].second;
293 MENUITEMINFOW info = {};
295 info.cbSize =
sizeof(info);
296 info.fMask = MIIM_STRING;
298 GetMenuItemInfoW(trayPopupMenu,
static_cast<uint32_t
>(i),
true, &info);
302 object.setString(
"functionName"s, function.
functionName);
304 object.setString(
"moduleName"s, function.
moduleName);
308 json::utility::appendArray(move(
object), items);
314 current.setArray(
"items", move(items));
325 DestroyMenu(trayPopupMenu);
330 DeleteObject(tray.hIcon);
332 tray.hIcon =
nullptr;
const std::wstring windowName
LRESULT sendRawMessage(UINT message, WPARAM wparam, LPARAM lparam)
SendMessage WinAPI wrapper.
void setOnDestroy(const std::function< void()> &onDestroy)
void setExitMode(exitMode mode)
void sendTrayMessage(uint32_t id)
Process tray commands.
bool removeTrayMenuItem(const std::wstring &text)
Remove tray menu text item.
bool addTrayMenuItem(const std::wstring &text, const std::function< void()> &onClick, uint32_t *menuItemId=nullptr)
Add tray menu text item. Works only if non NULL value passed in trayIconResource in contructor.
BaseMainWindow(const std::wstring &className, const std::wstring &titleName, const utility::ComponentSettings &settings, const std::string &windowFunctionName, uint16_t trayIconResource, bool alwaysShowTray=false, bool maximize=false, bool minimize=false, const std::string &moduleName="", uint16_t smallIconResource=NULL, uint16_t largeIconResource=NULL)
virtual json::JSONBuilder getStructure() const override
virtual size_t getHash() const override
Used as key in creators.
void initTray(uint16_t trayIconResource, bool alwaysShowTrayIcon)
virtual ~BaseMainWindow()
virtual void onDestroyEvent()
Base class for separate windows.
virtual json::JSONBuilder getStructure() const override
virtual void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) final override
static GUIFramework & get()
Singleton instance access.
virtual void setOnClose(const std::function< bool()> &onClose) final
static uint32_t getCodepage()
string to_string(wstring_view stringToConvert, uint32_t codepage)
void(*)() onClickSignature
Default on click signature.
Function(const std::function< void()> &callable)
All settings for windows.