stuff-from-scratch/apps/sample-gui/gui-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);
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());
auto args = CommandLineArgs::CreateUnique();
initializeCommandLineArgs(args.get());
args->RecordLaunchPath();
// 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
2021-10-31 13:04:48 +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();
gui_app.SetMainApplication(main_app);
MLOG_INFO("Running GUI Application");
gui_app.Run();
main_app->ShutDown();
return 0;
}
2020-07-04 18:43:08 +00:00