MCPcopy Create free account
hub / github.com/OpenKneeboard/OpenKneeboard / wWinMain

Function wWinMain

src/utilities/set-tab-remote.cpp:19–70  ·  view source on GitHub ↗

We only need a standard `main()` function, but using wWinMain prevents a window/task bar entry from temporarily appearing

Source from the content-addressed store, hash-verified

17// We only need a standard `main()` function, but using wWinMain prevents
18// a window/task bar entry from temporarily appearing
19int WINAPI wWinMain(
20 HINSTANCE hInstance,
21 HINSTANCE hPrevInstance,
22 PWSTR pCmdLine,
23 int nCmdShow) {
24 DPrintSettings::Set({
25 .prefix = "SetTab-Remote",
26 .consoleOutput = DPrintSettings::ConsoleOutputMode::ALWAYS,
27 });
28 int argc = 0;
29 auto argv = CommandLineToArgvW(pCmdLine, &argc);
30
31 if (argc < 2 || argc > 4) {
32 dprint("Usage: (id|name|position) IDENTIFIER [PAGE] [KNEEBOARD]");
33 return 0;
34 }
35
36 const auto kind = std::wstring_view(argv[0]);
37 const auto identifier = winrt::to_string(std::wstring_view(argv[1]));
38
39 BaseSetTabEvent base {};
40
41 if (argc >= 3) {
42 base.mPageNumber = wcstoull(argv[2], nullptr, 10);
43 }
44 if (argc >= 4) {
45 base.mKneeboard = wcstoull(argv[3], nullptr, 10);
46 }
47
48 if (kind == L"id") {
49 APIEvent::FromStruct(SetTabByIDEvent {base, identifier}).Send();
50 return 0;
51 }
52
53 if (kind == L"name") {
54 APIEvent::FromStruct(SetTabByNameEvent {base, identifier}).Send();
55 return 0;
56 }
57
58 if (kind == L"position") {
59 const auto position = std::strtoull(identifier.c_str(), nullptr, 10);
60 if (position < 1) {
61 dprint("Error: position must start at 1");
62 return 0;
63 }
64 APIEvent::FromStruct(SetTabByIndexEvent {base, position - 1}).Send();
65 return 0;
66 }
67
68 dprint(L"Error: first argument must be 'id' or 'name', but '{}' given", kind);
69 return 1;
70}

Callers

nothing calls this directly

Calls 2

to_stringFunction · 0.50
SendMethod · 0.45

Tested by

no test coverage detected