diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2020-10-24 21:33:44 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2020-10-27 00:11:41 +0300 |
commit | a864099ba77157090c4cd12817245122c163ec24 (patch) | |
tree | f15b1f2801219fa9af6111fa28591858d87711ec /include/winapi | |
parent | Process: add termination methods (diff) | |
download | winapi-common-a864099ba77157090c4cd12817245122c163ec24.tar.gz winapi-common-a864099ba77157090c4cd12817245122c163ec24.zip |
rework Process API & tests
* Add separate classes ProcessParameters & ShellParameters for
Process::create() and Process::shell() methods.
* Add a separate "worker" executable. It's used in tests via a fairly
complicated scheme, receiving orders to execute via a shared memory
region.
* Add tests that utilize the Console API, reading console window's
screen buffer directly, making for more reliable tests & broader
coverage.
Diffstat (limited to 'include/winapi')
-rw-r--r-- | include/winapi/process.hpp | 31 | ||||
-rw-r--r-- | include/winapi/window_style.hpp | 27 |
2 files changed, 57 insertions, 1 deletions
diff --git a/include/winapi/process.hpp b/include/winapi/process.hpp index 5c9e3c9..095b50c 100644 --- a/include/winapi/process.hpp +++ b/include/winapi/process.hpp @@ -11,6 +11,7 @@ #include "resource.hpp" #include <boost/config.hpp> +#include <boost/optional.hpp> #include <windows.h> @@ -19,12 +20,40 @@ namespace winapi { +struct ProcessParameters { + enum ConsoleCreationMode { + ConsoleNone, + ConsoleInherit, + ConsoleNew, + }; + + explicit ProcessParameters(const CommandLine& cmd_line) : cmd_line{cmd_line} {} + + CommandLine cmd_line; + boost::optional<process::IO> io; + ConsoleCreationMode console_mode = ConsoleNew; +}; + +struct ShellParameters : ProcessParameters { + explicit ShellParameters(const CommandLine& cmd_line) : ProcessParameters{cmd_line} {} + + static ShellParameters runas(const CommandLine& cmd_line) { + ShellParameters params{cmd_line}; + params.verb = "runas"; + return params; + } + + boost::optional<std::string> verb; +}; + class Process { public: + static Process create(ProcessParameters); static Process create(const CommandLine&); static Process create(const CommandLine&, process::IO); - static Process runas(const CommandLine&); + static Process shell(const ShellParameters&); + static Process shell(const CommandLine&); bool is_running() const; void wait() const; diff --git a/include/winapi/window_style.hpp b/include/winapi/window_style.hpp new file mode 100644 index 0000000..dd12a56 --- /dev/null +++ b/include/winapi/window_style.hpp @@ -0,0 +1,27 @@ +// Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com> +// This file is part of the "winapi-common" project. +// For details, see https://github.com/egor-tensin/winapi-common. +// Distributed under the MIT License. + +#pragma once + +namespace winapi { + +enum class WindowStyle { + // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow + ForceMinimize = 11, + Hide = 0, + Maximize = 3, + Minimize = 6, + Restore = 9, + Show = 5, + ShowDefault = 10, + ShowMaximized = 3, + ShowMinimized = 2, + ShowMinNoActive = 7, + ShowNA = 8, + ShowNoActivate = 4, + ShowNormal = 1, +}; + +} // namespace winapi |