HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
crt.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
21#include "os_detect.hpp"
22
23#if TT_OPERATING_SYSTEM == TT_OS_WINDOWS
24#include "application_win32.hpp"
25#define tt_application(...) tt::application_win32(__VA_ARGS__)
26
27#include <Windows.h>
28#elif TT_OPERATING_SYSTEM == TT_OS_MACOS
29#include "application_macos.hpp"
30#define tt_application(...) tt::application_macos(__VA_ARGS__)
31
32#endif
33
34#pragma once
35
43int tt_main(std::vector<std::string> arguments, tt::os_handle instance);
44
45#if TT_OPERATING_SYSTEM == TT_OS_WINDOWS
46
57int WINAPI WinMain(
58 _In_ HINSTANCE hInstance,
59 [[maybe_unused]] _In_opt_ HINSTANCE hPrevInstance,
60 [[maybe_unused]] _In_ LPSTR lpCmdLine,
61 _In_ int nShowCmd)
62{
63 int argc;
64 auto argv = CommandLineToArgvW(GetCommandLineW(), &argc);
65
66 if (argc < 1) {
67 std::cerr << "Missing executable from argument list." << std::endl;
68 return 2;
69 }
70
71 auto arguments = std::vector<std::string>{};
72 arguments.reserve(argc + 1);
73
74 for (auto i = 0; i != argc; ++i) {
75 arguments.push_back(std::move(tt::to_string(std::wstring(argv[i]))));
76 }
77 LocalFree(argv);
78
79 switch (nShowCmd) {
80 case 3:
81 arguments.insert(std::next(std::begin(arguments)), "--window-state=maximize");
82 break;
83 case 0:
84 case 2:
85 case 6:
86 case 7:
87 case 11:
88 arguments.insert(std::next(std::begin(arguments)), "--window-state=minimize");
89 break;
90 default:;
91 }
92
93 return tt_main(std::move(arguments), hInstance);
94}
95
96#else
97
98int main(int argc, char **argv)
99{
100 if (argc < 1) {
101 std::cerr << "Missing executable from argument list." << std::endl;
102 return 2;
103 }
104
105 auto arguments = std::vector<std::string>{};
106 arguments.reserve(argc);
107
108 for (int i = 0; i != argc; ++i) {
109 arguments.emplace_back(argv[i]);
110 }
111
112 return tt_main(arguments, {});
113}
114
115#endif
116
int tt_main(std::vector< std::string > arguments, tt::os_handle instance)
Main entry-point.
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
Windows entry-point.
Definition crt.hpp:57
T begin(T... args)
T endl(T... args)
T move(T... args)
T next(T... args)
T reserve(T... args)