Skip to content

Commit

Permalink
allow setting initial window style
Browse files Browse the repository at this point in the history
  • Loading branch information
lostmsu committed Jun 25, 2023
1 parent 1d19d45 commit fd43818
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/NDetours.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<!-- Package stuff -->
<Version>0.0.7</Version>
<Version>0.0.8</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Description>Managed package that simplifies injection of Detours-based DLLs</Description>
Expand Down Expand Up @@ -36,6 +36,7 @@
<!-- The following is recommended for public projects -->
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="PInvoke.Kernel32" Version="0.7.124" />
<PackageReference Include="PInvoke.User32" Version="0.7.124" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions src/ProcessDetour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public static unsafe Process Start(StartInfo startInfo) {
var startupInfo = new Kernel32.STARTUPINFO {
cb = sizeof(Kernel32.STARTUPINFO),
};
if (startInfo.ShowWindow is { } style) {
startupInfo.dwFlags |= Kernel32.StartupInfoFlags.STARTF_USESHOWWINDOW;
startupInfo.wShowWindow = (ushort)style;
}
Kernel32.PROCESS_INFORMATION processInfo;
var flags = startInfo.Flags;
var dlls = new StrPtr[startInfo.InjectDlls.Count];
Expand Down
13 changes: 13 additions & 0 deletions src/StartInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;

using static PInvoke.Kernel32;
using static PInvoke.User32;

partial class ProcessDetour {
public sealed class StartInfo {
Expand All @@ -13,6 +14,18 @@ public sealed class StartInfo {
public IDictionary<string, string>? Environment { get; set; }
public CreateProcessFlags Flags { get; set; } = CreateProcessFlags.None;

WindowShowStyle showWindow = WindowShowStyle.SW_SHOWDEFAULT;
public WindowShowStyle? ShowWindow {
get => this.showWindow == WindowShowStyle.SW_SHOWDEFAULT
? null : this.showWindow;
set {
if (value == WindowShowStyle.SW_SHOWDEFAULT)
throw new ArgumentException($"{nameof(WindowShowStyle.SW_SHOWDEFAULT)} can not be used when starting new process.");

this.showWindow = value ?? WindowShowStyle.SW_SHOWDEFAULT;
}
}

public StartInfo(string executable) {
this.Executable = executable ?? throw new ArgumentNullException(nameof(executable));
}
Expand Down

0 comments on commit fd43818

Please sign in to comment.