Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#tool GitVersion.CommandLine&version=5.3.7
#tool gitreleasemanager
#tool vswhere
#addin Cake.Figlet

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -39,15 +38,6 @@ var isDevelopBranch = StringComparer.OrdinalIgnoreCase.Equals("develop", branchN
var isReleaseBranch = StringComparer.OrdinalIgnoreCase.Equals("main", branchName);
var isTagged = AppVeyor.Environment.Repository.Tag.IsTag;

var latestInstallationPath = VSWhereLatest(new VSWhereLatestSettings { IncludePrerelease = true });
var msBuildPath = latestInstallationPath.Combine("./MSBuild/Current/Bin");
var msBuildPathExe = msBuildPath.CombineWithFilePath("./MSBuild.exe");

if (FileExists(msBuildPathExe) == false)
{
throw new NotImplementedException("You need at least Visual Studio 2019 to build this project.");
}

// Directories and Paths
var solution = "src/ControlzEx.sln";
var publishDir = "./src/bin";
Expand All @@ -74,7 +64,6 @@ Setup(ctx =>
Information("IsLocalBuild : {0}", isLocal);
Information("Branch : {0}", branchName);
Information("Configuration : {0}", configuration);
Information("MSBuildPath : {0}", msBuildPath);
});

Teardown(ctx =>
Expand All @@ -96,21 +85,19 @@ Task("Clean")
Task("Restore")
.Does(() =>
{
NuGetRestore(solution, new NuGetRestoreSettings { MSBuildPath = msBuildPath.ToString() });
DotNetCoreRestore(solution);
});

Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
var msBuildSettings = new MSBuildSettings {
Verbosity = verbosity
, ToolPath = msBuildPathExe
, Configuration = configuration
, ArgumentCustomization = args => args.Append("/m").Append("/nr:false") // The /nr switch tells msbuild to quit once it's done
var msBuildSettings = new DotNetCoreMSBuildSettings {
//Verbosity = (DotNetCoreVerbosity)verbosity
};
MSBuild(solution, msBuildSettings
DotNetCoreMSBuild(solution, msBuildSettings
.SetMaxCpuCount(0)
.SetConfiguration(configuration)
.WithProperty("Version", isReleaseBranch ? gitVersion.MajorMinorPatch : gitVersion.NuGetVersion)
.WithProperty("AssemblyVersion", gitVersion.AssemblySemVer)
.WithProperty("FileVersion", gitVersion.AssemblySemFileVer)
Expand All @@ -122,14 +109,13 @@ Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
var msBuildSettings = new MSBuildSettings {
Verbosity = verbosity
, ToolPath = msBuildPathExe
, Configuration = configuration
var msBuildSettings = new DotNetCoreMSBuildSettings {
//Verbosity = (DotNetCoreVerbosity)verbosity
};
var project = "./src/ControlzEx/ControlzEx.csproj";
MSBuild(project, msBuildSettings
DotNetCoreMSBuild(project, msBuildSettings
.WithTarget("pack")
.SetConfiguration(configuration)
.WithProperty("NoBuild", "true")
.WithProperty("IncludeBuildOutput", "true")
.WithProperty("PackageOutputPath", "../bin")
Expand Down
26 changes: 26 additions & 0 deletions src/ControlzEx.Tests/Native/NativeMethodsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace ControlzEx.Tests.Native
{
using ControlzEx.Standard;
using NUnit.Framework;

#pragma warning disable CS0618 // Type or member is obsolete
[TestFixture]
public class NativeMethodsTests
{
[Test]
public void GetMonitorInfoShouldReturnValidData()
{
var cursorPos = NativeMethods.GetCursorPos();

var monitor = NativeMethods.MonitorFromPoint(cursorPos, MonitorOptions.MONITOR_DEFAULTTONEAREST);

var monitorInfo = NativeMethods.GetMonitorInfo(monitor);

Assert.That(monitorInfo.rcMonitor.Width, Is.GreaterThan(0));
Assert.That(monitorInfo.rcMonitor.Height, Is.GreaterThan(0));

Assert.That(monitorInfo.rcWork.Width, Is.GreaterThan(0));
Assert.That(monitorInfo.rcWork.Width, Is.GreaterThan(0));
}
}
}
2 changes: 1 addition & 1 deletion src/ControlzEx/Microsoft.Windows.Shell/Standard/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ControlzEx.Standard

/// <summary>A static class for verifying assumptions.</summary>
[Obsolete(DesignerConstants.Win32ElementWarning)]
public static class Assert
internal static class Assert
{
// Blend and VS don't like Debugger.Break being called on their design surfaces. Badness will happen.
//private static readonly bool _isNotAtRuntime = (bool)System.ComponentModel.DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(System.Windows.DependencyObject)).DefaultValue;
Expand Down
26 changes: 15 additions & 11 deletions src/ControlzEx/Microsoft.Windows.Shell/Standard/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3434,33 +3434,37 @@ public static IntPtr GetModuleHandle(string lpModuleName)
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DllImport("user32.dll", EntryPoint = "GetMonitorInfo", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool _GetMonitorInfo([In] IntPtr hMonitor, [Out] MONITORINFO lpmi);
private static extern bool _GetMonitorInfo([In] IntPtr hMonitor, ref MONITORINFO lpmi);

[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
public static MONITORINFO GetMonitorInfo([In] IntPtr hMonitor)
{
var mi = new MONITORINFO();
mi.cbSize = Marshal.SizeOf(typeof(MONITORINFO));
if (!_GetMonitorInfo(hMonitor, mi))
var mi = new MONITORINFO
{
throw new Win32Exception();
cbSize = Marshal.SizeOf(typeof(MONITORINFO))
};
if (!_GetMonitorInfo(hMonitor, ref mi))
{
HRESULT.ThrowLastError();
}
return mi;
}

[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DllImport("user32.dll", EntryPoint = "GetMonitorInfoW", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool _GetMonitorInfoW([In] IntPtr hMonitor, [Out] MONITORINFO lpmi);
private static extern bool _GetMonitorInfoW([In] IntPtr hMonitor, ref MONITORINFO lpmi);

[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
public static MONITORINFO GetMonitorInfoW([In] IntPtr hMonitor)
{
var mi = new MONITORINFO();
mi.cbSize = Marshal.SizeOf(typeof(MONITORINFO));
if (!_GetMonitorInfoW(hMonitor, mi))
var mi = new MONITORINFO
{
throw new Win32Exception();
cbSize = Marshal.SizeOf(typeof(MONITORINFO))
};
if (!_GetMonitorInfoW(hMonitor, ref mi))
{
HRESULT.ThrowLastError();
}
return mi;
}
Expand Down Expand Up @@ -3493,7 +3497,7 @@ public static IntPtr GetTaskBarHandleForMonitor(IntPtr monitor)
public static IntPtr GetStockObject(StockObject fnObject)
{
IntPtr retPtr = _GetStockObject(fnObject);
if (retPtr == null)
if (retPtr == IntPtr.Zero)
{
HRESULT.ThrowLastError();
}
Expand Down
4 changes: 0 additions & 4 deletions src/ControlzEx/Native/MONITORINFO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ namespace ControlzEx.Standard

[Obsolete(DesignerConstants.Win32ElementWarning)]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
#if NETCOREAPP5_0
public struct MONITORINFO
#else
public class MONITORINFO
#endif
{
public int cbSize;
public RECT rcMonitor;
Expand Down
50 changes: 2 additions & 48 deletions src/ControlzEx/Native/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using ControlzEx.Standard;

namespace ControlzEx.Native
{
using ControlzEx.Standard;

/// <devdoc>http://msdn.microsoft.com/en-us/library/ms182161.aspx</devdoc>
[SuppressUnmanagedCodeSecurity]
[Obsolete(DesignerConstants.Win32ElementWarning)]
public static class UnsafeNativeMethods
{
/// <devdoc>http://msdn.microsoft.com/en-us/library/windows/desktop/ms633572%28v=vs.85%29.aspx</devdoc>
[DllImport("user32", CallingConvention = CallingConvention.Winapi)]
internal static extern IntPtr DefWindowProc([In] IntPtr hwnd, [In] int msg, [In] IntPtr wParam, [In] IntPtr lParam);

/// <devdoc>http://msdn.microsoft.com/en-us/library/dd144901%28v=VS.85%29.aspx</devdoc>
[DllImport("user32", EntryPoint = "GetMonitorInfoW", ExactSpelling = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetMonitorInfo([In] IntPtr hMonitor, [Out] MONITORINFO lpmi);

/// <devdoc>http://msdn.microsoft.com/en-us/library/dd145064%28v=VS.85%29.aspx</devdoc>
[DllImport("user32")]
internal static extern IntPtr MonitorFromWindow([In] IntPtr handle, [In] MonitorOptions flags);

[DllImport("user32.dll", SetLastError = true)]
internal static extern IntPtr MonitorFromPoint(POINT pt, MonitorOptions dwFlags);

/// <devdoc>http://msdn.microsoft.com/en-us/library/windows/desktop/ms647486%28v=vs.85%29.aspx</devdoc>
[DllImport("user32", CharSet = CharSet.Unicode, ExactSpelling = true, EntryPoint = "LoadStringW", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
public static extern int LoadString([In] [Optional] SafeLibraryHandle hInstance, [In] uint uID, [Out] StringBuilder lpBuffer, [In] int nBufferMax);
Expand All @@ -38,18 +23,6 @@ public static class UnsafeNativeMethods
[DllImport("user32", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern bool IsWindow([In] [Optional] IntPtr hWnd);

/// <devdoc>http://msdn.microsoft.com/en-us/library/windows/desktop/ms647985(v=vs.85).aspx</devdoc>
[DllImport("user32")]
internal static extern IntPtr GetSystemMenu([In] IntPtr hWnd, [In] bool bRevert);

/// <devdoc>http://msdn.microsoft.com/en-us/library/windows/desktop/ms648003(v=vs.85).aspx</devdoc>
[DllImport("user32")]
internal static extern uint TrackPopupMenuEx([In] IntPtr hmenu, [In] uint fuFlags, [In] int x, [In] int y, [In] IntPtr hwnd, [In] [Optional] IntPtr lptpm);

/// <devdoc>http://msdn.microsoft.com/en-us/library/windows/desktop/ms644944(v=vs.85).aspx</devdoc>
[DllImport("user32", EntryPoint = "PostMessage", SetLastError = true)]
private static extern bool _PostMessage([In] [Optional] IntPtr hWnd, [In] uint Msg, [In] IntPtr wParam, [In] IntPtr lParam);

/// <devdoc>http://msdn.microsoft.com/en-us/library/windows/desktop/ms684175%28v=vs.85%29.aspx</devdoc>
[DllImport("kernel32", CharSet = CharSet.Unicode, ExactSpelling = true, EntryPoint = "LoadLibraryW", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
public static extern SafeLibraryHandle LoadLibrary([In] [MarshalAs(UnmanagedType.LPWStr)] string lpFileName);
Expand All @@ -62,30 +35,11 @@ public static class UnsafeNativeMethods
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();

internal static void PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam)
{
if (!_PostMessage(hWnd, Msg, wParam, lParam))
{
throw new Win32Exception();
}
}

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

[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool RedrawWindow(IntPtr hWnd, [In] ref RECT lprcUpdate, IntPtr hrgnUpdate, Constants.RedrawWindowFlags flags);

[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool RedrawWindow(IntPtr hWnd, IntPtr lprcUpdate, IntPtr hrgnUpdate, Constants.RedrawWindowFlags flags);

[DllImport("user32.dll")]
internal static extern int MapVirtualKey(uint uCode, uint uMapType);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetKeyNameText(int lParam, [MarshalAs(UnmanagedType.LPWStr), Out] StringBuilder str, int size);
}
}
}