3#include <Covellite/App/Application.hpp>
4#include <alicorn/platform/windows.hpp>
9#include <boost/core/ignore_unused.hpp>
10#include <alicorn/platform/winapi-check.hpp>
11#include <Covellite/Events.hpp>
12#include <Covellite/App/Events.hpp>
13#include "ClassName.windows.hpp"
17using namespace covellite::app;
19static WNDCLASSEX WindowClass = { 0 };
25Application::Application(
const Run_t & _Run) :
28 const auto hInstance = GetModuleHandle(
nullptr);
30 WindowClass.cbSize =
sizeof(WindowClass);
31 WindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
32 WindowClass.hInstance = hInstance;
33 WindowClass.lpszClassName = ClassName;
34 WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
35 WindowClass.hIcon = USING_MOCK ::LoadIcon(hInstance, L
"ApplicationIcon");
36 WindowClass.hIconSm = USING_MOCK ::LoadIcon(hInstance, L
"ApplicationIcon");
38 WindowClass.lpfnWndProc =
39 [](HWND _hWnd, UINT _Message, WPARAM _wParam, LPARAM _lParam) -> LRESULT
42 USING_MOCK ::GetWindowLongPtr(_hWnd, GWLP_USERDATA));
43 if (pEvents !=
nullptr)
45 const ::std::pair<WPARAM, LPARAM> Params{ _wParam, _lParam };
46 const auto IsSuccess = (*pEvents)[_Message](Params);
47 if (IsSuccess)
return 0;
50 return USING_MOCK ::DefWindowProc(_hWnd, _Message, _wParam, _lParam);
53 WINAPI_CHECK RegisterClassEx(&WindowClass);
55 m_Events[events::Application.Exit].Connect([](
void)
noexcept
66Application::Application(Continuous) :
76Application::Application(EventBased) :
81 Application::~Application(
void)
noexcept
83 USING_MOCK ::UnregisterClass(ClassName, GetModuleHandle(
nullptr));
97 void Application::Main(CreateApp_t _fnCreateApp,
void * _pParams)
noexcept
99 ::boost::ignore_unused(_pParams);
103 _fnCreateApp()->Run();
105 catch (const ::std::exception & _Ex)
107 const auto ErrorDescription =
108 ::std::string{
"Exception: " } + _Ex.what() +
".";
109 MessageBoxA(NULL, ErrorDescription.c_str(),
"Covellite++", MB_OK);
113 const auto ErrorDescription =
114 ::std::string{
"Exception: " } +
"unknown" +
".";
115 MessageBoxA(NULL, ErrorDescription.c_str(),
"Covellite++", MB_OK);
124::std::string Application::GetCommandLine(
void)
const
126 const auto *
const pCommandLine = GetCommandLineA();
127 return (pCommandLine ==
nullptr) ?
"" : pCommandLine;
132 using ProcessEvents_t = ::std::function<bool(MSG &)>;
134 const ProcessEvents_t ProcessEventsEventBased = [](MSG & _Message)
136 const auto Result = USING_MOCK::GetMessage(&_Message, NULL, 0, 0);
137 if (Result == -1) WINAPI_CHECK FALSE;
138 if (_Message.message == WM_QUIT)
return true;
140 USING_MOCK::TranslateMessage(&_Message);
141 USING_MOCK::DispatchMessage(&_Message);
145 bool IsLostFocus =
false;
147 const ProcessEvents_t ProcessEventsContinuous =
148 [&IsLostFocus](MSG & _Message)
noexcept
150 const auto Result = (IsLostFocus) ?
151 USING_MOCK ::GetMessage(&_Message, NULL, 0, 0) :
152 USING_MOCK ::PeekMessage(&_Message, 0, 0, 0, PM_REMOVE);
153 if (Result == FALSE)
return true;
155 if (_Message.message == WM_SETFOCUS) IsLostFocus =
false;
156 if (_Message.message == WM_KILLFOCUS) IsLostFocus =
true;
157 if (_Message.message == WM_QUIT)
return true;
159 USING_MOCK::TranslateMessage(&_Message);
160 USING_MOCK::DispatchMessage(&_Message);
164 const auto ProcessEvents = (_IsWaitMessage) ?
165 ProcessEventsEventBased : ProcessEventsContinuous;
167 m_Events[events::Application.Start]();
173 while (!ProcessEvents(Message)) {};
174 if (Message.message == WM_QUIT)
break;
176 m_Events[events::Application.Update]();
Класс входит в проект Covellite.App Базовый класс приложения для Android.
Definition Application.hpp:51
VIRTUAL_MOCK bool PostCommand(bool)
Функция вызова сигнала произошедшего события..
Definition Application.android.cpp:233
Класс входит в проект Covellite.Events Класс для работы с событиями фреймворка.
Definition Events.hpp:36