GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
MenuItem.cpp
Go to the documentation of this file.
1#include "MenuItem.h"
2
3#include "GUIFramework.h"
4
6
7using namespace std;
8
9namespace gui_framework
10{
11 MenuItem::MenuItem(const wstring& text, const function<void()>& onClick) :
12 BaseMenuItem(text),
13 onClick(onClick)
14 {
15
16 }
17
18 MenuItem::MenuItem(const wstring& text, const string& functionName, const string& moduleName) :
19 BaseMenuItem(text),
20 functionName(functionName),
21 moduleName(moduleName)
22 {
23 GUIFramework& instance = GUIFramework::get();
24 const HMODULE& module = instance.getModules().at(moduleName);
25
26 onClickSignature tem = reinterpret_cast<onClickSignature>(GetProcAddress(module, functionName.data()));
27
28 if (!tem)
29 {
30 throw exceptions::CantFindFunctionFromModuleException(functionName, moduleName, __FILE__, __FUNCTION__, __LINE__);
31 }
32
33 onClick = tem;
34 }
35
36 void MenuItem::processMessage()
37 {
38 onClick();
39 }
40
41 json::JSONBuilder MenuItem::getStructure() const
42 {
43 using json::utility::jsonObject;
44
45 if (functionName.empty())
46 {
47 return BaseMenuItem::getStructure();
48 }
49
50 json::JSONBuilder builder = BaseMenuItem::getStructure();
51
52 builder.
53 append("functionName", functionName).
54 append("moduleName", moduleName);
55
56 return builder;
57 }
58}
MenuItem(const std::wstring &text, const std::function< void()> &onClick)
void(*)() onClickSignature
Default on click signature.