stuff-from-scratch/apps/notes_tk/main-win.cpp

68 lines
1.6 KiB
C++
Raw Normal View History

2020-07-04 18:43:08 +00:00
#ifndef UNICODE
#define UNICODE
#endif
2021-10-31 13:04:48 +00:00
#include "MainApplication.h"
#include "GuiApplication.h"
#include "CommandLineArgs.h"
#include "Win32WindowInterface.h"
#include "FileLogger.h"
#include "StringUtils.h"
2020-07-04 18:43:08 +00:00
#include "windows.h"
2021-10-31 13:04:48 +00:00
#include <iostream>
#include <vector>
#include <string>
2020-07-04 18:43:08 +00:00
2021-10-31 13:04:48 +00:00
void initializeCommandLineArgs(CommandLineArgs* args)
2020-07-04 18:43:08 +00:00
{
2021-10-31 13:04:48 +00:00
int nArgs{ 0 };
auto szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if (szArglist == nullptr)
2020-07-04 18:43:08 +00:00
{
2021-10-31 13:04:48 +00:00
return;
2020-07-04 18:43:08 +00:00
}
2021-10-31 13:04:48 +00:00
std::vector<std::string> windowsArgs(nArgs);
for (int idx = 0; idx < nArgs; idx++)
2020-07-04 18:43:08 +00:00
{
2021-10-31 13:04:48 +00:00
windowsArgs[idx] = StringUtils::convert(szArglist[idx]);
2020-07-04 18:43:08 +00:00
}
2021-10-31 13:04:48 +00:00
LocalFree(szArglist);
2022-11-30 20:53:17 +00:00
args->process(windowsArgs);
2020-07-04 18:43:08 +00:00
}
2021-10-31 13:04:48 +00:00
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
2020-07-04 18:43:08 +00:00
{
2021-10-31 13:04:48 +00:00
std::ofstream out("out.txt");
std::cout.rdbuf(out.rdbuf());
2022-11-30 20:53:17 +00:00
auto args = CommandLineArgs::Create();
2021-10-31 13:04:48 +00:00
initializeCommandLineArgs(args.get());
2022-11-30 20:53:17 +00:00
args->recordLaunchPath();
2021-10-31 13:04:48 +00:00
// Start the main app
auto main_app = MainApplication::Create();
2020-07-04 18:43:08 +00:00
2021-10-31 13:04:48 +00:00
auto applicationContext = std::make_unique<Win32ApplicationContext>();
applicationContext->hInstance = reinterpret_cast<void*>(hInstance);
applicationContext->nCmdShow = nCmdShow;
2020-07-04 18:43:08 +00:00
2022-11-30 20:53:17 +00:00
main_app->initialize(std::move(args), std::move(applicationContext));
2020-07-04 18:43:08 +00:00
2021-10-31 13:04:48 +00:00
MLOG_INFO("Creating GUI Application");
// Start the gui application
auto gui_app = GuiApplication();
2022-11-30 20:53:17 +00:00
//gui_app.setMainApplication(main_app);
2021-10-31 13:04:48 +00:00
MLOG_INFO("Running GUI Application");
2022-11-30 20:53:17 +00:00
gui_app.run();
2021-10-31 13:04:48 +00:00
2022-11-30 20:53:17 +00:00
main_app->shutDown();
2021-10-31 13:04:48 +00:00
return 0;
}
2020-07-04 18:43:08 +00:00