OneCore.Net.WinAPI 1.0.0

Suggested Alternatives

OneCore.Net.WIN.WinAPI

Additional Details

The OneCore.Net.WIN.WinAPI 1.0.0 is identical to this library. It got renamed and retargeted to point out it runs on windows only.

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package OneCore.Net.WinAPI --version 1.0.0
                    
NuGet\Install-Package OneCore.Net.WinAPI -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OneCore.Net.WinAPI" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OneCore.Net.WinAPI" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="OneCore.Net.WinAPI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OneCore.Net.WinAPI --version 1.0.0
                    
#r "nuget: OneCore.Net.WinAPI, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OneCore.Net.WinAPI@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OneCore.Net.WinAPI&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=OneCore.Net.WinAPI&version=1.0.0
                    
Install as a Cake Tool

OneCore

OneCore.Net.WinAPI Library

Overview

OneCore.Net.WinAPI is an internal library that provides low-level WinAPI bindings used by other OneCore libraries; it is not intended for standalone use and remains incomplete by design.

Features

  • Dwmapi: Access to the WinAPI methods within the "dwmapi.dll"
  • Kernel32: Access to WinAPI methods within the "kernel32.dll".
  • Shell32: Access to WinAPI methods within the "shell32.dll".
  • User32: Access to WinAPI methods within the "user32.dll".
  • UxTheme: Access to WinAPI methods within the "uxtheme.dll".
  • Data: Values and structures to use within any of those above. Like WM (WindowMessages), WH (WindowHandle) and many more.

Getting Started

  1. Installation:

    • Install the OneCore.Net.WinAPI library via NuGet Package Manager:
    dotnet add package OneCore.Net.WinAPI
    
  2. Usage:

    • Direct access the objects like
    User32.ShowWindow(windowHandle, WindowShowStyle.Restore);
    
    • Or a wrapper
    public class Demo
    {
        public Demo(IUser32 user32)
        {
            _user32 = user32;
        }
    
        public void RestoreWindow(Window window)
        {
            var windowHandle = ((HwndSource)PresentationSource.FromVisual(window))!.Handle;
            _user32.ShowWindow(windowHandle, WindowShowStyle.Restore);
        }
    }
    

Example

  • Target
    public class Demo
    {
        public Demo(IUser32 user32)
        {
            _user32 = user32;
        }
    
        public void RestoreWindow(Window window)
        {
            var windowHandle = ((HwndSource)PresentationSource.FromVisual(window))!.Handle;
            _user32.ShowWindow(windowHandle, WindowShowStyle.Restore);
        }
    }
    
  • UnitTest
    public class DemoTests
    {
        private Demo _target,
    
        [Setup]
        public void Setup()
        {
            _user32 = new Mock<IUser32>();
            _target = new Demo(_user32.Object);
        }
    
        [Test]
        public void RestoreWindow_CalledAfterMinimizedFromNormal_RestoresTheWindowBackToNormal()
        {
            var window = Utils.OpenDummyWindow();
            window.WindowState = WindowState.Normal;
    
            window.WindowState = WindowState.Minimized;
            _target.RestoreWindow(window);
    
            _user32.Verify(x => x.ShowWindow(It.IsAny<nint>(), WindowShowStyle.Restore), Times.Once());
            Assert.That(window.WindowState, Is.EqualTo(WindowState.Normal));
        }
    
        [Test]
        public void RestoreWindow_CalledAfterMinimizedFromNormal_RestoresTheWindowBackToMaximized()
        {
            var window = Utils.OpenDummyWindow();
            window.WindowState = WindowState.Maximized;
    
            window.WindowState = WindowState.Minimized;
            _target.RestoreWindow(window);
    
            _user32.Verify(x => x.ShowWindow(It.IsAny<nint>(), WindowShowStyle.Restore), Times.Once());
            Assert.That(window.WindowState, Is.EqualTo(WindowState.Maximized));
        }
    }
    

License

Copyright (c) David Wendland. All rights reserved. Licensed under the MIT License. See LICENSE file in the project root for full license information.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated