Skip to content

Commit

Permalink
Merge pull request #149 from DevyusCode/vNext
Browse files Browse the repository at this point in the history
Version 1.10.0.2310
  • Loading branch information
lpeyr authored Sep 30, 2023
2 parents d5d2266 + afbe4a3 commit 37bf85b
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 37 deletions.
6 changes: 3 additions & 3 deletions PeyrSharp.Core/PeyrSharp.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Core</Title>
<Version>1.9.0.2309</Version>
<Version>1.10.0.2310</Version>
<Authors>Devyus</Authors>
<Description>Core methods and features of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
Expand All @@ -31,8 +31,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Enums" Version="1.10.0.2310" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.10.0.2310" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion PeyrSharp.Enums/PeyrSharp.Enums.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageProjectUrl>https://peyrsharp.leocorporation.dev/</PackageProjectUrl>
<RepositoryUrl>https://github.com/DevyusCode/PeyrSharp</RepositoryUrl>
<PackageTags>enums;c-sharp;dotnet;vb;peyrsharp;leo corp</PackageTags>
<Version>1.9.0.2309</Version>
<Version>1.10.0.2310</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
Expand Down
7 changes: 3 additions & 4 deletions PeyrSharp.Env/PeyrSharp.Env.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Env</Title>
<Version>1.9.0.2309</Version>
<Version>1.10.0.2310</Version>
<Authors>Devyus</Authors>
<Description>Environment-related methods of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
Expand All @@ -16,8 +16,7 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Added Supported OS attribute (#137)
- Added CurrentTheme property (#138)</PackageReleaseNotes>
<PackageReleaseNotes></PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -33,6 +32,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="PeyrSharp.Enums" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Enums" Version="1.10.0.2310" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>PeyrSharp.Exceptions</Title>
<Version>1.9.0.2309</Version>
<Version>1.10.0.2310</Version>
<Company>Devyus</Company>
<Description>Exceptions of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
Expand Down
7 changes: 3 additions & 4 deletions PeyrSharp.Extensions/PeyrSharp.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Extensions</Title>
<Version>1.9.0.2309</Version>
<Version>1.10.0.2310</Version>
<Authors>Devyus</Authors>
<Description>Extensions methods of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
Expand All @@ -16,8 +16,7 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Added ToLowerAt(s) (#136)
- Added ToLowerAt(str, r) (#136)</PackageReleaseNotes>
<PackageReleaseNotes></PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -32,7 +31,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Enums" Version="1.10.0.2310" />
</ItemGroup>

</Project>
14 changes: 10 additions & 4 deletions PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<UseWPF>true</UseWPF>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.UiHelpers</Title>
<Version>1.9.0.2309</Version>
<Version>1.10.0.2310</Version>
<Authors>Devyus</Authors>
<Description>Useful helpers for Windows Forms and Windows Presentation Framework.</Description>
<Copyright>© 2023</Copyright>
Expand All @@ -20,8 +20,14 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Added WindowInfo class (#139)
- Added the possibility to get a list of opened windows (#139)</PackageReleaseNotes>
<PackageReleaseNotes>- Added the possibility to close windows (#143)
- Added the possibility to maximize windows (#143)
- Added the possibility to restore windows (#143)
- Added the possibility to minimize windows (#143)
- Added XML documentation (#143)
- Added the possibility to set the position of any window (#144)
- Added SetTopMost() method (#145)
- Added GetWindowSize() method (#146)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -36,7 +42,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Enums" Version="1.10.0.2310" />
</ItemGroup>

</Project>
116 changes: 110 additions & 6 deletions PeyrSharp.UiHelpers/WindowHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,108 @@ public static List<WindowInfo> GetWindows()
return windowList;
}

private static bool IsWindowVisible(IntPtr hWnd)
/// <summary>
/// Closes a window.
/// </summary>
/// <param name="windowInfo">The window to close.</param>
public static void CloseWindow(WindowInfo windowInfo)
{
SendMessage(windowInfo.Handle, WM_SYSCOMMAND, (IntPtr)SC_CLOSE, IntPtr.Zero);
}

/// <summary>
/// Maximizes a window.
/// </summary>
/// <param name="windowInfo">The window to maximize.</param>
public static void MaximizeWindow(WindowInfo windowInfo)
{
SendMessage(windowInfo.Handle, WM_SYSCOMMAND, (IntPtr)SC_MAXIMIZE, IntPtr.Zero);
}

/// <summary>
/// Restores a window.
/// </summary>
/// <param name="windowInfo">The window to restore.</param>
public static void RestoreWindow(WindowInfo windowInfo)
{
SendMessage(windowInfo.Handle, WM_SYSCOMMAND, (IntPtr)SC_RESTORE, IntPtr.Zero);
}

/// <summary>
/// Minimizes a window.
/// </summary>
/// <param name="windowInfo">The window to minimize.</param>
public static void MinimizeWindow(WindowInfo windowInfo)
{
SendMessage(windowInfo.Handle, WM_SYSCOMMAND, (IntPtr)SC_MINIMIZE, IntPtr.Zero);
}

/// <summary>
/// Moves a window to specified coordinates.
/// </summary>
/// <param name="windowInfo">The window to move.</param>
/// <param name="x">The X-axis coordinates.</param>
/// <param name="y">The Y-axis coordinates.</param>
public static void MoveWindow(WindowInfo windowInfo, int x, int y)
{
SetWindowPos(windowInfo.Handle, IntPtr.Zero, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}

/// <summary>
/// Sets the Topmost property of a window.
/// </summary>
/// <param name="windowInfo">The window to target.</param>
/// <param name="isTopMost">The value of the TopMost property. <see langword="true"/> if the window should always stay on top; <see langword="false"/> otherwise.</param>
public static void SetTopMost(WindowInfo windowInfo, bool isTopMost)
{
return IsWindowVisibleCore(hWnd) && !IsIconic(hWnd);
SetWindowPos(windowInfo.Handle, isTopMost ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}

/// <summary>
/// Gets the width and height of a window.
/// </summary>
/// <param name="windowInfo">The window to get the size of.</param>
/// <returns>A tuple of integers; the first one represents the width of the window, the second one represents the height.</returns>
/// <exception cref="InvalidOperationException"></exception>
public static (int, int) GetWindowSize(WindowInfo windowInfo)
{
if (GetWindowRect(windowInfo.Handle, out RECT rect))
{
int width = rect.Right - rect.Left;
int height = rect.Bottom - rect.Top;
return (width, height);
}
else
{
throw new InvalidOperationException("Failed to retrieve window size.");
}
}

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowVisibleCore(IntPtr hWnd);
private static extern bool IsWindowVisible(IntPtr hWnd);

private const int WM_SYSCOMMAND = 0x0112;

private const int SC_CLOSE = 0xF060;
private const int SC_MAXIMIZE = 0xF030;
private const int SC_RESTORE = 0xF120;
private const int SC_MINIMIZE = 0xF020;

private const uint SWP_NOSIZE = 0x0001;
private const uint SWP_NOZORDER = 0x0004;
internal const uint SWP_NOMOVE = 0x0002;

internal const int HWND_TOPMOST = -1;
internal const int HWND_NOTOPMOST = -2;

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsIconic(IntPtr hWnd);
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
Expand All @@ -90,5 +180,19 @@ private static bool IsWindowVisible(IntPtr hWnd)

[DllImport("user32.dll")]
private static extern int GetClassName(IntPtr hWnd, StringBuilder className, int count);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

[Serializable]
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
}
}
2 changes: 1 addition & 1 deletion PeyrSharp/PeyrSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public static class PeyrSharp
/// <summary>
/// The current version of PeyrSharp.
/// </summary>
public static string Version => "1.9.0.2309";
public static string Version => "1.10.0.2310";
}
}
29 changes: 16 additions & 13 deletions PeyrSharp/PeyrSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net5.0;net6.0;net5.0-windows;net6.0-windows;net7.0;net7.0-windows</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp</Title>
<Version>1.9.0.2309</Version>
<Version>1.10.0.2310</Version>
<Authors>Devyus</Authors>
<Copyright>© 2023</Copyright>
<Description>A C# library designed to make developers' job easier.</Description>
Expand All @@ -17,12 +17,15 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Added ToLowerAt(s) (#136)
- Added ToLowerAt(str, r) (#136)
- Added LaunchUWPApp(UwpApp) (#137)
- Added CurrentTheme property (#138)
- Added WindowInfo class (#139)
- Added the possibility to get a list of opened windows (#139)</PackageReleaseNotes>
<PackageReleaseNotes>(for Windows only)
- Added the possibility to close windows (#143)
- Added the possibility to maximize windows (#143)
- Added the possibility to restore windows (#143)
- Added the possibility to minimize windows (#143)
- Added XML documentation (#143)
- Added the possibility to set the position of any window (#144)
- Added SetTopMost() method (#145)
- Added GetWindowSize() method (#146)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -37,12 +40,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Core" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Enums" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Env" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Extensions" Version="1.9.0.2309" />
<PackageReference Condition="'$(TargetPlatformIdentifier)' == 'Windows'" Include="PeyrSharp.UiHelpers" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Core" Version="1.10.0.2310" />
<PackageReference Include="PeyrSharp.Enums" Version="1.10.0.2310" />
<PackageReference Include="PeyrSharp.Env" Version="1.10.0.2310" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.10.0.2310" />
<PackageReference Include="PeyrSharp.Extensions" Version="1.10.0.2310" />
<PackageReference Condition="'$(TargetPlatformIdentifier)' == 'Windows'" Include="PeyrSharp.UiHelpers" Version="1.10.0.2310" />
</ItemGroup>

</Project>

0 comments on commit 37bf85b

Please sign in to comment.