From 23b6fee1f0b1722a9f081e52b8f47eea45a0f709 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 25 Feb 2022 10:49:11 -0600 Subject: [PATCH] this was a test that Evan wanted me to try. seemed to work okay, but it's not validated with WAM --- .../base/InteractivityFactory.cpp | 9 ++-- src/tools/scratch/main.cpp | 41 +++++++++++++++++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/interactivity/base/InteractivityFactory.cpp b/src/interactivity/base/InteractivityFactory.cpp index b1733f14c59..08fa893a434 100644 --- a/src/interactivity/base/InteractivityFactory.cpp +++ b/src/interactivity/base/InteractivityFactory.cpp @@ -354,7 +354,8 @@ using namespace Microsoft::Console::Interactivity; pseudoClass.lpfnWndProc = DefWindowProc; RegisterClass(&pseudoClass); - const auto windowStyle = (owner == HWND_DESKTOP) ? WS_OVERLAPPEDWINDOW : WS_CHILD; + // const auto windowStyle = (owner == HWND_DESKTOP) ? WS_OVERLAPPEDWINDOW : WS_CHILD; + const auto windowStyle = WS_OVERLAPPEDWINDOW; // Attempt to create window hwnd = CreateWindowExW( @@ -376,9 +377,9 @@ using namespace Microsoft::Console::Interactivity; status = NTSTATUS_FROM_WIN32(gle); } - const auto awareness{ GetThreadDpiAwarenessContext() }; - awareness; - SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); + // const auto awareness{ GetThreadDpiAwarenessContext() }; + // awareness; + // SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); break; } diff --git a/src/tools/scratch/main.cpp b/src/tools/scratch/main.cpp index 029b50f140f..26bcbec1acd 100644 --- a/src/tools/scratch/main.cpp +++ b/src/tools/scratch/main.cpp @@ -154,15 +154,12 @@ int createSomeWindows(const HWND& consoleHwnd) return 0; } -// This wmain exists for help in writing scratch programs while debugging. -int __cdecl wmain(int /*argc*/, WCHAR* /*argv[]*/) +int doDefaultOutput() { const auto pid{ GetCurrentProcessId() }; const auto consoleWindow{ GetConsoleWindow() }; - // createSomeWindows(consoleWindow); wprintf(fmt::format(L"pid: {}\n", pid).c_str()); - wprintf(fmt::format(L"consoleWindow: {0:#010x}\n", reinterpret_cast(consoleWindow)).c_str()); const auto mainHwnd{ find_main_window(pid) }; @@ -181,3 +178,39 @@ int __cdecl wmain(int /*argc*/, WCHAR* /*argv[]*/) return 0; } + +// This wmain exists for help in writing scratch programs while debugging. +int __cdecl wmain(int argc, WCHAR* argv[]) +{ + doDefaultOutput(); + + const auto consoleWindow{ GetConsoleWindow() }; + + if (argc <= 1) + { + return 0; + } + + HWND target = consoleWindow; + std::wstring arg{ argv[1] }; + if (arg == L"--parent" && argc > 2) + { + target = GetAncestor(consoleWindow, GA_ROOT); + arg = argv[2]; + } + + if (arg == L"messagebox") + { + MessageBoxW(target, L"foo", L"bar", MB_OK); + } + else if (arg == L"windows") + { + createSomeWindows(target); + } + else if (arg == L"hide") + { + ShowWindow(target, SW_HIDE); + } + + return 0; +}