stuff-from-scratch/apps/sample-gui/gui-main-win.cpp
2022-11-30 20:53:17 +00:00

67 lines
1.6 KiB
C++

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