├── .gitattributes ├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── README.md ├── azure-pipelines.yml ├── doc ├── api │ └── index.md ├── apidoc │ └── readme.txt ├── articles │ ├── intro.md │ └── toc.yml ├── docfx.json ├── filterConfig.yml ├── images │ ├── d.svg │ ├── favicon.ico │ └── logo.svg ├── index.md ├── template │ └── partials │ │ └── navbar.tmpl.partial └── toc.yml └── src ├── Dapplo.Windows.Advapi32 ├── Advapi32Api.cs ├── Dapplo.Windows.Advapi32.csproj ├── Enums │ ├── RegistryKeySecurityAccessRights.cs │ ├── RegistryNotifyFilter.cs │ ├── RegistryOpenOptions.cs │ └── TokenInformationClasses.cs ├── RegistryMonitor.cs ├── Structs │ ├── SidAndAttributes.cs │ └── TokenGroups.cs └── app.config ├── Dapplo.Windows.Citrix ├── Dapplo.Windows.Citrix.csproj ├── Enums │ ├── ConnectStates.cs │ ├── EventMask.cs │ └── InfoClasses.cs ├── Structs │ ├── AppInfo.cs │ ├── ClientAddress.cs │ ├── ClientDisplay.cs │ ├── ClientInfo.cs │ ├── ClientLatency.cs │ ├── OsVersionInfo.cs │ ├── SessionTime.cs │ └── UserInfo.cs └── WinFrame.cs ├── Dapplo.Windows.Clipboard ├── ClipboardAccessDeniedException.cs ├── ClipboardByteExtensions.cs ├── ClipboardFileExtensions.cs ├── ClipboardFormatExtensions.cs ├── ClipboardMiscExtensions.cs ├── ClipboardNative.cs ├── ClipboardRenderFormatRequest.cs ├── ClipboardStreamExtensions.cs ├── ClipboardStringExtensions.cs ├── ClipboardUpdateInformation.cs ├── Dapplo.Windows.Clipboard.csproj ├── IClipboardAccessToken.cs ├── Internals │ ├── ClipboardAccessToken.cs │ ├── ClipboardInfoExtensions.cs │ ├── ClipboardNativeInfo.cs │ ├── ClipboardSemaphore.cs │ ├── NativeMethods.cs │ └── UnmanagedMemoryStreamWrapper.cs ├── StandardClipboardFormats.cs └── app.config ├── Dapplo.Windows.Com ├── ComProgIdAttribute.cs ├── ComWrapper.cs ├── Dapplo.Windows.Com.csproj ├── DisposableCom.cs ├── DisposableComImplementation.cs ├── IDispatch.cs ├── IDisposableCom.cs ├── IOleCommandTarget.cs ├── IOleWindow.cs ├── IUnknown.cs ├── Ole32Api.cs └── OleAut32Api.cs ├── Dapplo.Windows.Common ├── Dapplo.Windows.Common.csproj ├── Enums │ ├── AdjacentTo.cs │ ├── HRESULT.cs │ └── Win32Error.cs ├── Extensions │ ├── EnumExtensions.cs │ ├── HResultExtensions.cs │ ├── NativePointExtensions.cs │ ├── NativePointFloatExtensions.cs │ ├── NativeRectExtensions.cs │ ├── NativeRectFloatExtensions.cs │ ├── NativeSizeExtensions.cs │ └── NativeSizeFloatExtensions.cs ├── Structs │ ├── NativePoint.cs │ ├── NativePointFloat.cs │ ├── NativeRect.cs │ ├── NativeRectFloat.cs │ ├── NativeSize.cs │ └── NativeSizeFloat.cs ├── TypeConverters │ ├── NativePointTypeConverter.cs │ ├── NativeRectFloatTypeConverter.cs │ ├── NativeRectTypeConverter.cs │ ├── NativeSizeFloatTypeConverter.cs │ └── NativeSizeTypeConverter.cs ├── Win32.cs └── WindowsVersion.cs ├── Dapplo.Windows.DesktopWindowsManager ├── Dapplo.Windows.DesktopWindowsManager.csproj ├── DwmApi.cs ├── Enums │ ├── DwmBlurBehindFlags.cs │ ├── DwmSetIconicLivePreviewFlags.cs │ ├── DwmThumbnailPropertyFlags.cs │ ├── DwmWindowAttributes.cs │ └── DwmWindowCornerPreference.cs └── Structs │ ├── DwmBlurBehind.cs │ └── DwmThumbnailProperties.cs ├── Dapplo.Windows.Devices ├── Dapplo.Windows.Devices.csproj ├── DeviceInterfaceChangeInfo.cs ├── DeviceNotification.cs ├── DeviceNotificationEvent.cs ├── Enums │ ├── DeviceBroadcastDeviceType.cs │ ├── DeviceChangeEvent.cs │ ├── DeviceInterfaceClass.cs │ └── DeviceNotifyFlags.cs ├── Structs │ ├── DevBroadcastDeviceInterface.cs │ ├── DevBroadcastHandle.cs │ ├── DevBroadcastHeader.cs │ ├── DevBroadcastPort.cs │ └── DevBroadcastVolume.cs ├── VolumeInfo.cs └── app.config ├── Dapplo.Windows.Dpi ├── BitmapScaleHandler.cs ├── Dapplo.Windows.Dpi.csproj ├── DpiCalculator.cs ├── DpiChangeInfo.cs ├── DpiHandler.cs ├── Enums │ ├── DialogDpiChangeBehaviors.cs │ ├── DialogScalingBehaviors.cs │ ├── DpiAwareness.cs │ ├── DpiAwarenessContext.cs │ ├── DpiHostingBehavior.cs │ └── MonitorDpiType.cs ├── Forms │ ├── DpiAwareForm.cs │ ├── DpiUnawareForm.cs │ └── FormsDpiExtensions.cs ├── NativeDpiMethods.cs ├── Wpf │ └── WindowDpiExtensions.cs └── app.config ├── Dapplo.Windows.EmbeddedBrowser ├── Dapplo.Windows.EmbeddedBrowser.csproj ├── ExtendedWebBrowser.cs └── InternetExplorerVersion.cs ├── Dapplo.Windows.Example.ConsoleDemo ├── App.config ├── Dapplo.Windows.Example.ConsoleDemo.csproj └── Program.cs ├── Dapplo.Windows.Example.FormsExample ├── App.config ├── Dapplo.Windows.Example.FormsExample.csproj ├── FodyWeavers.xml ├── FormDpiUnaware.Designer.cs ├── FormDpiUnaware.cs ├── FormDpiUnaware.resx ├── FormExtendsDpiAwareForm.Designer.cs ├── FormExtendsDpiAwareForm.cs ├── FormExtendsDpiAwareForm.resx ├── FormWithAttachedDpiHandler.Designer.cs ├── FormWithAttachedDpiHandler.cs ├── FormWithAttachedDpiHandler.resx ├── Program.cs ├── Properties │ ├── Resources.Designer.cs │ └── Resources.resx ├── WebBrowserExtensions.cs ├── WebBrowserForm.Designer.cs ├── WebBrowserForm.cs ├── app.manifest ├── help.png └── layer-rotate.png ├── Dapplo.Windows.Example.WpfExample ├── App.config ├── App.xaml ├── App.xaml.cs ├── Dapplo.Windows.Example.WpfExample.csproj ├── Icons │ └── delete.png ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── app.manifest └── icon.png ├── Dapplo.Windows.Gdi32 ├── Dapplo.Windows.Gdi32.csproj ├── Enums │ ├── BitmapCompressionMethods.cs │ ├── ColorSpace.cs │ ├── DeviceCaps.cs │ ├── DibColors.cs │ ├── GdiPlusStatus.cs │ ├── GpUnit.cs │ └── RasterOperations.cs ├── Gdi32Api.cs ├── GdiExtensions.cs ├── GdiPlusApi.cs ├── SafeHandles │ ├── SafeCompatibleDcHandle.cs │ ├── SafeDcHandle.cs │ ├── SafeDibSectionHandle.cs │ ├── SafeGraphicsDcHandle.cs │ ├── SafeHBitmapHandle.cs │ ├── SafeObjectHandle.cs │ ├── SafeRegionHandle.cs │ ├── SafeSelectObjectHandle.cs │ └── SafeWindowDcHandle.cs ├── Structs │ ├── BitfieldColorMask.cs │ ├── BitmapFileHeader.cs │ ├── BitmapInfoHeader.cs │ ├── BitmapV4Header.cs │ ├── BitmapV5Header.cs │ ├── BlurParams.cs │ ├── CieXyz.cs │ ├── CieXyzTripple.cs │ └── RgbQuad.cs └── app.config ├── Dapplo.Windows.Icons ├── CursorHelper.cs ├── Dapplo.Windows.Icons.csproj ├── Enums │ ├── FolderIconType.cs │ └── IconSize.cs ├── IconExtensions.cs ├── IconHelper.cs ├── NativeCursorMethods.cs ├── NativeIconMethods.cs ├── SafeHandles │ └── SafeIconHandle.cs ├── Structs │ └── IconInfo.cs └── app.config ├── Dapplo.Windows.Input ├── Dapplo.Windows.Input.csproj ├── Enums │ ├── ExtendedKeyFlags.cs │ ├── ExtendedMouseFlags.cs │ ├── HidUsagePages.cs │ ├── HidUsagesConsumer.cs │ ├── HidUsagesGeneric.cs │ ├── HookTypes.cs │ ├── InputTypes.cs │ ├── KeyEventFlags.cs │ ├── MapVkType.cs │ ├── MouseButtonStates.cs │ ├── MouseButtons.cs │ ├── MouseEventFlags.cs │ ├── MouseStates.cs │ ├── RawInputDataCommands.cs │ ├── RawInputDeviceFlags.cs │ ├── RawInputDeviceInfoCommands.cs │ ├── RawInputDeviceTypes.cs │ ├── RawInputDevices.cs │ ├── RawKeyboardFlags.cs │ ├── ScanCodes.cs │ └── VirtualKeyCode.cs ├── Keyboard │ ├── IKeyboardHookEventHandler.cs │ ├── KeyCombinationHandler.cs │ ├── KeyHelper.cs │ ├── KeyOrCombinationHandler.cs │ ├── KeySequenceHandler.cs │ ├── KeyboardHook.cs │ ├── KeyboardHookEventArgs.cs │ ├── KeyboardHookExtensions.cs │ ├── KeyboardInputGenerator.cs │ └── VirtualKeyCodeExtensions.cs ├── Mouse │ ├── MouseHook.cs │ ├── MouseHookEventArgs.cs │ └── MouseInputGenerator.cs ├── NativeInput.cs ├── RawInputApi.cs ├── RawInputDeviceChangeEventArgs.cs ├── RawInputDeviceInformation.cs ├── RawInputEventArgs.cs ├── RawInputMonitor.cs ├── Structs │ ├── HardwareInput.cs │ ├── Input.cs │ ├── InputUnion.cs │ ├── KeyboardInput.cs │ ├── KeyboardLowLevelHookStruct.cs │ ├── LastInputInfo.cs │ ├── MouseInput.cs │ ├── MouseLowLevelHookStruct.cs │ ├── RawDevice.cs │ ├── RawHID.cs │ ├── RawInput.cs │ ├── RawInputDevice.cs │ ├── RawInputDeviceInfo.cs │ ├── RawInputDeviceInfoHID.cs │ ├── RawInputDeviceInfoKeyboard.cs │ ├── RawInputDeviceInfoMouse.cs │ ├── RawInputDeviceList.cs │ ├── RawInputHeader.cs │ ├── RawKeyboard.cs │ └── RawMouse.cs └── app.config ├── Dapplo.Windows.Kernel32 ├── Dapplo.Windows.Kernel32.csproj ├── Enums │ ├── DefaultDllDirectories.cs │ ├── GlobalMemorySettings.cs │ ├── ProcessAccessRights.cs │ ├── ThreadAccess.cs │ ├── WindowsProductTypes.cs │ ├── WindowsProducts.cs │ └── WindowsSuites.cs ├── Kernel32Api.cs ├── PackageInfo.cs ├── PsAPI.cs └── Structs │ └── OsVersionInfoEx.cs ├── Dapplo.Windows.Messages ├── Dapplo.Windows.Messages.csproj ├── Enumerations │ └── WindowsMessages.cs ├── MessageLoop.cs ├── Structs │ └── Msg.cs ├── WinProcFormsExtensions.cs ├── WinProcHandler.cs ├── WinProcHandlerHook.cs ├── WinProcListener.cs ├── WinProcWindowsExtensions.cs ├── WindowMessageInfo.cs ├── WindowsMessage.cs └── app.config ├── Dapplo.Windows.Multimedia ├── Dapplo.Windows.Multimedia.csproj ├── Enums │ ├── SoundSettings.cs │ └── SystemSounds.cs └── WinMm.cs ├── Dapplo.Windows.Shell32 ├── Dapplo.Windows.Shell32.csproj ├── Enums │ ├── AppBarEdges.cs │ ├── AppBarMessages.cs │ ├── AppBarStates.cs │ ├── ShellFileAttributeFlags.cs │ └── ShellGetFileInfoFlags.cs ├── Shell32Api.cs └── Structs │ ├── AppBarData.cs │ └── ShellFileInfo.cs ├── Dapplo.Windows.Tests.Benchmarks ├── ClipboardBenchmarks.cs ├── Dapplo.Windows.Tests.Benchmarks.csproj ├── EnumerateWindowsBenchmark.cs ├── InteropWindowBenchmark.cs ├── Program.cs └── ScreenboundsBenchmark.cs ├── Dapplo.Windows.Tests ├── AppWindowTests.cs ├── CitrixTests.cs ├── ClipboardTests.cs ├── ComInterfaces │ ├── ExcelApplicationClass.cs │ └── IExcelApplication.cs ├── ComTests.cs ├── CommonStructTests.cs ├── Dapplo.Windows.Tests.csproj ├── DeviceTests.cs ├── DisplayTest.cs ├── DpiTests.cs ├── DwmTest.cs ├── IconTests.cs ├── InputTests.cs ├── InteropWindowTests.cs ├── Kernel32Tests.cs ├── KeyboardHookTests.cs ├── MouseHookTests.cs ├── Properties │ └── AssemblyInfo.cs ├── RawInputTests.cs ├── RectTests.cs ├── RegistryTests.cs ├── SafeHandleTests.cs ├── ScrollingTests.cs ├── Shell32Tests.cs ├── SoftwareInstallationTests.cs ├── User32Tests.cs ├── VersionTests.cs ├── WinEventHookTests.cs ├── WindowsEnumeratorTests.cs ├── app.config └── xunit.runner.json ├── Dapplo.Windows.User32 ├── Dapplo.Windows.User32.csproj ├── DisplayInfo.cs ├── Enums │ ├── ClassLongIndex.cs │ ├── CursorInfoFlags.cs │ ├── DesktopAccessRight.cs │ ├── ExtendedWindowStyleFlags.cs │ ├── GetWindowCommands.cs │ ├── MonitorFrom.cs │ ├── MonitorInfoFlags.cs │ ├── ObjectIdentifiers.cs │ ├── ObjectStates.cs │ ├── PrintWindowFlags.cs │ ├── RegionResults.cs │ ├── ScrollBarCommands.cs │ ├── ScrollBarStateIndexes.cs │ ├── ScrollBarTypes.cs │ ├── ScrollInfoMask.cs │ ├── ScrollModes.cs │ ├── SendMessageTimeoutFlags.cs │ ├── ShowWindowCommands.cs │ ├── SysColorIndexes.cs │ ├── SysCommands.cs │ ├── SystemMetric.cs │ ├── SystemParametersInfoActions.cs │ ├── SystemParametersInfoBehaviors.cs │ ├── TitleBarInfoIndexes.cs │ ├── WindowDisplayAffinity.cs │ ├── WindowLongIndex.cs │ ├── WindowPos.cs │ ├── WindowStyleFlags.cs │ └── windowPlacementFlags.cs ├── SafeHandles │ └── SafeCurrentInputDesktopHandle.cs ├── Structs │ ├── AnimationInfo.cs │ ├── CursorInfo.cs │ ├── MonitorInfoEx.cs │ ├── ScrollBarInfo.cs │ ├── ScrollInfo.cs │ ├── TitleBarInfoEx.cs │ ├── WindowInfo.cs │ └── WindowPlacement.cs ├── TypeConverters │ └── WindowPlacementTypeConverter.cs ├── User32Api.cs └── app.config ├── Dapplo.Windows.sln ├── Dapplo.Windows.snk ├── Dapplo.Windows ├── App │ ├── AppQuery.cs │ ├── IAppVisibility.cs │ └── MonitorAppVisibility.cs ├── Dapplo.Windows.csproj ├── Desktop │ ├── EnvironmentChangedEventArgs.cs │ ├── EnvironmentMonitor.cs │ ├── IInteropWindow.cs │ ├── InteropWindow.cs │ ├── InteropWindowExtensions.cs │ ├── InteropWindowFactory.cs │ ├── InteropWindowQuery.cs │ ├── WinEventHook.cs │ ├── WindowScroller.cs │ └── WindowsEnumerator.cs ├── Enums │ ├── InteropWindowRetrieveSettings.cs │ ├── WinEventHookFlags.cs │ └── WinEvents.cs ├── Extensions │ ├── BtmapExtensions.cs │ ├── FormsExtensions.cs │ └── WindowsExtensions.cs ├── Software │ ├── InstallationInformation.cs │ └── SoftwareDetails.cs ├── Structs │ └── WinEventInfo.cs └── app.config ├── Directory.Build.props ├── NuGet.Config ├── global.json ├── icon.png └── version.json /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | github: lakritzator 5 | patreon: # Replace with a single Patreon username 6 | open_collective: # Replace with a single open collective project 7 | ko_fi: # Replace with a single Ko-fi username 8 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 9 | custom: # Replace with a custom url 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Dapplo and Contributors 4 | 5 | All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /doc/api/index.md: -------------------------------------------------------------------------------- 1 | # Dapplo.Windows API Description 2 | 3 | Here is the API described.. 4 | -------------------------------------------------------------------------------- /doc/apidoc/readme.txt: -------------------------------------------------------------------------------- 1 | Here are over-write files located 2 | -------------------------------------------------------------------------------- /doc/articles/intro.md: -------------------------------------------------------------------------------- 1 | # Dapplo.Windows 2 | -------------------------------------------------------------------------------- /doc/articles/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Introduction 2 | href: intro.md 3 | -------------------------------------------------------------------------------- /doc/docfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": [ 3 | { 4 | "src": [ 5 | { 6 | "src": "../src", 7 | "files": [ 8 | "**/*.csproj" 9 | ], 10 | "exclude": [ 11 | "**/bin/**", 12 | "**/obj/**", 13 | "**Tests/*.csproj", 14 | "**Example/*.csproj", 15 | ] 16 | } 17 | ], 18 | "dest": "api", 19 | "filter": "filterConfig.yml" 20 | } 21 | ], 22 | "build": { 23 | "content": [ 24 | { 25 | "files": [ 26 | "api/**.md", 27 | "api/**.yml", 28 | "articles/**.md", 29 | "articles/**/toc.yml", 30 | "toc.yml", 31 | "*.md" 32 | ], 33 | "exclude": [ 34 | "_site/**", 35 | "README.md" 36 | ] 37 | } 38 | ], 39 | "resource": [ 40 | { 41 | "files": [ 42 | "images/**" 43 | ], 44 | } 45 | ], 46 | "overwrite": [ 47 | { 48 | "files": [ 49 | "apidoc/**.md" 50 | ], 51 | } 52 | ], 53 | "dest": "_site", 54 | "globalMetadata": { 55 | "_appTitle": "Dapplo.Windows", 56 | "_appLogoPath": "images/d.svg", 57 | "_appFaviconPath": "images/favicon.ico", 58 | "_appFooter": "Copyright © 2017 Dapplo" 59 | }, 60 | "globalMetadataFiles": [], 61 | "template": [ 62 | "statictoc", 63 | "template" 64 | ], 65 | "fileMetadataFiles": [], 66 | "postProcessors": [], 67 | "noLangKeyword": false 68 | } 69 | } -------------------------------------------------------------------------------- /doc/filterConfig.yml: -------------------------------------------------------------------------------- 1 | apiRules: 2 | - exclude: 3 | uidRegex: ^.*PowerShell.*$ 4 | type: Namespace 5 | -------------------------------------------------------------------------------- /doc/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dapplo/Dapplo.Windows/55d2ca3705b75403fbf6d00cf9dd2b8b7a8a3d12/doc/images/favicon.ico -------------------------------------------------------------------------------- /doc/template/partials/navbar.tmpl.partial: -------------------------------------------------------------------------------- 1 | {{!Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.}} 2 | 3 | -------------------------------------------------------------------------------- /doc/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Articles 2 | href: articles/ 3 | - name: Api Documentation 4 | href: api/ 5 | homepage: api/index.md 6 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Advapi32/Dapplo.Windows.Advapi32.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Advapi32 is a library for accessing the Advanced Windows 32 Base API 4 | windows native Advapi32 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | true 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Advapi32/Enums/RegistryNotifyFilter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | 6 | namespace Dapplo.Windows.Advapi32.Enums; 7 | 8 | /// 9 | /// A value that indicates the changes that should be reported 10 | /// 11 | [Flags] 12 | public enum RegistryNotifyFilter 13 | { 14 | /// Notify the caller if a subkey is added or deleted. 15 | ChangeName = 1, 16 | /// Notify the caller of changes to the attributes of the key, 17 | /// such as the security descriptor information. 18 | ChangeAttributes = 2, 19 | /// Notify the caller of changes to a value of the key. This can 20 | /// include adding or deleting a value, or changing an existing value. 21 | ChangeLastSet = 4, 22 | /// Notify the caller of changes to the security descriptor 23 | /// of the key. 24 | ChangeSecurity = 8, 25 | /// 26 | /// Indicates that the lifetime of the registration must not be tied to the lifetime of the thread issuing the RegNotifyChangeKeyValue call. 27 | /// Note This flag value is only supported in Windows 8 and later. 28 | /// 29 | ThreadAgnostic = 0x10000000 30 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Advapi32/Enums/RegistryOpenOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | 6 | namespace Dapplo.Windows.Advapi32.Enums; 7 | 8 | /// 9 | /// Specifies the option to apply when opening the key. 10 | /// 11 | [Flags] 12 | public enum RegistryOpenOptions 13 | { 14 | /// 15 | /// No options 16 | /// 17 | None = 0, 18 | /// 19 | /// The key is a symbolic link. Registry symbolic links should only be used when absolutely necessary. 20 | /// 21 | OpenLink = 8 22 | 23 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Advapi32/Structs/SidAndAttributes.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace Dapplo.Windows.Advapi32.Structs; 8 | 9 | /// 10 | /// The SID_AND_ATTRIBUTES structure represents a security identifier (SID) and its attributes. 11 | /// SIDs are used to uniquely identify users or groups. 12 | /// 13 | [StructLayout(LayoutKind.Sequential)] 14 | public struct SidAndAttributes 15 | { 16 | /// 17 | /// A pointer to a SID structure. 18 | /// 19 | public IntPtr Sid; 20 | /// 21 | /// Specifies attributes of the SID. This value contains up to 32 one-bit flags. Its meaning depends on the definition and use of the SID. 22 | /// 23 | public readonly uint Attributes; 24 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Advapi32/Structs/TokenGroups.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Dapplo.Windows.Advapi32.Structs; 7 | 8 | /// 9 | /// The TOKEN_GROUPS structure contains information about the group security identifiers (SIDs) in an access token. 10 | /// 11 | [StructLayout(LayoutKind.Sequential)] 12 | public struct TokenGroups 13 | { 14 | /// 15 | /// Specifies the number of groups in the access token. 16 | /// 17 | public readonly int GroupCount; 18 | /// 19 | /// Specifies an array of SID_AND_ATTRIBUTES structures that contain a set of SIDs and corresponding attributes. 20 | /// The Attributes members of the SID_AND_ATTRIBUTES structures can have the following values. 21 | /// 22 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] 23 | public SidAndAttributes[] Groups; 24 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Advapi32/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Citrix/Dapplo.Windows.Citrix.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Citrix is a library which has citrix supporting code 4 | windows native citrix 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Citrix/Enums/ConnectStates.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Citrix.Enums; 4 | 5 | /// 6 | /// The connect states 7 | /// 8 | public enum ConnectStates 9 | { 10 | /// 11 | /// WFActive: User logged on to WinStation 12 | /// 13 | Active, 14 | 15 | /// 16 | /// WFConnected: WinStation connected to client 17 | /// 18 | Connected, 19 | 20 | /// 21 | /// WFConnectQuery: In the process of connecting to client 22 | /// 23 | ConnectQuery, 24 | 25 | /// 26 | /// WFShadow: Shadowing another WinStation 27 | /// 28 | Shadow, 29 | 30 | /// 31 | /// WFDisconnected: WinStation logged on without client 32 | /// 33 | Disconnected, 34 | 35 | /// 36 | /// WFIdle: Waiting for client to connect 37 | /// 38 | Idle, 39 | 40 | /// 41 | /// WFListen: WinStation is listening for connection 42 | /// 43 | Listen, 44 | 45 | /// 46 | /// WFReset: WinStation is being reset 47 | /// 48 | Reset, 49 | 50 | /// 51 | /// WFDown: WinStation is down due to error 52 | /// 53 | Down, 54 | 55 | /// 56 | /// WFInit: WinStation in initialization 57 | /// 58 | Init 59 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Citrix/Structs/AppInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Runtime.InteropServices; 4 | 5 | namespace Dapplo.Windows.Citrix.Structs; 6 | 7 | /// 8 | /// This structure is returned when WFQuerySessionInformation is called with WFInfoClasses.AppInfo 9 | /// 10 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 11 | public struct AppInfo 12 | { 13 | [MarshalAs(UnmanagedType.LPWStr)] 14 | private readonly string _initialProgram; 15 | [MarshalAs(UnmanagedType.LPWStr)] 16 | private readonly string _workingDirectory; 17 | [MarshalAs(UnmanagedType.LPWStr)] 18 | private readonly string _applicationName; 19 | 20 | /// 21 | /// Return the InitialProgram 22 | /// 23 | public string InitialProgram => _initialProgram; 24 | 25 | /// 26 | /// Return the WorkingDirectory 27 | /// 28 | public string WorkingDirectory => _workingDirectory; 29 | 30 | /// 31 | /// Return the application name 32 | /// 33 | public string ApplicationName => _applicationName; 34 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Citrix/Structs/ClientAddress.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Net.Sockets; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Dapplo.Windows.Citrix.Structs; 7 | 8 | /// 9 | /// This structure is returned when WFQuerySessionInformation is called with WFInfoClasses.ClientAddress 10 | /// 11 | [StructLayout(LayoutKind.Sequential)] 12 | public unsafe struct ClientAddress 13 | { 14 | private readonly int _adressFamily; 15 | 16 | private fixed byte _address[20]; 17 | 18 | /// 19 | /// Address Family 20 | /// 21 | public AddressFamily AddressFamily => (AddressFamily)_adressFamily; 22 | 23 | /// 24 | /// IP Address used 25 | /// 26 | public string IpAddress 27 | { 28 | get 29 | { 30 | fixed (byte* address = _address) 31 | { 32 | return $"{address[2]}.{address[3]}.{address[4]}.{address[5]}"; 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Citrix/Structs/ClientDisplay.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Runtime.InteropServices; 4 | using Dapplo.Windows.Common.Structs; 5 | 6 | namespace Dapplo.Windows.Citrix.Structs; 7 | 8 | /// 9 | /// This structure is returned when WFQuerySessionInformation is called with WFInfoClasses.ClientDisplay 10 | /// 11 | [StructLayout(LayoutKind.Sequential)] 12 | public struct ClientDisplay 13 | { 14 | private readonly uint _horizontalResolution; 15 | private readonly uint _verticalResolution; 16 | private readonly uint _colorDepth; 17 | 18 | /// 19 | /// Return the client's display size 20 | /// 21 | public NativeSize ClientSize => new NativeSize((int)_horizontalResolution, (int)_verticalResolution); 22 | 23 | /// 24 | /// Returns the number of colors the client can display 25 | /// 26 | public uint ColorDepth 27 | { 28 | get => _colorDepth switch 29 | { 30 | 1 => 4, 31 | 2 => 8, 32 | 4 => 16, 33 | 8 => 24, 34 | 16 => 32, 35 | _ => _colorDepth 36 | }; 37 | } 38 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Citrix/Structs/ClientInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Runtime.InteropServices; 4 | 5 | namespace Dapplo.Windows.Citrix.Structs; 6 | 7 | /// 8 | /// This structure is returned when WFQuerySessionInformation is called with WFInfoClasses.ClientInfo 9 | /// 10 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 11 | public struct ClientInfo 12 | { 13 | [MarshalAs(UnmanagedType.LPWStr)] 14 | private readonly string _name; 15 | [MarshalAs(UnmanagedType.LPWStr)] 16 | private readonly string _directory; 17 | private readonly int _buildNumber; 18 | private readonly int _productId; 19 | private readonly int _hardwareId; 20 | private readonly ClientAddress _address; 21 | 22 | /// 23 | /// Return the client's name 24 | /// 25 | public string Name => _name; 26 | 27 | /// 28 | /// Return the client's directory 29 | /// 30 | public string Directory => _directory; 31 | 32 | /// 33 | /// Return the client's BuildNumber 34 | /// 35 | public int BuildNumber => _buildNumber; 36 | 37 | /// 38 | /// Return the client's product ID 39 | /// 40 | public int ProductId => _productId; 41 | 42 | /// 43 | /// Return the client's hardware ID 44 | /// 45 | public int HardwareId => _hardwareId; 46 | 47 | /// 48 | /// Return the client's address 49 | /// 50 | public ClientAddress Address => _address; 51 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Citrix/Structs/ClientLatency.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Runtime.InteropServices; 4 | 5 | namespace Dapplo.Windows.Citrix.Structs; 6 | 7 | /// 8 | /// This structure is returned when WFQuerySessionInformation is called with WFInfoClasses.ClientLatency 9 | /// 10 | [StructLayout(LayoutKind.Sequential)] 11 | public struct ClientLatency 12 | { 13 | private readonly uint _avarage; 14 | private readonly uint _last; 15 | private readonly uint _derivation; 16 | 17 | /// 18 | /// Return the client's avarage latency 19 | /// 20 | public uint Avarage => _avarage; 21 | /// 22 | /// Return the client's last latency 23 | /// 24 | public uint Last => _last; 25 | 26 | /// 27 | /// Return the client's latency derivation 28 | /// 29 | public uint Derivation => _derivation; 30 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Citrix/Structs/SessionTime.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Runtime.InteropServices; 4 | 5 | namespace Dapplo.Windows.Citrix.Structs; 6 | 7 | /// 8 | /// This structure is returned when WFQuerySessionInformation is called with WFInfoClasses.SessionTime 9 | /// 10 | [StructLayout(LayoutKind.Sequential)] 11 | public struct SessionTime 12 | { 13 | private readonly double _connectTime; 14 | private readonly double _disconnectTime; 15 | private readonly double _lastInputTime; 16 | private readonly double _logonTime; 17 | private readonly double _currentTime; 18 | 19 | /// 20 | /// Return the username 21 | /// 22 | public double ConnectTime => _connectTime; 23 | 24 | /// 25 | /// Return the last disconnect time 26 | /// 27 | public double DisconnectTime => _disconnectTime; 28 | 29 | /// 30 | /// Return the last input time 31 | /// 32 | public double LastInputTime => _lastInputTime; 33 | 34 | /// 35 | /// Return the logon time 36 | /// 37 | public double LogonTime => _logonTime; 38 | 39 | /// 40 | /// Return the current time 41 | /// 42 | public double CurrentTime => _currentTime; 43 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Citrix/Structs/UserInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Runtime.InteropServices; 4 | 5 | namespace Dapplo.Windows.Citrix.Structs; 6 | 7 | /// 8 | /// This structure is returned when WFQuerySessionInformation is called with WFInfoClasses.UserInfo 9 | /// 10 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 11 | public struct UserInfo 12 | { 13 | [MarshalAs(UnmanagedType.LPWStr)] 14 | private readonly string _userName; 15 | [MarshalAs(UnmanagedType.LPWStr)] 16 | private readonly string _domainName; 17 | [MarshalAs(UnmanagedType.LPWStr)] 18 | private readonly string _connectionName; 19 | 20 | /// 21 | /// Return the username 22 | /// 23 | public string Username => _userName; 24 | 25 | /// 26 | /// Return the domain name 27 | /// 28 | public string Domainname => _domainName; 29 | 30 | /// 31 | /// Return the connection name 32 | /// 33 | public string ConnectionName => _connectionName; 34 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Clipboard/ClipboardAccessDeniedException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Clipboard; 6 | 7 | /// 8 | public class ClipboardAccessDeniedException : Exception 9 | { 10 | /// 11 | public ClipboardAccessDeniedException() 12 | { 13 | } 14 | 15 | /// 16 | public ClipboardAccessDeniedException(string message) : base(message) 17 | { 18 | } 19 | 20 | /// 21 | public ClipboardAccessDeniedException(string message, Exception inner) : base(message, inner) 22 | { 23 | } 24 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Clipboard/ClipboardFileExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Dapplo.Windows.Clipboard.Internals; 6 | 7 | namespace Dapplo.Windows.Clipboard; 8 | 9 | /// 10 | /// These are extensions to work with the clipboard 11 | /// 12 | public static class ClipboardFileExtensions 13 | { 14 | /// 15 | /// Get a list of file-names on the clipboard 16 | /// 17 | /// IClipboard 18 | /// IEnumerable of string 19 | public static IEnumerable GetFileNames(this IClipboardAccessToken clipboardAccessToken) 20 | { 21 | clipboardAccessToken.ThrowWhenNoAccess(); 22 | 23 | var hDrop = NativeMethods.GetClipboardData((uint)StandardClipboardFormats.Drop); 24 | 25 | unsafe 26 | { 27 | var files = NativeMethods.DragQueryFile(hDrop, uint.MaxValue, null, 0); 28 | if (files == 0) 29 | { 30 | return Enumerable.Empty(); 31 | } 32 | 33 | var result = new List(); 34 | const int capacity = 260; 35 | var filename = stackalloc char[capacity]; 36 | for (uint i = 0; i < files; i++) 37 | { 38 | var nrCharacters = NativeMethods.DragQueryFile(hDrop, i, filename, capacity); 39 | if (nrCharacters == 0) 40 | { 41 | continue; 42 | } 43 | result.Add(new string(filename, 0, nrCharacters)); 44 | } 45 | 46 | return result; 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Clipboard/ClipboardRenderFormatRequest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Dapplo.Windows.Clipboard; 5 | 6 | /// 7 | /// Information about the render format request 8 | /// 9 | public class ClipboardRenderFormatRequest 10 | { 11 | private string _requestedFormat; 12 | 13 | /// 14 | /// The format ID which was requested 15 | /// 16 | public uint RequestedFormatId { get; internal set; } 17 | 18 | /// 19 | /// The format which was requested 20 | /// 21 | public string RequestedFormat { 22 | get 23 | { 24 | if (_requestedFormat != null) 25 | { 26 | return _requestedFormat; 27 | } 28 | _requestedFormat = ClipboardFormatExtensions.MapIdToFormat(RequestedFormatId); 29 | return _requestedFormat; 30 | } 31 | } 32 | 33 | /// 34 | /// Specifies if this request specifies that the clipboard is destroyed 35 | /// 36 | public bool IsDestroyClipboard { get; internal set; } 37 | 38 | /// 39 | /// If you need to render all formats, this is true 40 | /// 41 | public bool RenderAllFormats => RequestedFormatId == 0; 42 | 43 | /// 44 | /// The access token for the clipboard access 45 | /// 46 | public IClipboardAccessToken AccessToken { get; internal set; } 47 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Clipboard/Dapplo.Windows.Clipboard.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Clipboard is a library for accessing the clipboard in a more modern way. 4 | windows native clipboard 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | true 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Clipboard/IClipboardAccessToken.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Clipboard; 6 | 7 | /// 8 | /// This interface is returned by the ClipboardNative.Access(), which calls the ClipboardLockProvider. 9 | /// The access token is only valid within the same thread or window. 10 | /// When you got a IClipboardAccessToken, you can access the clipboard, until it's disposed. 11 | /// Don't forget to dispose this!!! 12 | /// 13 | public interface IClipboardAccessToken : IDisposable 14 | { 15 | /// 16 | /// Check if the clipboard can be accessed 17 | /// 18 | bool CanAccess { get; } 19 | 20 | /// 21 | /// The clipboard access was denied due to a timeout 22 | /// 23 | bool IsLockTimeout { get; } 24 | 25 | /// 26 | /// The clipboard couldn't be opened 27 | /// 28 | bool IsOpenTimeout { get; } 29 | 30 | /// 31 | /// This throws a ClipboardAccessDeniedException when the clipboard can't be accessed 32 | /// 33 | void ThrowWhenNoAccess(); 34 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Clipboard/Internals/ClipboardAccessToken.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Clipboard.Internals; 6 | 7 | /// 8 | /// This is the clipboard access token 9 | /// 10 | internal class ClipboardAccessToken : IClipboardAccessToken 11 | { 12 | private readonly Action _disposeAction; 13 | 14 | public ClipboardAccessToken(Action disposeAction = null) 15 | { 16 | _disposeAction = disposeAction; 17 | } 18 | 19 | /// 20 | public void Dispose() 21 | { 22 | CanAccess = false; 23 | _disposeAction?.Invoke(); 24 | } 25 | 26 | /// 27 | public bool CanAccess { get; internal set; } = true; 28 | 29 | /// 30 | public bool IsOpenTimeout { get; internal set; } 31 | 32 | /// 33 | public bool IsLockTimeout { get; internal set; } 34 | 35 | /// 36 | public void ThrowWhenNoAccess() 37 | { 38 | if (CanAccess) 39 | { 40 | return; 41 | } 42 | 43 | if (IsLockTimeout) 44 | { 45 | throw new ClipboardAccessDeniedException("The clipboard was already locked by another thread or task in your application, a timeout occured."); 46 | } 47 | if (IsOpenTimeout) 48 | { 49 | throw new ClipboardAccessDeniedException("The clipboard couldn't be opened for usage, it's probably locked by another process"); 50 | } 51 | throw new ClipboardAccessDeniedException("The clipboard is no longer locked, please check your disposing code."); 52 | } 53 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Clipboard/Internals/ClipboardNativeInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using Dapplo.Windows.Kernel32; 5 | 6 | namespace Dapplo.Windows.Clipboard.Internals; 7 | 8 | /// 9 | /// This class contains native information to handle the clipboard contents 10 | /// 11 | internal class ClipboardNativeInfo : IDisposable 12 | { 13 | internal IntPtr GlobalHandle { get; set; } 14 | internal bool NeedsWrite { get; set; } 15 | 16 | /// 17 | /// The format id which is processed 18 | /// 19 | internal uint FormatId { get; set; } 20 | internal IntPtr MemoryPtr { get; set; } 21 | 22 | /// 23 | /// Returns the size of the clipboard area 24 | /// 25 | internal int Size => Kernel32Api.GlobalSize(GlobalHandle); 26 | 27 | /// 28 | /// Cleanup this native info by unlocking the global handle 29 | /// 30 | public void Dispose() 31 | { 32 | if (NeedsWrite) 33 | { 34 | // Place the content on the clipboard 35 | NativeMethods.SetClipboardDataWithErrorHandling(FormatId, GlobalHandle); 36 | } 37 | Kernel32Api.GlobalUnlock(GlobalHandle); 38 | } 39 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Clipboard/Internals/UnmanagedMemoryStreamWrapper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.IO; 5 | 6 | namespace Dapplo.Windows.Clipboard.Internals; 7 | 8 | /// 9 | /// This wraps an UnmanagedMemoryStream, to also take care or disposing some disposable 10 | /// 11 | internal class UnmanagedMemoryStreamWrapper : UnmanagedMemoryStream 12 | { 13 | private IDisposable _disposable; 14 | 15 | public unsafe UnmanagedMemoryStreamWrapper(byte* bytes, long length, long capacity, FileAccess fileAccess) : base(bytes, length, capacity, fileAccess) 16 | { 17 | } 18 | 19 | public void SetDisposable(IDisposable disposable) 20 | { 21 | _disposable = disposable; 22 | } 23 | 24 | protected override void Dispose(bool disposing) 25 | { 26 | base.Dispose(disposing); 27 | _disposable?.Dispose(); 28 | } 29 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Clipboard/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Com/ComProgIdAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Dapplo.Windows.Com; 4 | 5 | /// 6 | /// An attribute to specifiy the ProgID of the COM class to create. (As suggested by Kristen Wegner) 7 | /// 8 | [AttributeUsage(AttributeTargets.Interface)] 9 | public sealed class ComProgIdAttribute : Attribute 10 | { 11 | /// Constructor 12 | /// The COM ProgID. 13 | public ComProgIdAttribute(string value) 14 | { 15 | Value = value; 16 | } 17 | 18 | /// 19 | /// Returns the COM ProgID 20 | /// 21 | public string Value { get; } 22 | 23 | /// 24 | /// Extracts the attribute from the specified type. 25 | /// 26 | /// 27 | /// The interface type. 28 | /// 29 | /// 30 | /// The . 31 | /// 32 | /// 33 | /// is . 34 | /// 35 | public static ComProgIdAttribute GetAttribute(Type interfaceType) 36 | { 37 | if (null == interfaceType) 38 | { 39 | throw new ArgumentNullException(nameof(interfaceType)); 40 | } 41 | 42 | var attributeType = typeof(ComProgIdAttribute); 43 | var attributes = interfaceType.GetCustomAttributes(attributeType, false); 44 | 45 | if (0 == attributes.Length) 46 | { 47 | var interfaces = interfaceType.GetInterfaces(); 48 | foreach (var t in interfaces) 49 | { 50 | interfaceType = t; 51 | attributes = interfaceType.GetCustomAttributes(attributeType, false); 52 | if (0 != attributes.Length) 53 | { 54 | break; 55 | } 56 | } 57 | } 58 | 59 | if (0 == attributes.Length) 60 | { 61 | return null; 62 | } 63 | return (ComProgIdAttribute) attributes[0]; 64 | } 65 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Com/Dapplo.Windows.Com.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Com is a library which has com supporting code 4 | net472;netstandard2.0;netcoreapp3.1;net6.0-windows 5 | windows native Com 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Com/DisposableCom.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Com; 4 | 5 | /// 6 | /// A factory for IDisposableCom 7 | /// 8 | public static class DisposableCom 9 | { 10 | /// 11 | /// Create a ComDisposable for the supplied type object 12 | /// 13 | /// Type for the com object 14 | /// the com object itself 15 | /// IDisposableCom of type T 16 | public static IDisposableCom Create(T comObject) 17 | { 18 | if (Equals(comObject, default(T))) 19 | { 20 | return null; 21 | } 22 | 23 | return new DisposableComImplementation(comObject); 24 | } 25 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Com/DisposableComImplementation.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Dapplo.Windows.Com; 7 | 8 | /// 9 | /// Implementation of the IDisposableCom, this is internal to prevent other code to use it directly 10 | /// 11 | /// Type of the com object 12 | internal class DisposableComImplementation : IDisposableCom 13 | { 14 | public DisposableComImplementation(T obj) 15 | { 16 | ComObject = obj; 17 | } 18 | 19 | public T ComObject { get; private set; } 20 | 21 | /// 22 | /// Cleans up the COM object. 23 | /// 24 | public void Dispose() 25 | { 26 | Dispose(true); 27 | GC.SuppressFinalize(this); 28 | } 29 | 30 | /// 31 | /// Release the COM reference 32 | /// 33 | /// if this was called from the interface. 34 | private void Dispose(bool disposing) 35 | { 36 | if (!disposing) 37 | { 38 | return; 39 | } 40 | // Do not catch an exception from this. 41 | // You may want to remove these guards depending on 42 | // what you think the semantics should be. 43 | if (!Equals(ComObject, default(T)) && Marshal.IsComObject(ComObject)) 44 | { 45 | Marshal.ReleaseComObject(ComObject); 46 | } 47 | ComObject = default; 48 | } 49 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Com/IDisposableCom.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Com; 6 | 7 | /// 8 | /// A simple com wrapper which helps with "using" 9 | /// 10 | /// Type to wrap 11 | public interface IDisposableCom : IDisposable 12 | { 13 | /// 14 | /// The actual com object 15 | /// 16 | T ComObject { get; } 17 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Com/IOleWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Dapplo.Windows.Com; 5 | 6 | /// 7 | /// The IOleWindow interface provides methods that allow an application to obtain the handle to the various windows that participate in in-place activation, and also to enter and exit context-sensitive help mode. 8 | /// See IOleWindow interface 9 | /// 10 | [ComImport] 11 | [Guid("00000114-0000-0000-C000-000000000046")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | public interface IOleWindow 14 | { 15 | /// 16 | /// Retrieves a handle to one of the windows participating in in-place activation (frame, document, parent, or in-place object window) 17 | /// 18 | /// A pointer to a variable that receives the window handle. 19 | void GetWindow(out IntPtr phWnd); 20 | /// 21 | /// Determines whether context-sensitive help mode should be entered during an in-place activation session. 22 | /// 23 | /// TRUE if help mode should be entered; FALSE if it should be exited. 24 | void ContextSensitiveHelp([In] [MarshalAs(UnmanagedType.Bool)] bool fEnterMode); 25 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Com/IUnknown.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Dapplo.Windows.Com; 5 | 6 | /// 7 | /// Enables clients to get pointers to other interfaces on a given object through the QueryInterface method, and manage the existence of the object through the AddRef and Release methods. All other COM interfaces are inherited, directly or indirectly, from IUnknown. Therefore, the three methods in IUnknown are the first entries in the VTable for every interface. 8 | /// 9 | [ComImport] 10 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 11 | [Guid("00000000-0000-0000-C000-000000000046")] 12 | public interface IUnknown 13 | { 14 | /// 15 | /// Retrieves pointers to the supported interfaces on an object. 16 | /// 17 | /// 18 | /// IntPtr 19 | IntPtr QueryInterface(ref Guid riid); 20 | 21 | /// 22 | /// Increments the reference count for an interface on an object. 23 | /// 24 | /// uint 25 | [PreserveSig] 26 | uint AddRef(); 27 | 28 | /// 29 | /// Decrements the reference count for an interface on an object. 30 | /// 31 | /// uint 32 | [PreserveSig] 33 | uint Release(); 34 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Common/Dapplo.Windows.Common.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Common is a library which contains common files for Dapplo.Windows projects 4 | windows native Common 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | true 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Common/Enums/AdjacentTo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Common.Enums; 4 | 5 | /// 6 | /// Where is the rectangle Adjacent to? 7 | /// 8 | public enum AdjacentTo 9 | { 10 | /// 11 | /// It's not connected 12 | /// 13 | None, 14 | /// 15 | /// It's connected on the left side. 16 | /// 17 | Left, 18 | /// 19 | /// It's connected on the right side. 20 | /// 21 | Right, 22 | /// 23 | /// It's connected on the top side. 24 | /// 25 | Top, 26 | /// 27 | /// It's connected on the bottom side. 28 | /// 29 | Bottom 30 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Common/Enums/HRESULT.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Diagnostics.CodeAnalysis; 4 | 5 | namespace Dapplo.Windows.Common.Enums; 6 | 7 | /// 8 | /// The HRESULT represents Windows error codes 9 | /// See wikipedia 10 | /// 11 | [SuppressMessage("ReSharper", "InconsistentNaming")] 12 | public enum HResult 13 | { 14 | #pragma warning disable 1591 15 | S_OK = 0, 16 | S_FALSE = 1, 17 | E_FAIL = unchecked((int) 0x80004005), 18 | E_INVALIDARG = unchecked((int) 0x80070057), 19 | E_NOTIMPL = unchecked((int) 0x80004001), 20 | E_POINTER = unchecked((int) 0x80004003), 21 | E_PENDING = unchecked((int) 0x8000000A), 22 | E_NOINTERFACE = unchecked((int) 0x80004002), 23 | E_ABORT = unchecked((int) 0x80004004), 24 | E_ACCESSDENIED = unchecked((int) 0x80070006), 25 | E_HANDLE = unchecked((int) 0x80070006), 26 | E_UNEXPECTED = unchecked((int) 0x8000FFFF), 27 | E_FILENOTFOUND = unchecked((int) 0x80070002), 28 | E_PATHNOTFOUND = unchecked((int) 0x80070003), 29 | E_INVALID_DATA = unchecked((int) 0x8007000D), 30 | E_OUTOFMEMORY = unchecked((int) 0x8007000E), 31 | E_INSUFFICIENT_BUFFER = unchecked((int) 0x8007007A), 32 | WSAECONNABORTED = unchecked((int) 0x80072745), 33 | WSAECONNRESET = unchecked((int) 0x80072746), 34 | ERROR_TOO_MANY_CMDS = unchecked((int) 0x80070038), 35 | ERROR_NOT_SUPPORTED = unchecked((int) 0x80070032), 36 | TYPE_E_ELEMENTNOTFOUND = unchecked((int) 0x8002802B) 37 | #pragma warning restore 1591 38 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Common/Extensions/EnumExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.ComponentModel; 6 | 7 | namespace Dapplo.Windows.Common.Extensions; 8 | 9 | /// 10 | /// Some enum extensions used throughout the code 11 | /// 12 | public static class EnumExtensions 13 | { 14 | /// 15 | /// Get an attribute of a certain type, placed upon an enum value 16 | /// 17 | /// Type of attribute 18 | /// Enum 19 | /// 20 | public static T GetAttributeOfType(this Enum enumVal) where T : Attribute 21 | { 22 | var type = enumVal.GetType(); 23 | var memInfo = type.GetMember(enumVal.ToString()); 24 | var attributes = memInfo[0].GetCustomAttributes(typeof(T), false); 25 | return attributes.Length > 0 ? (T)attributes[0] : null; 26 | } 27 | 28 | /// 29 | /// Get the description of an enum 30 | /// 31 | /// Enum 32 | /// string 33 | public static string GetEnumDescription(this Enum enumVal) 34 | { 35 | var descriptionAttribute = enumVal.GetAttributeOfType(); 36 | return descriptionAttribute?.Description; 37 | } 38 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Common/Extensions/HResultExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Diagnostics.Contracts; 5 | using System.Runtime.InteropServices; 6 | using Dapplo.Windows.Common.Enums; 7 | 8 | namespace Dapplo.Windows.Common.Extensions; 9 | 10 | /// 11 | /// Extensions to handle the HResult 12 | /// 13 | public static class HResultExtensions 14 | { 15 | /// 16 | /// Test if the HResult represents a fail 17 | /// 18 | /// HResult 19 | /// bool 20 | [Pure] 21 | public static bool Failed(this HResult hResult) 22 | { 23 | return hResult < 0; 24 | } 25 | 26 | /// 27 | /// Test if the HResult represents a success 28 | /// 29 | /// HResult 30 | /// bool 31 | [Pure] 32 | public static bool Succeeded(this HResult hResult) 33 | { 34 | return hResult >= HResult.S_OK; 35 | } 36 | 37 | /// 38 | /// Throw an exception on Failure 39 | /// 40 | /// HResult 41 | public static void ThrowOnFailure(this HResult hResult) 42 | { 43 | if (Failed(hResult)) 44 | { 45 | throw Marshal.GetExceptionForHR((int) hResult); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Common/Extensions/NativeSizeExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Diagnostics.Contracts; 4 | using Dapplo.Windows.Common.Structs; 5 | 6 | namespace Dapplo.Windows.Common.Extensions; 7 | 8 | /// 9 | /// Helper method for the NativeSizeExtensions struct 10 | /// 11 | public static class NativeSizeExtensions 12 | { 13 | /// 14 | /// Create a new NativeSize, from the supplied one, using the specified width 15 | /// 16 | /// NativeSize 17 | /// int 18 | /// NativeSize 19 | [Pure] 20 | public static NativeSize ChangeWidth(this NativeSize size, int width) 21 | { 22 | return new NativeSize(width, size.Height); 23 | } 24 | 25 | /// 26 | /// Create a new NativeSize, from the supplied one, using the specified height 27 | /// 28 | /// NativeSize 29 | /// int 30 | /// NativeSize 31 | [Pure] 32 | public static NativeSize ChangeHeight(this NativeSize size, int height) 33 | { 34 | return new NativeSize(size.Width, height); 35 | } 36 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.DesktopWindowsManager/Dapplo.Windows.DesktopWindowsManager.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.DesktopWindowsManager helps to use the windows dwm api 4 | windows dwm 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | true 8 | True 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.DesktopWindowsManager/Enums/DwmBlurBehindFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.DesktopWindowsManager.Enums; 6 | 7 | /// 8 | /// Configuration flags for the DwmEnableBlurBehindWindow function 9 | /// 10 | [Flags] 11 | public enum DwmBlurBehindFlags 12 | { 13 | /// 14 | /// None 15 | /// 16 | None = 0, 17 | 18 | /// 19 | /// Transparency Enabled 20 | /// 21 | Enable = 1, 22 | 23 | /// 24 | /// Region enabled 25 | /// 26 | BlurRegion = 2, 27 | 28 | /// 29 | /// Transition on maximized enabled 30 | /// 31 | TransitionMaximized = 4 32 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.DesktopWindowsManager/Enums/DwmSetIconicLivePreviewFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.DesktopWindowsManager.Enums; 6 | 7 | /// 8 | /// Configuration flags for the DwmSetIconicLivePreviewBitmap function 9 | /// 10 | [Flags] 11 | public enum DwmSetIconicLivePreviewFlags 12 | { 13 | /// 14 | /// None 15 | /// 16 | None = 0, 17 | 18 | /// 19 | /// Displays a frame around the provided bitmap. 20 | /// 21 | DisplayFrame = 1 22 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.DesktopWindowsManager/Enums/DwmThumbnailPropertyFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.DesktopWindowsManager.Enums; 6 | 7 | /// 8 | /// A flag to indicate which properties are set by the DwmUpdateThumbnailProperties method 9 | /// 10 | [Flags] 11 | public enum DwmThumbnailPropertyFlags 12 | { 13 | /// 14 | /// A value for the rcDestination member has been specified. 15 | /// 16 | Destination = 0x00000001, 17 | 18 | /// 19 | /// A value for the rcSource member has been specified. 20 | /// 21 | Source = 0x00000002, 22 | 23 | /// 24 | /// A value for the opacity member has been specified. 25 | /// 26 | Opacity = 0x00000004, 27 | 28 | /// 29 | /// A value for the fVisible member has been specfied. 30 | /// 31 | Visible = 0x00000008, 32 | 33 | /// 34 | /// A value for the fSourceClientAreaOnly member has been specified. 35 | /// 36 | SourceClientAreaOnly = 0x00000010 37 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.DesktopWindowsManager/Enums/DwmWindowCornerPreference.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Dapplo.Windows.DesktopWindowsManager.Enums; 5 | 6 | /// 7 | /// Flags used by the DwmSetWindowAttribute function to specify the rounded corner preference for a window. 8 | /// 9 | public enum DwmWindowCornerPreference : uint 10 | { 11 | /// 12 | /// Let the system decide when to round window corners. 13 | /// 14 | Default = 0, 15 | /// 16 | /// Never round window corners. 17 | /// 18 | DoNotRound = 1, 19 | /// 20 | /// Round the corners, if appropriate. 21 | /// 22 | Round = 2, 23 | /// 24 | /// Round the corners if appropriate, with a small radius. 25 | /// 26 | RoundSmall = 3 27 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Devices/Dapplo.Windows.Devices.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Devices is a library which provides device information. 4 | windows devices 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | true 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Devices/DeviceInterfaceChangeInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Dapplo.Windows.Devices.Enums; 5 | using Dapplo.Windows.Devices.Structs; 6 | 7 | namespace Dapplo.Windows.Devices; 8 | 9 | /// 10 | /// Information on device changes 11 | /// 12 | public class DeviceInterfaceChangeInfo 13 | { 14 | /// 15 | /// Type of the event 16 | /// 17 | public DeviceChangeEvent EventType { get; internal set; } 18 | 19 | /// 20 | /// The already prepared DevBroadcastDeviceInterface 21 | /// 22 | public DevBroadcastDeviceInterface Device { get; internal set; } 23 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Devices/Enums/DeviceBroadcastDeviceType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Dapplo.Windows.Devices.Enums; 5 | 6 | /// 7 | /// See DEV_BROADCAST_HDR structure 8 | /// 9 | public enum DeviceBroadcastDeviceType : uint 10 | { 11 | /// 12 | /// DBT_DEVTYP_OEM: OEM- or IHV-defined device type. This structure is a DEV_BROADCAST_OEM structure. 13 | /// 14 | Oem = 0, 15 | /// 16 | /// DBT_DEVTYP_VOLUME: Logical volume. This structure is a DEV_BROADCAST_VOLUME structure. 17 | /// 18 | Volume = 2, 19 | /// 20 | /// DBT_DEVTYP_PORT: Port device (serial or parallel). This structure is a DEV_BROADCAST_PORT structure. 21 | /// 22 | Port = 3, 23 | /// 24 | /// DBT_DEVTYP_DEVICEINTERFACE: Class of devices. This structure is a DEV_BROADCAST_DEVICEINTERFACE structure. 25 | /// 26 | DeviceInterface = 5, 27 | /// 28 | /// DBT_DEVTYP_HANDLE: File system handle. This structure is a DEV_BROADCAST_HANDLE structure. 29 | /// 30 | Handle = 6 31 | 32 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Devices/Enums/DeviceNotifyFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Devices.Enums; 6 | 7 | /// 8 | /// See RegisterDeviceNotificationW function 9 | /// 10 | [Flags] 11 | public enum DeviceNotifyFlags : uint 12 | { 13 | /// 14 | /// The hRecipient parameter is a window handle. 15 | /// 16 | WindowHandle = 0x00000000, 17 | 18 | /// 19 | /// The hRecipient parameter is a service status handle. 20 | /// 21 | ServiceHandle = 0x00000001, 22 | 23 | /// 24 | /// Notifies the recipient of device interface events for all device interface classes. (The dbcc_classguid member is ignored.) 25 | /// This value can be used only if the dbch_devicetype member is DBT_DEVTYP_DEVICEINTERFACE. 26 | /// 27 | AllInterfaceClasses = 0x00000004, 28 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Devices/Structs/DevBroadcastHeader.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Runtime.InteropServices; 4 | using Dapplo.Windows.Devices.Enums; 5 | 6 | namespace Dapplo.Windows.Devices.Structs; 7 | 8 | /// 9 | /// Serves as a standard header for information related to a device event reported through the WM_DEVICECHANGE message. 10 | /// 11 | /// The members of the DEV_BROADCAST_HDR structure are contained in each device management structure. To determine which structure you have received through WM_DEVICECHANGE, treat the structure as a DEV_BROADCAST_HDR structure and check its dbch_devicetype member. 12 | /// See DEV_BROADCAST_HDR structure 13 | /// 14 | [StructLayout(LayoutKind.Sequential)] 15 | public struct DevBroadcastHeader 16 | { 17 | private readonly int _size; 18 | // The device type, which determines the event-specific information that follows the first three members. 19 | private readonly DeviceBroadcastDeviceType _deviceType; 20 | private readonly int _reserved; 21 | 22 | /// 23 | /// The device type, which determines the event-specific information that follows the first three members. 24 | /// 25 | public DeviceBroadcastDeviceType DeviceType => _deviceType; 26 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Devices/Structs/DevBroadcastPort.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Runtime.InteropServices; 4 | using Dapplo.Windows.Devices.Enums; 5 | 6 | namespace Dapplo.Windows.Devices.Structs; 7 | 8 | /// 9 | /// Contains information about a modem, serial, or parallel port. 10 | /// See DEV_BROADCAST_PORT_W structure 11 | /// 12 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 13 | public struct DevBroadcastPort 14 | { 15 | private int _size; 16 | // The device type, which determines the event-specific information that follows the first three members. 17 | private DeviceBroadcastDeviceType _deviceType; 18 | private readonly int _reserved; 19 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)] 20 | private readonly string _name; 21 | 22 | /// 23 | /// The name of the device. 24 | /// 25 | public string Name => _name; 26 | 27 | /// 28 | /// Factory for an empty DevBroadcastPort 29 | /// 30 | /// DevBroadcastPort 31 | public static DevBroadcastPort Create() 32 | { 33 | return new DevBroadcastPort 34 | { 35 | _deviceType = DeviceBroadcastDeviceType.Port, 36 | _size = Marshal.SizeOf(typeof(DevBroadcastPort)) 37 | }; 38 | } 39 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Devices/VolumeInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using Dapplo.Windows.Devices.Enums; 4 | using Dapplo.Windows.Devices.Structs; 5 | 6 | namespace Dapplo.Windows.Devices; 7 | 8 | /// 9 | /// Information on a volume change 10 | /// 11 | public class VolumeInfo 12 | { 13 | /// 14 | /// Type of the event 15 | /// 16 | public DeviceChangeEvent EventType { get; internal set; } 17 | 18 | /// 19 | /// The volume that was added / removed 20 | /// 21 | public DevBroadcastVolume Volume { get; internal set; } 22 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Devices/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Dpi/Dapplo.Windows.Dpi.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Dpi assists to make an application Dpi-Aware. 4 | windows native dpi 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | true 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Dpi/DpiChangeInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Dapplo.Windows.Dpi; 5 | 6 | /// 7 | /// Stores information about a DPI change 8 | /// 9 | public class DpiChangeInfo 10 | { 11 | /// 12 | /// The DPI from before the change 13 | /// 14 | public int PreviousDpi { get; } 15 | 16 | /// 17 | /// The new DPI 18 | /// 19 | public int NewDpi { get; } 20 | 21 | /// 22 | /// Creates a DpiChangeInfo 23 | /// 24 | /// uint 25 | /// uint 26 | public DpiChangeInfo(int previousDpi, int newDpi) 27 | { 28 | PreviousDpi = previousDpi; 29 | NewDpi = newDpi; 30 | } 31 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Dpi/Enums/DialogDpiChangeBehaviors.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Dpi.Enums; 6 | 7 | /// 8 | /// In Per Monitor v2 contexts, dialogs will automatically respond to DPI changes by resizing themselves and re-computing the positions of their child windows (here referred to as re-layouting). This enum works in conjunction with SetDialogDpiChangeBehavior in order to override the default DPI scaling behavior for dialogs. 9 | /// This does not affect DPI scaling behavior for the child windows of dialogs(beyond re-layouting), which is controlled by DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS. 10 | /// 11 | [Flags] 12 | public enum DialogDpiChangeBehaviors 13 | { 14 | /// 15 | /// The default behavior of the dialog manager. In response to a DPI change, the dialog manager will re-layout each control, update the font on each control, resize the dialog, and update the dialog's own font. 16 | /// 17 | Default = 0, 18 | 19 | /// 20 | /// Prevents the dialog manager from responding to WM_GETDPISCALEDSIZE and WM_DPICHANGED, disabling all default DPI scaling behavior. 21 | /// 22 | DisableAll = 1, 23 | 24 | /// 25 | /// Prevents the dialog manager from resizing the dialog in response to a DPI change. 26 | /// 27 | DisableResize = 2, 28 | 29 | /// 30 | /// Prevents the dialog manager from re-layouting all of the dialogue's immediate children HWNDs in response to a DPI change. 31 | /// 32 | DisableControlRelayout = 3 33 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Dpi/Enums/DialogScalingBehaviors.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Dpi.Enums; 6 | 7 | /// 8 | /// Describes per-monitor DPI scaling behavior overrides for child windows within dialogs. The values in this enumeration are bitfields and can be combined. 9 | /// 10 | /// This enum is used with SetDialogControlDpiChangeBehavior in order to override the default per-monitor DPI scaling behavior for a child window within a dialog. 11 | /// 12 | /// These settings only apply to individual controls within dialogs. The dialog-wide per-monitor DPI scaling behavior of a dialog is controlled by DIALOG_DPI_CHANGE_BEHAVIORS. 13 | /// 14 | [Flags] 15 | public enum DialogScalingBehaviors 16 | { 17 | /// 18 | /// The default behavior of the dialog manager. The dialog managed will update the font, size, and position of the child window on DPI changes. 19 | /// 20 | Default = 0, 21 | 22 | /// 23 | /// Prevents the dialog manager from sending an updated font to the child window via WM_SETFONT in response to a DPI change. 24 | /// 25 | DisableFontUpdate = 1, 26 | 27 | /// 28 | /// Prevents the dialog manager from resizing and repositioning the child window in response to a DPI change. 29 | /// 30 | DisableRelayout = 2 31 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Dpi/Enums/DpiAwareness.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Dpi.Enums; 4 | 5 | /// 6 | /// Identifies the dots per inch (dpi) setting for a thread, process, or window. 7 | /// Can be used everywhere ProcessDpiAwareness is passed. 8 | /// 9 | public enum DpiAwareness 10 | { 11 | /// 12 | /// Invalid DPI awareness. This is an invalid DPI awareness value. 13 | /// 14 | Invalid = -1, 15 | 16 | /// 17 | /// DPI unaware. 18 | /// This process does not scale for DPI changes and is always assumed to have a scale factor of 100% (96 DPI). 19 | /// It will be automatically scaled by the system on any other DPI setting. 20 | /// 21 | Unaware = 0, 22 | 23 | /// 24 | /// System DPI aware. 25 | /// This process does not scale for DPI changes. 26 | /// It will query for the DPI once and use that value for the lifetime of the process. 27 | /// If the DPI changes, the process will not adjust to the new DPI value. 28 | /// It will be automatically scaled up or down by the system when the DPI changes from the system value. 29 | /// 30 | SystemAware = 1, 31 | 32 | /// 33 | /// Per monitor DPI aware. 34 | /// This process checks for the DPI when it is created and adjusts the scale factor whenever the DPI changes. 35 | /// These processes are not automatically scaled by the system. 36 | /// 37 | PerMonitorAware = 2 38 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Dpi/Enums/DpiHostingBehavior.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Dpi.Enums; 4 | 5 | /// 6 | /// Identifies the DPI hosting behavior for a window. 7 | /// This behavior allows windows created in the thread to host child windows with a different DPI_AWARENESS_CONTEXT 8 | /// 9 | public enum DpiHostingBehavior 10 | { 11 | /// 12 | /// Invalid DPI hosting behavior. This usually occurs if the previous SetThreadDpiHostingBehavior call used an invalid parameter. 13 | /// 14 | Invalid = -1, 15 | 16 | /// 17 | /// Default DPI hosting behavior. The associated window behaves as normal, and cannot create or re-parent child windows with a different DPI_AWARENESS_CONTEXT. 18 | /// 19 | Default = 0, 20 | 21 | /// 22 | /// Mixed DPI hosting behavior. This enables the creation and re-parenting of child windows with different DPI_AWARENESS_CONTEXT. These child windows will be independently scaled by the OS. 23 | /// 24 | Mixed = 1 25 | 26 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Dpi/Enums/MonitorDpiType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Dpi.Enums; 6 | 7 | /// 8 | /// See 9 | /// 10 | /// MONITOR_DPI_TYPE 11 | /// enumeration 12 | /// 13 | /// 14 | [Flags] 15 | public enum MonitorDpiType 16 | { 17 | /// 18 | /// The effective DPI. 19 | /// This value should be used when determining the correct scale factor for scaling UI elements. 20 | /// This incorporates the scale factor set by the user for this specific display. 21 | /// 22 | EffectiveDpi = 0, 23 | 24 | /// 25 | /// The angular DPI. 26 | /// This DPI ensures rendering at a compliant angular resolution on the screen. 27 | /// This does not include the scale factor set by the user for this specific display 28 | /// 29 | AngularDpi = 1, 30 | 31 | /// 32 | /// The raw DPI. 33 | /// This value is the linear DPI of the screen as measured on the screen itself. 34 | /// Use this value when you want to read the pixel density and not the recommended scaling setting. 35 | /// This does not include the scale factor set by the user for this specific display and is not guaranteed to be a 36 | /// supported DPI value. 37 | /// 38 | RawDpi = 2 39 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Dpi/Forms/DpiUnawareForm.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | #if !NETSTANDARD2_0 4 | using System; 5 | using System.Diagnostics.CodeAnalysis; 6 | using System.Windows.Forms; 7 | using Dapplo.Windows.Dpi.Enums; 8 | 9 | namespace Dapplo.Windows.Dpi.Forms 10 | { 11 | /// 12 | /// This is a DPI-Unaware Form, making the form use the Windows build-in scaling, even if the application is DPI Aware. 13 | /// 14 | [SuppressMessage("Sonar Code Smell", "S110:Inheritance tree of classes should not be too deep", Justification = "This is what extending Form does...")] 15 | public class DpiUnawareForm : Form 16 | { 17 | private IDisposable _dpiAwarenessContextScope; 18 | 19 | /// 20 | protected override void CreateHandle() 21 | { 22 | _dpiAwarenessContextScope = NativeDpiMethods.ScopedThreadDpiAwarenessContext(DpiAwarenessContext.Unaware); 23 | base.CreateHandle(); 24 | } 25 | 26 | /// 27 | protected override void OnHandleCreated(EventArgs e) 28 | { 29 | _dpiAwarenessContextScope.Dispose(); 30 | base.OnHandleCreated(e); 31 | } 32 | } 33 | } 34 | #endif -------------------------------------------------------------------------------- /src/Dapplo.Windows.Dpi/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.EmbeddedBrowser/Dapplo.Windows.EmbeddedBrowser.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.EmbeddedBrowser is a small library which helps to embed the Internet Explorer in the most recent version. 4 | windows native browser embedded ie 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.ConsoleDemo/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.ConsoleDemo/Dapplo.Windows.Example.ConsoleDemo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net472;netcoreapp3.1;net6.0-windows 4 | Exe 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.ConsoleDemo/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using Dapplo.Windows.Input.Enums; 5 | using Dapplo.Windows.Input.Keyboard; 6 | using Dapplo.Windows.Messages; 7 | 8 | namespace Dapplo.Windows.Example.ConsoleDemo; 9 | 10 | internal static class Program 11 | { 12 | [STAThread] 13 | private static void Main(string[] args) 14 | { 15 | var key = new KeyCombinationHandler(VirtualKeyCode.KeyA); 16 | using (KeyboardHook.KeyboardEvents.Where(key).Subscribe(e => Hit())) 17 | { 18 | MessageLoop.ProcessMessages(); 19 | } 20 | } 21 | 22 | private static void Hit() 23 | { 24 | Console.WriteLine("Hit"); 25 | } 26 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.FormsExample/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.FormsExample/Dapplo.Windows.Example.FormsExample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net472;netcoreapp3.1;net6.0-windows 4 | WinExe 5 | true 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.FormsExample/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.FormsExample/FormDpiUnaware.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using Dapplo.Windows.Dpi.Forms; 4 | 5 | namespace Dapplo.Windows.Example.FormsExample; 6 | 7 | /// 8 | /// This extends the DpiUnawareForm to disable DPI awareness 9 | /// 10 | public partial class FormDpiUnaware : DpiUnawareForm 11 | { 12 | public FormDpiUnaware() 13 | { 14 | InitializeComponent(); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.FormsExample/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Windows.Forms; 5 | using Dapplo.Log; 6 | using Dapplo.Log.Loggers; 7 | 8 | namespace Dapplo.Windows.Example.FormsExample; 9 | 10 | internal static class Program 11 | { 12 | /// 13 | /// The main entry point for the application. 14 | /// 15 | [STAThread] 16 | private static void Main() 17 | { 18 | LogSettings.RegisterDefaultLogger(LogLevels.Verbose); 19 | Application.EnableVisualStyles(); 20 | Application.SetCompatibleTextRenderingDefault(false); 21 | var formDpiUnaware = new FormDpiUnaware(); 22 | formDpiUnaware.Show(); 23 | var formWithAttachedDpiHandler = new FormWithAttachedDpiHandler(); 24 | formWithAttachedDpiHandler.Show(); 25 | var formExtendsDpiAwareForm = new FormExtendsDpiAwareForm(); 26 | formExtendsDpiAwareForm.Show(); 27 | var webBrowserForm = new WebBrowserForm(); 28 | webBrowserForm.Show(); 29 | Application.Run(); 30 | } 31 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.FormsExample/WebBrowserExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Reactive.Disposables; 6 | using System.Reactive.Linq; 7 | using System.Windows.Forms; 8 | 9 | namespace Dapplo.Windows.Example.FormsExample; 10 | 11 | public static class WebBrowserExtensions 12 | { 13 | /// 14 | /// Create an observable for the navigating events 15 | /// 16 | /// WebBrowser 17 | /// IObservable which publishes WebBrowserNavigatingEventArgs 18 | public static IObservable OnNavigating(this WebBrowser webBrowser) 19 | { 20 | return Observable.Create(observer => 21 | { 22 | void Handler(object sender, WebBrowserNavigatingEventArgs args) 23 | { 24 | observer.OnNext(args); 25 | } 26 | 27 | webBrowser.Navigating += Handler; 28 | return Disposable.Create(() => 29 | { 30 | // Remove the event handlers 31 | webBrowser.Navigating -= Handler; 32 | }); 33 | }); 34 | } 35 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.FormsExample/WebBrowserForm.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using Dapplo.Log; 6 | using Dapplo.Windows.Dpi.Forms; 7 | using Dapplo.Windows.EmbeddedBrowser; 8 | 9 | namespace Dapplo.Windows.Example.FormsExample; 10 | 11 | public partial class WebBrowserForm : DpiAwareForm 12 | { 13 | private static readonly LogSource Log = new LogSource(); 14 | public WebBrowserForm() 15 | { 16 | InternetExplorerVersion.ChangeEmbeddedVersion(); 17 | 18 | InitializeComponent(); 19 | extendedWebBrowser1.OnNavigating().Subscribe(args => 20 | { 21 | Log.Info().WriteLine(args.Url.AbsoluteUri); 22 | }); 23 | } 24 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.FormsExample/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dapplo/Dapplo.Windows/55d2ca3705b75403fbf6d00cf9dd2b8b7a8a3d12/src/Dapplo.Windows.Example.FormsExample/help.png -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.FormsExample/layer-rotate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dapplo/Dapplo.Windows/55d2ca3705b75403fbf6d00cf9dd2b8b7a8a3d12/src/Dapplo.Windows.Example.FormsExample/layer-rotate.png -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.WpfExample/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.WpfExample/App.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.WpfExample/App.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Windows; 4 | using Dapplo.Log; 5 | using Dapplo.Log.Loggers; 6 | using Dapplo.Windows.Dpi; 7 | 8 | namespace Dapplo.Windows.Example.WpfExample; 9 | 10 | /// 11 | /// Interaction logic for App.xaml 12 | /// 13 | public partial class App 14 | { 15 | protected override void OnStartup(StartupEventArgs e) 16 | { 17 | LogSettings.RegisterDefaultLogger(LogLevels.Verbose); 18 | NativeDpiMethods.EnableDpiAware(); 19 | base.OnStartup(e); 20 | } 21 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.WpfExample/Icons/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dapplo/Dapplo.Windows/55d2ca3705b75403fbf6d00cf9dd2b8b7a8a3d12/src/Dapplo.Windows.Example.WpfExample/Icons/delete.png -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.WpfExample/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.WpfExample/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Diagnostics; 5 | using System.Reactive.Linq; 6 | using System.Windows; 7 | using Dapplo.Windows.Devices; 8 | using Dapplo.Windows.Dpi.Wpf; 9 | using Dapplo.Windows.Messages; 10 | using Dapplo.Windows.Messages.Enumerations; 11 | using Dapplo.Windows.User32; 12 | 13 | namespace Dapplo.Windows.Example.WpfExample; 14 | 15 | /// 16 | /// Interaction logic for MainWindow.xaml 17 | /// 18 | public partial class MainWindow 19 | { 20 | public MainWindow() 21 | { 22 | InitializeComponent(); 23 | this.AttachDpiHandler(); 24 | 25 | this.WinProcMessages() 26 | .Where(m => m.Message == WindowsMessages.WM_DESTROY) 27 | .Subscribe(m => { MessageBox.Show($"{m.Message}"); }); 28 | 29 | DeviceNotification.OnVolumeAdded().Subscribe(volumeInfo => Debug.WriteLine($"Drives {volumeInfo.Volume.Drives} were added")); 30 | DeviceNotification.OnVolumeRemoved().Subscribe(volumeInfo => Debug.WriteLine($"Drives {volumeInfo.Volume.Drives} were removed")); 31 | 32 | DeviceNotification 33 | .OnDeviceArrival() 34 | .Subscribe(deviceInterfaceChangeInfo => Debug.WriteLine("Device added: {0}, for more information goto {1}", deviceInterfaceChangeInfo.Device.FriendlyDeviceName, deviceInterfaceChangeInfo.Device.UsbDeviceInfoUri)); 35 | 36 | // A small example to lock the PC when a YubiKey is removed 37 | DeviceNotification.OnDeviceRemoved() 38 | .Where(deviceInterfaceChangeInfo => deviceInterfaceChangeInfo.Device.Name.Contains("Yubi")) 39 | .Subscribe(deviceInterfaceChangeInfo => User32Api.LockWorkStation()); 40 | } 41 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Example.WpfExample/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dapplo/Dapplo.Windows/55d2ca3705b75403fbf6d00cf9dd2b8b7a8a3d12/src/Dapplo.Windows.Example.WpfExample/icon.png -------------------------------------------------------------------------------- /src/Dapplo.Windows.Gdi32/Dapplo.Windows.Gdi32.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Gdi32 bringt Gdi32 and GdiPlus functionality. 4 | windows native gdi 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Gdi32/Enums/BitmapCompressionMethods.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Diagnostics.CodeAnalysis; 4 | 5 | namespace Dapplo.Windows.Gdi32.Enums; 6 | 7 | /// 8 | /// Type of compression used for the bitmap in the BitmapInfoHeader 9 | /// 10 | [SuppressMessage("ReSharper", "InconsistentNaming")] 11 | public enum BitmapCompressionMethods : uint 12 | { 13 | /// 14 | /// No compression 15 | /// 16 | BI_RGB = 0, 17 | 18 | /// 19 | /// RLE 8BPP 20 | /// 21 | BI_RLE8 = 1, 22 | 23 | /// 24 | /// RLE 4BPP 25 | /// 26 | BI_RLE4 = 2, 27 | 28 | /// 29 | /// Specifies that the bitmap is not compressed and that the color table consists of three DWORD color masks that 30 | /// specify the 31 | /// red, green, and blue components, respectively, of each pixel. This is valid when used with 16- and 32-bpp bitmaps. 32 | /// 33 | BI_BITFIELDS = 3, 34 | 35 | /// 36 | /// Indicates that the image is a JPEG image. 37 | /// 38 | BI_JPEG = 4, 39 | 40 | /// 41 | /// Indicates that the image is a PNG image. 42 | /// 43 | BI_PNG = 5 44 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Gdi32/Enums/DibColors.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Gdi32.Enums; 4 | 5 | /// 6 | /// The DIBColors enumeration defines how to interpret the values in the color table of a DIB. 7 | /// 8 | public enum DibColors : uint 9 | { 10 | /// 11 | /// The color table contains literal RGB values. 12 | /// 13 | RgbColors = 0x00, 14 | /// 15 | /// The color table consists of an array of 16-bit indexes into the LogPalette object (section 2.2.17) that is currently defined in the playback device context. 16 | /// 17 | PalColors = 0x01, 18 | /// 19 | /// No color table exists. The pixels in the DIB are indices into the current logical palette in the playback device context. 20 | /// 21 | PalIndices = 0x02 22 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Gdi32/Enums/GdiPlusStatus.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Diagnostics.CodeAnalysis; 4 | 5 | namespace Dapplo.Windows.Gdi32.Enums; 6 | 7 | /// 8 | /// Status result for GDI+ calls 9 | /// 10 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 11 | public enum GdiPlusStatus 12 | { 13 | #pragma warning disable 1591 14 | Ok = 0, 15 | GenericError = 1, 16 | InvalidParameter = 2, 17 | OutOfMemory = 3, 18 | ObjectBusy = 4, 19 | InsufficientBuffer = 5, 20 | NotImplemented = 6, 21 | Win32Error = 7, 22 | WrongState = 8, 23 | Aborted = 9, 24 | FileNotFound = 10, 25 | ValueOverflow = 11, 26 | AccessDenied = 12, 27 | UnknownImageFormat = 13, 28 | FontFamilyNotFound = 14, 29 | FontStyleNotFound = 15, 30 | NotTrueTypeFont = 16, 31 | UnsupportedGdiplusVersion = 17, 32 | GdiplusNotInitialized = 18, 33 | PropertyNotFound = 19, 34 | PropertyNotSupported = 20, 35 | ProfileNotFound = 21 36 | #pragma warning restore 1591 37 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Gdi32/Enums/GpUnit.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Gdi32.Enums; 4 | 5 | /// 6 | /// GDI Plus unit description. 7 | /// 8 | public enum GpUnit 9 | { 10 | /// 11 | /// World coordinate (non-physical unit). 12 | /// 13 | UnitWorld, 14 | 15 | /// 16 | /// Variable - for PageTransform only. 17 | /// 18 | UnitDisplay, 19 | 20 | /// 21 | /// Each unit is one device pixel. 22 | /// 23 | UnitPixel, 24 | 25 | /// 26 | /// Each unit is a printer's point, or 1/72 inch. 27 | /// 28 | UnitPoint, 29 | 30 | /// 31 | /// Each unit is 1 inch. 32 | /// 33 | UnitInch, 34 | 35 | /// 36 | /// Each unit is 1/300 inch. 37 | /// 38 | UnitDocument, 39 | 40 | /// 41 | /// Each unit is 1 millimeter. 42 | /// 43 | UnitMillimeter 44 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Gdi32/SafeHandles/SafeDcHandle.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using Microsoft.Win32.SafeHandles; 4 | 5 | namespace Dapplo.Windows.Gdi32.SafeHandles; 6 | 7 | /// 8 | /// Base class for all Safe "DC" Handles 9 | /// 10 | public abstract class SafeDcHandle : SafeHandleZeroOrMinusOneIsInvalid 11 | { 12 | /// 13 | /// Constructor which passes the SafeHandleZeroOrMinusOneIsInvalid to the base 14 | /// 15 | /// 16 | /// true to reliably release the handle during the finalization phase; false to prevent reliable 17 | /// release (not recommended). 18 | /// 19 | protected SafeDcHandle(bool ownsHandle) : base(ownsHandle) 20 | { 21 | } 22 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Gdi32/SafeHandles/SafeDibSectionHandle.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Security; 6 | 7 | namespace Dapplo.Windows.Gdi32.SafeHandles; 8 | 9 | /// 10 | /// A DIB Section SafeHandle implementation 11 | /// 12 | public class SafeDibSectionHandle : SafeObjectHandle 13 | { 14 | /// 15 | /// Default constructor is needed to support marshalling!! 16 | /// 17 | [SecurityCritical] 18 | public SafeDibSectionHandle() : base(true) 19 | { 20 | } 21 | 22 | /// 23 | /// Create a SafeDibSectionHandle for an existing DIB Section 24 | /// 25 | /// 26 | [SecurityCritical] 27 | public SafeDibSectionHandle(IntPtr preexistingHandle) : base(true) 28 | { 29 | SetHandle(preexistingHandle); 30 | } 31 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Gdi32/SafeHandles/SafeHBitmapHandle.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Drawing; 6 | using System.Security; 7 | 8 | namespace Dapplo.Windows.Gdi32.SafeHandles; 9 | 10 | /// 11 | /// A hbitmap SafeHandle implementation, use this for disposable usage of HBitmap 12 | /// 13 | public class SafeHBitmapHandle : SafeObjectHandle 14 | { 15 | /// 16 | /// Default constructor is needed to support marshalling!! 17 | /// 18 | [SecurityCritical] 19 | public SafeHBitmapHandle() : base(true) 20 | { 21 | } 22 | 23 | /// 24 | /// Create a SafeHBitmapHandle from an existing handle 25 | /// 26 | /// IntPtr to HBitmap 27 | [SecurityCritical] 28 | public SafeHBitmapHandle(IntPtr preexistingHandle) : base(true) 29 | { 30 | SetHandle(preexistingHandle); 31 | } 32 | 33 | /// 34 | /// Create a SafeHBitmapHandle from a Bitmap 35 | /// 36 | /// Bitmap to call GetHbitmap on 37 | [SecurityCritical] 38 | public SafeHBitmapHandle(Bitmap bitmap) : base(true) 39 | { 40 | SetHandle(bitmap.GetHbitmap()); 41 | } 42 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Gdi32/SafeHandles/SafeObjectHandle.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using Microsoft.Win32.SafeHandles; 6 | 7 | namespace Dapplo.Windows.Gdi32.SafeHandles; 8 | 9 | /// 10 | /// Abstract class SafeObjectHandle which contains all handles that are cleaned with DeleteObject 11 | /// 12 | public abstract class SafeObjectHandle : SafeHandleZeroOrMinusOneIsInvalid 13 | { 14 | /// 15 | /// Create SafeObjectHandle 16 | /// 17 | /// True if the class owns the handle 18 | protected SafeObjectHandle(bool ownsHandle) : base(ownsHandle) 19 | { 20 | } 21 | 22 | /// 23 | /// Call DeleteObject 24 | /// 25 | /// true if this worked 26 | protected override bool ReleaseHandle() 27 | { 28 | if (handle != IntPtr.Zero) 29 | { 30 | return Gdi32Api.DeleteObject(handle); 31 | } 32 | 33 | return false; 34 | } 35 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Gdi32/SafeHandles/SafeRegionHandle.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Security; 5 | 6 | namespace Dapplo.Windows.Gdi32.SafeHandles; 7 | 8 | /// 9 | /// A hRegion SafeHandle implementation 10 | /// 11 | public class SafeRegionHandle : SafeObjectHandle 12 | { 13 | /// 14 | /// Default constructor is needed to support marshalling!! 15 | /// 16 | [SecurityCritical] 17 | public SafeRegionHandle() : base(true) 18 | { 19 | } 20 | 21 | /// 22 | /// Create a SafeRegionHandle from an existing handle 23 | /// 24 | /// IntPtr to region 25 | [SecurityCritical] 26 | public SafeRegionHandle(IntPtr preexistingHandle) : base(true) 27 | { 28 | SetHandle(preexistingHandle); 29 | } 30 | 31 | /// 32 | /// Directly call Gdi32.CreateRectRgn 33 | /// 34 | /// 35 | /// 36 | /// 37 | /// 38 | /// SafeRegionHandle 39 | public static SafeRegionHandle CreateRectRgn(int left, int top, int right, int bottom) 40 | { 41 | return Gdi32Api.CreateRectRgn(left, top, right, bottom); 42 | } 43 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Gdi32/Structs/RgbQuad.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Dapplo.Windows.Gdi32.Structs; 7 | 8 | /// 9 | /// The RGBQUAD structure describes a color consisting of relative intensities of red, green, and blue. 10 | /// 11 | [StructLayout(LayoutKind.Sequential)] 12 | public struct RgbQuad 13 | { 14 | private byte rgbBlue; 15 | private byte rgbGreen; 16 | private byte rgbRed; 17 | private byte rgbReserved; 18 | 19 | /// 20 | /// The intensity of blue in the color. 21 | /// 22 | public byte Blue 23 | { 24 | get => rgbBlue; 25 | set => rgbBlue = value; 26 | } 27 | 28 | /// 29 | /// The intensity of green in the color. 30 | /// 31 | public byte Green 32 | { 33 | get => rgbGreen; 34 | set => rgbGreen = value; 35 | } 36 | 37 | /// 38 | /// The intensity of red in the color. 39 | /// 40 | public byte Red 41 | { 42 | get => rgbRed; 43 | set => rgbRed = value; 44 | } 45 | 46 | /// 47 | /// The reserved value 48 | /// 49 | public byte Reserved 50 | { 51 | get => rgbReserved; 52 | set => rgbReserved = value; 53 | } 54 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Gdi32/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Icons/Dapplo.Windows.Icons.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Icons has supporting code for icons. 4 | windows native icons 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | true 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Icons/Enums/FolderIconType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Dapplo.Windows.Icons.Enums; 5 | 6 | /// 7 | /// Options to specify whether folders should be in the open or closed state. 8 | /// 9 | public enum FolderIconType 10 | { 11 | /// 12 | /// Specify open folder. 13 | /// 14 | Open = 0, 15 | 16 | /// 17 | /// Specify closed folder. 18 | /// 19 | Closed = 1 20 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Icons/Enums/IconSize.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Dapplo.Windows.Icons.Enums; 5 | 6 | /// 7 | /// Options to specify the size of icons to return. 8 | /// 9 | public enum IconSize 10 | { 11 | /// 12 | /// Specify large icon - 32 pixels by 32 pixels. 13 | /// 14 | Large = 0, 15 | 16 | /// 17 | /// Specify small icon - 16 pixels by 16 pixels. 18 | /// 19 | Small = 1 20 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Icons/NativeCursorMethods.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Runtime.InteropServices; 5 | using Dapplo.Windows.User32; 6 | using Dapplo.Windows.User32.Structs; 7 | 8 | namespace Dapplo.Windows.Icons; 9 | 10 | /// 11 | /// Win32 native methods for Icon 12 | /// 13 | public static class NativeCursorMethods 14 | { 15 | /// 16 | /// See 17 | /// GetCursorInfo function 18 | /// Retrieves information about the global cursor. 19 | /// 20 | /// CursorInfo structure to fill 21 | /// bool 22 | [DllImport(User32Api.User32, SetLastError = true)] 23 | [return: MarshalAs(UnmanagedType.Bool)] 24 | public static extern bool GetCursorInfo(ref CursorInfo cursorInfo); 25 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Icons/SafeHandles/SafeIconHandle.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Drawing; 6 | using System.Security; 7 | using System.Security.Permissions; 8 | using Microsoft.Win32.SafeHandles; 9 | 10 | namespace Dapplo.Windows.Icons.SafeHandles; 11 | 12 | /// 13 | /// A SafeHandle class implementation for the hIcon 14 | /// 15 | public class SafeIconHandle : SafeHandleZeroOrMinusOneIsInvalid 16 | { 17 | /// 18 | /// Default constructor is needed to support marshalling!! 19 | /// 20 | [SecurityCritical] 21 | public SafeIconHandle() : base(true) 22 | { 23 | } 24 | 25 | /// 26 | /// Create a SafeIconHandle from a bitmap by calling GetHicon 27 | /// 28 | /// Bitmap 29 | public SafeIconHandle(Bitmap bitmap) : base(true) 30 | { 31 | SetHandle(bitmap.GetHicon()); 32 | } 33 | 34 | /// 35 | /// Create a SafeIconHandle from a hIcon 36 | /// 37 | /// IntPtr to an icon 38 | public SafeIconHandle(IntPtr hIcon) : base(true) 39 | { 40 | SetHandle(hIcon); 41 | } 42 | 43 | /// 44 | /// Call destroy icon 45 | /// 46 | /// true if this worked 47 | #if !NET6_0 48 | [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] 49 | #endif 50 | protected override bool ReleaseHandle() 51 | { 52 | return NativeIconMethods.DestroyIcon(handle); 53 | } 54 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Icons/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Dapplo.Windows.Input.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Input provides code to generate and get input from keyboard and mouse 4 | windows native input 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | true 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Enums/ExtendedKeyFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Input.Enums; 6 | 7 | /// 8 | /// The extended-key flag, event-injected flags, context code, and transition-state flag. 9 | /// This member is specified as follows. 10 | /// An application can use the following values to test the keystroke flags. 11 | /// Testing LLKHF_INJECTED (bit 4) will tell you whether the event was injected. 12 | /// If it was, then testing LLKHF_LOWER_IL_INJECTED (bit 1) will tell you whether or not the event was injected from a 13 | /// process running at lower integrity level. 14 | /// 15 | [Flags] 16 | public enum ExtendedKeyFlags : uint 17 | { 18 | /// 19 | /// No flags 20 | /// 21 | None = 0, 22 | 23 | /// 24 | /// Test the extended-key flag. 25 | /// 26 | Extended = 0x01, 27 | 28 | /// 29 | /// Test the event-injected (from a process running at lower integrity level) flag. 30 | /// 31 | LowerIntegretyInjected = 0x02, 32 | 33 | /// 34 | /// Test the event-injected (from any process) flag. 35 | /// 36 | Injected = 0x10, 37 | 38 | /// 39 | /// Test the context code. 40 | /// 41 | AltDown = 0x20, 42 | 43 | /// 44 | /// Test the transition-state flag. 45 | /// 46 | Up = 0x80 47 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Enums/ExtendedMouseFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Input.Enums; 6 | 7 | /// 8 | /// The event-injected flags. An application can use the following values to test the flags. 9 | /// Testing LLMHF_INJECTED (bit 0) will tell you whether the event was injected. 10 | /// If it was, then testing LLMHF_LOWER_IL_INJECTED (bit 1) will tell you whether or not 11 | /// the event was injected from a process running at lower integrity level. 12 | /// 13 | [Flags] 14 | public enum ExtendedMouseFlags : uint 15 | { 16 | /// 17 | /// Test the event-injected (from any process) flag. 18 | /// 19 | Injected = 0x01, 20 | 21 | /// 22 | /// Test the event-injected (from a process running at lower integrity level) flag. 23 | /// 24 | LowerIntegretyInjected = 0x02 25 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Enums/HidUsagesConsumer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Input.Enums; 4 | 5 | /// 6 | /// The different consumer HID usages 7 | /// See here 8 | /// 9 | public enum HidUsagesConsumer : ushort 10 | { 11 | /// 12 | /// Unknow usage 13 | /// 14 | Undefined = 0x00, 15 | /// 16 | /// Consumer Control 17 | /// 18 | ConsumerControl = 0x01 19 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Enums/InputTypes.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Input.Enums; 4 | 5 | /// 6 | /// An enum specifying the type of input event used for the SendInput call. 7 | /// This specifies which structure type of the union supplied to SendInput is used. 8 | /// See INPUT structure 9 | /// 10 | public enum InputTypes : uint 11 | { 12 | /// 13 | /// The event is a mouse event. 14 | /// 15 | Mouse = 0, 16 | 17 | /// 18 | /// The event is a keyboard event. 19 | /// 20 | Keyboard = 1, 21 | 22 | /// 23 | /// The event is a hardware event. 24 | /// 25 | Hardware = 2 26 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Enums/KeyEventFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Input.Enums; 6 | 7 | /// 8 | /// This enum specifies various aspects of a keystroke. This member can be certain combinations of the following 9 | /// values. 10 | /// See 11 | /// KEYBDINPUT structure 12 | /// 13 | [Flags] 14 | public enum KeyEventFlags : uint 15 | { 16 | /// 17 | /// If specified, the scan code was preceded by a prefix byte that has the value 0xE0 (224). 18 | /// 19 | ExtendedKey = 0x0001, 20 | 21 | /// 22 | /// If specified, the key is being released. If not specified, the key is being pressed. 23 | /// 24 | KeyUp = 0x0002, 25 | 26 | /// 27 | /// If specified, the system synthesizes a VK_PACKET keystroke. The VirtualKeyCode parameter must be zero. 28 | /// This flag can only be combined with the KeyUp flag. For more information, see the Remarks section. 29 | /// 30 | Unicode = 0x0004, 31 | 32 | /// 33 | /// If specified, wScan identifies the key and VirtualKeyCode is ignored. 34 | /// 35 | Scancode = 0x0008 36 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Enums/MouseButtons.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Input.Enums; 6 | 7 | /// 8 | /// Defines which mouse buttons to use 9 | /// 10 | [Flags] 11 | public enum MouseButtons 12 | { 13 | /// 14 | /// No button 15 | /// 16 | None, 17 | /// 18 | /// Left mouse button 19 | /// 20 | Left = 0x100000, 21 | /// 22 | /// Right mouse button 23 | /// 24 | Right = 0x200000, 25 | /// 26 | /// Middle mouse button 27 | /// 28 | Middle = 0x400000, 29 | /// 30 | /// Extra button 1 31 | /// 32 | XButton1 = 0x800000, 33 | /// 34 | /// Extra button 2 35 | /// 36 | XButton2 = 0x1000000, 37 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Enums/MouseStates.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Input.Enums; 6 | 7 | /// 8 | /// The mouse state. This member can be any reasonable combination of the following. 9 | /// See RAWMOUSE structure 10 | /// 11 | [Flags] 12 | public enum MouseStates : ushort 13 | { 14 | /// 15 | /// Mouse movement data is relative to the last mouse position. 16 | /// 17 | MoveRelative = 0x0000, 18 | 19 | /// 20 | /// Mouse movement data is based on absolute position. 21 | /// 22 | MoveAbsolute = 0x0001, 23 | 24 | /// 25 | /// Mouse coordinates are mapped to the virtual desktop (for a multiple monitor system). 26 | /// 27 | VirtualDesktop = 0x0002, 28 | 29 | /// 30 | /// The left button was released. 31 | /// 32 | AttributesChanged = 0x0004 33 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Enums/RawInputDataCommands.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Input.Enums; 4 | 5 | /// 6 | /// The commands to get the RawInputData 7 | /// See RAWINPUTDEVICELIST structure 8 | /// 9 | public enum RawInputDataCommands : uint 10 | { 11 | /// 12 | /// RID_INPUT: Get the raw data from the RAWINPUT structure. 13 | /// 14 | Input = 0x10000003, 15 | /// 16 | /// RID_HEADER: Get the header information from the RAWINPUT structure. 17 | /// 18 | Header = 0x10000005 19 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Enums/RawInputDeviceInfoCommands.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Input.Enums; 4 | 5 | /// 6 | /// See GetRawInputDeviceInfo function 7 | /// 8 | public enum RawInputDeviceInfoCommands : uint 9 | { 10 | /// 11 | /// pData points to a string that contains the device name. 12 | /// For this uiCommand only, the value in pcbSize is the character count (not the byte count) 13 | /// 14 | DeviceName = 0x20000007, 15 | /// 16 | /// pData points to an RID_DEVICE_INFO structure. 17 | /// 18 | DeviceInfo = 0x2000000b, 19 | /// 20 | /// pData points to the previously parsed data. 21 | /// 22 | PreparsedData = 0x20000005 23 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Enums/RawInputDeviceTypes.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Input.Enums; 4 | 5 | /// 6 | /// The type of device, using in the RAWINPUTDEVICELIST 7 | /// See RAWINPUTDEVICELIST structure 8 | /// 9 | public enum RawInputDeviceTypes : uint 10 | { 11 | /// 12 | /// RIM_TYPEMOUSE: Specified device is a mouse 13 | /// 14 | Mouse = 0, 15 | /// 16 | /// RIM_TYPEKEYBOARD: Specified device is a keyboard 17 | /// 18 | Keyboard = 1, 19 | /// 20 | /// RIM_TYPEHID: Specified device is not a mouse or a keyboard 21 | /// 22 | // ReSharper disable once InconsistentNaming 23 | HID = 2 24 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Enums/RawKeyboardFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Input.Enums; 6 | 7 | /// 8 | /// Enumeration containing flags for raw keyboard input. 9 | /// 10 | [Flags] 11 | public enum RawKeyboardFlags : ushort 12 | { 13 | /// 14 | /// The key is down. 15 | /// 16 | Make = 0, 17 | /// 18 | /// The key is up. 19 | /// 20 | Break = 1, 21 | /// 22 | /// The scan code has the E0 prefix. 23 | /// 24 | E0 = 2, 25 | /// 26 | /// The scan code has the E1 prefix. 27 | /// 28 | E1 = 4, 29 | /// 30 | /// No clue 31 | /// 32 | // ReSharper disable once InconsistentNaming 33 | TerminalServerSetLED = 8, 34 | /// 35 | /// No clue 36 | /// 37 | TerminalServerShadow = 0x10, 38 | /// 39 | /// No clue 40 | /// 41 | TerminalServerVkPacket = 0x20 42 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Keyboard/IKeyboardHookEventHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Input.Keyboard; 4 | 5 | /// 6 | /// This can handle KeyboardHookEventArgs, the handle method returns true if the key was handled. 7 | /// 8 | public interface IKeyboardHookEventHandler 9 | { 10 | /// 11 | /// Handle a KeyboardHookEventArgs 12 | /// 13 | /// 14 | /// bool true if handled 15 | bool Handle(KeyboardHookEventArgs keyboardHookEventArgs); 16 | 17 | /// 18 | /// Test if this event handler currently has keys pressed 19 | /// 20 | bool HasKeysPressed { get; } 21 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Keyboard/KeyboardHookExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Reactive.Linq; 5 | 6 | namespace Dapplo.Windows.Input.Keyboard; 7 | 8 | /// 9 | /// Extensions to assist with the Keyboard Hooks 10 | /// 11 | public static class KeyboardHookExtensions 12 | { 13 | /// 14 | /// Filter the KeyboardHookEventArgs with a IKeyboardHookEventHandler 15 | /// 16 | /// IObservable of KeyboardHookEventArgs, e.g. coming from KeyboardHook.KeyboardEvents 17 | /// IKeyboardHookEventHandler 18 | /// IObservable with the KeyboardHookEventArgs which was handled 19 | public static IObservable Where(this IObservable keyboardObservable, IKeyboardHookEventHandler keyboardHookEventHandler) 20 | { 21 | return keyboardObservable.Where(keyboardHookEventHandler.Handle); 22 | } 23 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Keyboard/VirtualKeyCodeExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using Dapplo.Windows.Input.Enums; 4 | 5 | namespace Dapplo.Windows.Input.Keyboard; 6 | 7 | /// 8 | /// Extensions for VirtualKeyCode 9 | /// 10 | public static class VirtualKeyCodeExtensions 11 | { 12 | /// 13 | /// Test if the VirtualKeyCode is a modifier key 14 | /// 15 | /// VirtualKeyCode 16 | /// bool 17 | public static bool IsModifier(this VirtualKeyCode virtualKeyCode) 18 | { 19 | bool isModifier = false; 20 | switch (virtualKeyCode) 21 | { 22 | case VirtualKeyCode.Capital: 23 | case VirtualKeyCode.NumLock: 24 | case VirtualKeyCode.Scroll: 25 | case VirtualKeyCode.LeftShift: 26 | case VirtualKeyCode.Shift: 27 | case VirtualKeyCode.RightShift: 28 | case VirtualKeyCode.Control: 29 | case VirtualKeyCode.LeftControl: 30 | case VirtualKeyCode.RightControl: 31 | case VirtualKeyCode.Menu: 32 | case VirtualKeyCode.LeftMenu: 33 | case VirtualKeyCode.RightMenu: 34 | case VirtualKeyCode.LeftWin: 35 | case VirtualKeyCode.RightWin: 36 | isModifier = true; 37 | break; 38 | } 39 | 40 | return isModifier; 41 | } 42 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Mouse/MouseHookEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using Dapplo.Windows.Common.Structs; 5 | using Dapplo.Windows.Messages; 6 | using Dapplo.Windows.Messages.Enumerations; 7 | 8 | namespace Dapplo.Windows.Input.Mouse; 9 | 10 | /// 11 | /// Information on mouse changes 12 | /// TODO: Make the information a lot clearer, than processing WindowsMessages 13 | /// 14 | public class MouseHookEventArgs : EventArgs 15 | { 16 | /// 17 | /// Set this to true if the event is handled, other event-handlers in the chain will not be called 18 | /// 19 | public bool Handled { get; set; } 20 | 21 | /// 22 | /// The x- and y-coordinates of the cursor, in per-monitor-aware screen coordinates. 23 | /// 24 | public NativePoint Point { get; set; } 25 | 26 | /// 27 | /// The mouse message 28 | /// 29 | public WindowsMessages WindowsMessage { get; set; } 30 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/RawInputDeviceChangeEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Input; 6 | 7 | /// 8 | /// Information on RawInput device changes 9 | /// 10 | public class RawInputDeviceChangeEventArgs : EventArgs 11 | { 12 | /// 13 | /// If true it was added, if false it was removed 14 | /// 15 | public bool Added { get; set; } 16 | 17 | /// 18 | /// The device which was added or removed 19 | /// 20 | public RawInputDeviceInformation DeviceInformation { get; set; } 21 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/RawInputDeviceInformation.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using Dapplo.Windows.Input.Structs; 5 | 6 | namespace Dapplo.Windows.Input; 7 | 8 | /// 9 | /// Describes a RawInput device 10 | /// 11 | public class RawInputDeviceInformation 12 | { 13 | /// 14 | /// The handle to the raw input device 15 | /// 16 | public IntPtr Handle { get; internal set; } 17 | 18 | /// 19 | /// The cryptic device name 20 | /// 21 | public string DeviceName { get; internal set; } 22 | 23 | /// 24 | /// A name which can be used to display to a user 25 | /// 26 | public string DisplayName { get; internal set; } 27 | 28 | /// 29 | /// The actual device information 30 | /// 31 | public RawInputDeviceInfo DeviceInfo { get; internal set; } 32 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/RawInputEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using Dapplo.Windows.Input.Structs; 5 | 6 | namespace Dapplo.Windows.Input; 7 | 8 | /// 9 | /// Raw Input information 10 | /// 11 | public class RawInputEventArgs : EventArgs 12 | { 13 | /// 14 | /// If true the application was in the foreground 15 | /// 16 | public bool IsForeground { get; set; } 17 | 18 | /// 19 | /// The actual raw input 20 | /// 21 | public RawInput RawInput { get; set; } 22 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Structs/HardwareInput.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Dapplo.Windows.Input.Structs; 7 | 8 | /// 9 | /// Contains information about a simulated message generated by an input device other than a keyboard or mouse. 10 | /// See HARDWAREINPUT structure 11 | /// 12 | [StructLayout(LayoutKind.Sequential)] 13 | [SuppressMessage("ReSharper", "ConvertToAutoProperty")] 14 | [SuppressMessage("ReSharper", "ArrangeAccessorOwnerBody")] 15 | public struct HardwareInput 16 | { 17 | private int _uMsg; 18 | private short _wParamL; 19 | private short _wParamH; 20 | 21 | /// 22 | /// The message generated by the input hardware. 23 | /// 24 | public int uMsg 25 | { 26 | get { return _uMsg; } 27 | set { _uMsg = value; } 28 | } 29 | 30 | /// 31 | /// The low-order word of the lParam parameter for uMsg. 32 | /// 33 | public short ParamL 34 | { 35 | get { return _wParamL; } 36 | set { _wParamL = value; } 37 | } 38 | 39 | /// 40 | /// The high-order word of the lParam parameter for uMsg. 41 | /// 42 | public short wParamH 43 | { 44 | get { return _wParamH; } 45 | set { _wParamH = value; } 46 | } 47 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Structs/InputUnion.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Runtime.InteropServices; 4 | 5 | namespace Dapplo.Windows.Input.Structs; 6 | 7 | /// 8 | /// A "union" containing a specific input struct 9 | /// 10 | [StructLayout(LayoutKind.Explicit)] 11 | public struct InputUnion 12 | { 13 | /// 14 | /// Assign this if the input is MouseInput 15 | /// 16 | [FieldOffset(0)] public MouseInput MouseInput; 17 | 18 | /// 19 | /// Assign this if the input is MouseInputKeyboardInput 20 | /// 21 | [FieldOffset(0)] public KeyboardInput KeyboardInput; 22 | 23 | /// 24 | /// Assign this if the input is HardwareInput 25 | /// 26 | [FieldOffset(0)] public HardwareInput HardwareInput; 27 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Structs/LastInputInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Dapplo.Windows.Input.Structs; 7 | 8 | /// 9 | /// A struct used by SendInput to store information for synthesizing input events such as keystrokes, mouse movement, 10 | /// and mouse clicks. 11 | /// See LASTINPUTINFO structure 12 | /// 13 | [StructLayout(LayoutKind.Sequential)] 14 | public struct LastInputInfo 15 | { 16 | private uint _cbSize; 17 | private readonly uint _dwTime; 18 | 19 | /// 20 | /// The tick count for the last registered input 21 | /// 22 | public uint TickCountLastInput => _dwTime; 23 | 24 | /// 25 | /// The timespan for how long ago the last input was 26 | /// 27 | public TimeSpan LastInputTimeSpan => TimeSpan.FromMilliseconds(Environment.TickCount - _dwTime); 28 | 29 | /// 30 | /// Returns the DateTimeOffset for the tick count of the last input 31 | /// 32 | public DateTimeOffset LastInputDateTime => DateTimeOffset.Now.Subtract(LastInputTimeSpan); 33 | 34 | /// 35 | /// A factory method to simplify creating the LastInputInfo struct 36 | /// 37 | /// LastInputInfo 38 | public static LastInputInfo Create() 39 | { 40 | return new LastInputInfo 41 | { 42 | _cbSize = (uint)Marshal.SizeOf(typeof(LastInputInfo)) 43 | }; 44 | } 45 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Structs/RawDevice.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Dapplo.Windows.Input.Structs; 7 | 8 | /// 9 | /// This is used to similate a union in the RawInput struct, were cannot use Explicit due to 32/64 bit 10 | /// 11 | [StructLayout(LayoutKind.Explicit)] 12 | [SuppressMessage("ReSharper", "ConvertToAutoProperty")] 13 | [SuppressMessage("ReSharper", "ArrangeAccessorOwnerBody")] 14 | public struct RawDevice 15 | { 16 | [FieldOffset(0)] private readonly RawMouse _mouse; 17 | [FieldOffset(0)] private readonly RawKeyboard _keyboard; 18 | [FieldOffset(0)] private readonly RawHID _hid; 19 | 20 | /// 21 | /// Information on the mouse 22 | /// 23 | public RawMouse Mouse 24 | { 25 | get { return _mouse; } 26 | } 27 | 28 | /// 29 | /// Information on the keyboard 30 | /// 31 | public RawKeyboard Keyboard 32 | { 33 | get { return _keyboard; } 34 | } 35 | 36 | /// 37 | /// Information on the HID device 38 | /// 39 | // ReSharper disable once InconsistentNaming 40 | public RawHID HID 41 | { 42 | get { return _hid; } 43 | } 44 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Structs/RawHID.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Diagnostics.CodeAnalysis; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace Dapplo.Windows.Input.Structs; 8 | 9 | /// 10 | /// Describes the format of the raw input from a Human Interface Device (HID). 11 | /// See RAWHID structure 12 | /// 13 | [StructLayout(LayoutKind.Sequential)] 14 | [SuppressMessage("ReSharper", "ConvertToAutoProperty")] 15 | [SuppressMessage("ReSharper", "ArrangeAccessorOwnerBody")] 16 | // ReSharper disable once InconsistentNaming 17 | public struct RawHID 18 | { 19 | // The size, in bytes, of each HID input in bRawData. 20 | private readonly uint _dwSizeHid; 21 | // The number of HID inputs in bRawData. 22 | private readonly uint _dwCount; 23 | // The raw input data, as an array of bytes. 24 | private readonly IntPtr _bRawData; 25 | 26 | /// 27 | /// Returns the raw input data, as an array of bytes. 28 | /// 29 | public byte[] GetData() 30 | { 31 | var data = new byte[_dwSizeHid * _dwCount]; 32 | Marshal.Copy(_bRawData, data, 0, data.Length); 33 | return data; 34 | } 35 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Structs/RawInput.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Dapplo.Windows.Input.Structs; 7 | 8 | /// 9 | /// Contains the raw input from a device. 10 | /// See RAWINPUT structure 11 | /// 12 | [StructLayout(LayoutKind.Sequential)] 13 | [SuppressMessage("ReSharper", "ConvertToAutoProperty")] 14 | [SuppressMessage("ReSharper", "ArrangeAccessorOwnerBody")] 15 | public struct RawInput 16 | { 17 | // 64 bit header size: 24 32 bit the header size: 16 18 | private RawInputHeader _header; 19 | // Creating the rest in a struct allows the header size to align correctly for 32/64 bit 20 | private RawDevice _device; 21 | 22 | /// 23 | /// The RawInput header 24 | /// 25 | public RawInputHeader Header 26 | { 27 | get { return _header; } 28 | set { _header = value; } 29 | } 30 | 31 | /// 32 | /// The device. 33 | /// 34 | public RawDevice Device 35 | { 36 | get { return _device; } 37 | set { _device = value; } 38 | } 39 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Structs/RawInputDeviceInfoMouse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Dapplo.Windows.Input.Structs; 7 | 8 | /// 9 | /// This struct defines the raw input data coming from the specified mouse. 10 | /// See RID_DEVICE_INFO_MOUSE structure 11 | /// Remarks: 12 | /// For the mouse, the Usage Page is 1 and the Usage is 2. 13 | /// 14 | [StructLayout(LayoutKind.Sequential)] 15 | [SuppressMessage("ReSharper", "ConvertToAutoProperty")] 16 | [SuppressMessage("ReSharper", "ArrangeAccessorOwnerBody")] 17 | public struct RawInputDeviceInfoMouse 18 | { 19 | private readonly int _dwId; 20 | private readonly int _dwNumberOfButtons; 21 | private readonly int _dwSampleRate; 22 | private readonly bool _fHasHorizontalWheel; 23 | 24 | /// 25 | /// The identifier of the mouse device. 26 | /// 27 | public int Id => _dwId; 28 | 29 | /// 30 | /// The number of buttons for the mouse. 31 | /// 32 | public int NumberOfButtons => _dwNumberOfButtons; 33 | 34 | /// 35 | /// The number of data points per second. This information may not be applicable for every mouse device. 36 | /// 37 | public int SampleRate => _dwSampleRate; 38 | 39 | /// 40 | /// TRUE if the mouse has a wheel for horizontal scrolling; otherwise, FALSE. 41 | /// Windows XP: This member is only supported starting with Windows Vista. 42 | /// 43 | public bool HasHorizontalWheel => _fHasHorizontalWheel; 44 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Structs/RawInputDeviceList.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Diagnostics.CodeAnalysis; 5 | using System.Runtime.InteropServices; 6 | using Dapplo.Windows.Input.Enums; 7 | 8 | namespace Dapplo.Windows.Input.Structs; 9 | 10 | /// 11 | /// Contains information about a raw input device. 12 | /// See RAWINPUTDEVICELIST structure 13 | /// 14 | [StructLayout(LayoutKind.Sequential)] 15 | [SuppressMessage("ReSharper", "ConvertToAutoProperty")] 16 | [SuppressMessage("ReSharper", "ArrangeAccessorOwnerBody")] 17 | public struct RawInputDeviceList 18 | { 19 | private readonly IntPtr _hDevice; 20 | private readonly RawInputDeviceTypes _dwType; 21 | 22 | /// 23 | /// A handle to the raw input device. 24 | /// 25 | public IntPtr Handle 26 | { 27 | get { return _hDevice; } 28 | } 29 | 30 | /// 31 | /// The type of device 32 | /// 33 | public RawInputDeviceTypes RawInputDeviceType 34 | { 35 | get { return _dwType; } 36 | } 37 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/Structs/RawInputHeader.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Diagnostics.CodeAnalysis; 5 | using System.Runtime.InteropServices; 6 | using Dapplo.Windows.Input.Enums; 7 | 8 | namespace Dapplo.Windows.Input.Structs; 9 | 10 | /// 11 | /// Contains the header information that is part of the raw input data. 12 | /// See RAWINPUTHEADER structure 13 | /// 14 | [StructLayout(LayoutKind.Sequential)] 15 | [SuppressMessage("ReSharper", "ConvertToAutoProperty")] 16 | [SuppressMessage("ReSharper", "ArrangeAccessorOwnerBody")] 17 | public struct RawInputHeader 18 | { 19 | private RawInputDeviceTypes _dwType; 20 | private uint _dwSize; // Size in bytes of the entire input packet of data. This includes RAWINPUT plus possible extra input reports in the RAWHID variable length array. 21 | private IntPtr _hDevice; // A handle to the device generating the raw input data. 22 | private IntPtr _wParam; // RIM_INPUT 0 if input occurred while application was in the foreground else RIM_INPUTSINK 1 if it was not. 23 | 24 | 25 | /// 26 | /// Type of raw input (RIM_TYPEHID 2, RIM_TYPEKEYBOARD 1, RIM_TYPEMOUSE 0) 27 | /// 28 | public RawInputDeviceTypes Type 29 | { 30 | get { return _dwType; } 31 | set { _dwType = value; } 32 | } 33 | 34 | /// 35 | /// A handle to the Device. 36 | /// 37 | public IntPtr DeviceHandle 38 | { 39 | get { return _hDevice; } 40 | set { _hDevice = value; } 41 | } 42 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Input/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Kernel32/Dapplo.Windows.Kernel32.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Kernel32 is a library to assist calling the kernel32 api 4 | windows native Kernel32 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Kernel32/Enums/DefaultDllDirectories.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Kernel32.Enums; 6 | 7 | /// 8 | /// The directories to search. This parameter can be any combination of the following values. 9 | /// See SetDefaultDllDirectories function 10 | /// 11 | [Flags] 12 | public enum DefaultDllDirectories 13 | { 14 | /// 15 | /// If this value is used, the application's installation directory is searched. 16 | /// 17 | SearchApplicationDirectory = 0x200, 18 | /// 19 | /// If this value is used, any path explicitly added using the AddDllDirectory or SetDllDirectory function is searched. If more than one directory has been added, the order in which those directories are searched is unspecified. 20 | /// 21 | SearchUserDirectories = 0x400, 22 | /// 23 | /// If this value is used, %windows%\system32 is searched. 24 | /// 25 | SearchSystem32Directory = 0x800, 26 | /// 27 | /// This value is a combination of LOAD_LIBRARY_SEARCH_APPLICATION_DIR, LOAD_LIBRARY_SEARCH_SYSTEM32, and LOAD_LIBRARY_SEARCH_USER_DIRS. 28 | /// This value represents the recommended maximum number of directories an application should include in its DLL search path. 29 | /// 30 | SearchDefaultDirectories = 0x1000 31 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Kernel32/Enums/GlobalMemorySettings.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Kernel32.Enums; 6 | 7 | /// 8 | /// See GlobalAlloc function 9 | /// 10 | [Flags] 11 | public enum GlobalMemorySettings : uint 12 | { 13 | /// 14 | /// Allocates fixed memory. The return value is a pointer. 15 | /// 16 | Fixed = 0, 17 | /// 18 | /// Allocates movable memory. Memory blocks are never moved in physical memory, but they can be moved within the default heap. 19 | /// The return value is a handle to the memory object. To translate the handle into a pointer, use the GlobalLock function. 20 | /// This value cannot be combined with Fixed. 21 | /// 22 | Movable = 0x02, 23 | /// 24 | /// Initializes memory contents to zero. 25 | /// 26 | ZeroInit = 0x40 27 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Kernel32/Enums/ThreadAccess.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Diagnostics.CodeAnalysis; 5 | 6 | namespace Dapplo.Windows.Kernel32.Enums; 7 | #pragma warning disable 1591 8 | [SuppressMessage("ReSharper", "InconsistentNaming")] 9 | [Flags] 10 | public enum ThreadAccess 11 | { 12 | TERMINATE = 0x0001, 13 | SUSPEND_RESUME = 0x0002, 14 | GET_CONTEXT = 0x0008, 15 | SET_CONTEXT = 0x0010, 16 | SET_INFORMATION = 0x0020, 17 | QUERY_INFORMATION = 0x0040, 18 | SET_THREAD_TOKEN = 0x0080, 19 | IMPERSONATE = 0x0100, 20 | DIRECT_IMPERSONATION = 0x0200 21 | #pragma warning restore 1591 22 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Kernel32/Enums/WindowsProductTypes.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Diagnostics.CodeAnalysis; 5 | 6 | namespace Dapplo.Windows.Kernel32.Enums; 7 | 8 | /// 9 | /// Any additional information about the system. This member can be one of the following values. 10 | /// See 11 | /// OSVERSIONINFOEX structure 12 | /// 13 | [Flags] 14 | [SuppressMessage("ReSharper", "InconsistentNaming")] 15 | public enum WindowsProductTypes : byte 16 | { 17 | /// 18 | /// The operating system is Windows 8, Windows 7, Windows Vista, Windows XP Professional, Windows XP Home Edition, or 19 | /// Windows 2000 Professional. 20 | /// 21 | VER_NT_WORKSTATION = 0x00000001, 22 | 23 | /// 24 | /// The system is a domain controller and the operating system is Windows Server 2012 , Windows Server 2008 R2, Windows 25 | /// Server 2008, Windows Server 2003, or Windows 2000 Server 26 | /// 27 | VER_NT_DOMAIN_CONTROLLER = 0x00000002, 28 | 29 | /// 30 | /// The operating system is Windows Server 2012, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, or 31 | /// Windows 2000 Server. 32 | /// Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER. 33 | /// 34 | VER_NT_SERVER = 0x00000003 35 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Messages/Dapplo.Windows.Messages.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Messages is a library with the Windows messages and a WinProc helper. 4 | windows messages 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | true 7 | true 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Messages/WinProcHandlerHook.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | #if !NETSTANDARD2_0 4 | using System; 5 | using System.Windows.Interop; 6 | 7 | namespace Dapplo.Windows.Messages 8 | { 9 | /// 10 | /// Wrapper of the HwndSourceHook for the WinProcHandler, to allow to specify a disposable 11 | /// 12 | public class WinProcHandlerHook 13 | { 14 | /// 15 | /// The actual HwndSourceHook 16 | /// 17 | public HwndSourceHook Hook { get; } 18 | 19 | /// 20 | /// Optional disposable which is called to make a cleanup possible 21 | /// 22 | public IDisposable Disposable { get; set; } 23 | 24 | /// 25 | /// Default constructor, taking the needed HwndSourceHook 26 | /// 27 | /// HwndSourceHook 28 | public WinProcHandlerHook(HwndSourceHook hook) 29 | { 30 | Hook = hook; 31 | } 32 | } 33 | } 34 | #endif -------------------------------------------------------------------------------- /src/Dapplo.Windows.Messages/WindowMessageInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using Dapplo.Windows.Messages.Enumerations; 5 | 6 | namespace Dapplo.Windows.Messages; 7 | 8 | /// 9 | /// Container for the windows messages 10 | /// 11 | public class WindowMessageInfo 12 | { 13 | /// 14 | /// IntPtr with the Handle of the window 15 | /// 16 | public IntPtr Handle { get; private set; } 17 | 18 | /// 19 | /// WindowsMessages which is the actual message 20 | /// 21 | public WindowsMessages Message { get; private set; } 22 | 23 | /// 24 | /// IntPtr with the word-param 25 | /// 26 | public IntPtr WordParam { get; private set; } 27 | 28 | /// 29 | /// IntPtr with the long-param 30 | /// 31 | public IntPtr LongParam { get; private set; } 32 | 33 | /// 34 | /// Factory method for the Window Message Info 35 | /// 36 | /// IntPtr with the Handle of the window 37 | /// WindowsMessages which is the actual message 38 | /// IntPtr with the word-param 39 | /// IntPtr with the long-param 40 | /// WindowMessageInfo 41 | public static WindowMessageInfo Create(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) 42 | { 43 | return new WindowMessageInfo 44 | { 45 | Handle = hWnd, 46 | Message = (WindowsMessages)msg, 47 | WordParam = wParam, 48 | LongParam = lParam 49 | }; 50 | } 51 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Messages/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Multimedia/Dapplo.Windows.Multimedia.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Multimedia is a simple wrapper around WinMM 4 | windows native winmm 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Multimedia/Enums/SystemSounds.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Multimedia.Enums; 4 | 5 | /// 6 | /// Default system sounds 7 | /// 8 | public enum SystemSounds 9 | { 10 | /// 11 | /// Sound/event that is associated with the Windows "Information" alert type. 12 | /// 13 | SystemAsterisk, 14 | 15 | /// 16 | /// Sound/event that is associated with the Windows "default" alert type. 17 | /// 18 | SystemDefault, 19 | 20 | /// 21 | /// Sound/event that is associated with the Windows "Exclamation" alert type. 22 | /// 23 | SystemExclamation, 24 | 25 | /// 26 | /// Sound/event that is associated with the Windows "Exit" alert type. 27 | /// 28 | SystemExit, 29 | 30 | /// 31 | /// Sound/event that is associated with the Windows "Hand" alert type. 32 | /// 33 | SystemHand, 34 | 35 | /// 36 | /// Sound/event that is associated with the Windows "Question" alert type. 37 | /// 38 | SystemQuestion, 39 | 40 | /// 41 | /// Sound/event that is associated with the Windows "Start". 42 | /// 43 | SystemStart, 44 | 45 | /// 46 | /// Sound/event that is associated with the Windows "Welcome". 47 | /// 48 | SystemWelcome 49 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Shell32/Dapplo.Windows.Shell32.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.Shell32 provides logic of the Windows Shell32 API 4 | windows native shell32 5 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Shell32/Enums/AppBarEdges.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.Shell32.Enums; 4 | 5 | /// 6 | /// A value that specifies an edge of the screen. 7 | /// 8 | public enum AppBarEdges : uint 9 | { 10 | /// 11 | /// Left edge. 12 | /// 13 | Left = 0, 14 | /// 15 | /// Top edge. 16 | /// 17 | Top = 1, 18 | /// 19 | /// Right edge. 20 | /// 21 | Right = 2, 22 | /// 23 | /// Bottom edge. 24 | /// 25 | Bottom = 3 26 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Shell32/Enums/AppBarStates.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Shell32.Enums; 6 | 7 | /// 8 | /// A value that specifies an edge of the screen. 9 | /// 10 | [Flags] 11 | public enum AppBarStates 12 | { 13 | /// 14 | /// ABS_MANUAL - No automatic function 15 | /// 16 | None = 0, 17 | /// 18 | /// ABS_AUTOHIDE - Autohides the AppBar 19 | /// 20 | AutoHide = 1, 21 | /// 22 | /// ABS_ALWAYSONTOP - Make sure the AppBar is always on top 23 | /// 24 | AllwaysOnTop = 2 25 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests.Benchmarks/ClipboardBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Threading.Tasks; 6 | using BenchmarkDotNet.Attributes; 7 | using Dapplo.Windows.Clipboard; 8 | using Dapplo.Windows.Messages; 9 | 10 | namespace Dapplo.Windows.Tests.Benchmarks; 11 | 12 | /// 13 | /// Benchmarks for accessing the clipboard 14 | /// 15 | [MinColumn, MaxColumn, MemoryDiagnoser] 16 | public class ClipboardBenchmarks 17 | { 18 | private readonly IntPtr _handle = WinProcHandler.Instance.Handle; 19 | [Benchmark, STAThread] 20 | public async Task LockClipboard() 21 | { 22 | using (await ClipboardNative.AccessAsync(_handle)) 23 | { 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests.Benchmarks/InteropWindowBenchmark.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Diagnostics; 5 | using System.Reactive.Linq; 6 | using System.Reactive.Threading.Tasks; 7 | using System.Threading.Tasks; 8 | using BenchmarkDotNet.Attributes; 9 | using Dapplo.Windows.Desktop; 10 | using Dapplo.Windows.Enums; 11 | 12 | namespace Dapplo.Windows.Tests.Benchmarks; 13 | 14 | [MinColumn, MaxColumn, MemoryDiagnoser] 15 | public class InteropWindowBenchmark : IDisposable 16 | { 17 | private Process _notepadProcess; 18 | 19 | [GlobalSetup] 20 | public void Setup() 21 | { 22 | // Start a process to test against 23 | _notepadProcess = Process.Start("notepad.exe"); 24 | if (_notepadProcess == null) 25 | { 26 | throw new NotSupportedException("Couldn't start notepad.exe"); 27 | } 28 | // Make sure it's started 29 | // Wait until the process started it's message pump (listening for input) 30 | _notepadProcess.WaitForInputIdle(); 31 | } 32 | 33 | [Benchmark, STAThread] 34 | public void Fill() 35 | { 36 | var interopWindow = InteropWindowFactory.CreateFor(_notepadProcess.MainWindowHandle); 37 | if (interopWindow.Handle == IntPtr.Zero) 38 | { 39 | throw new NotSupportedException("Somehow the window was not found!"); 40 | } 41 | interopWindow.Fill(); 42 | } 43 | 44 | [GlobalCleanup] 45 | public void Dispose() 46 | { 47 | // Kill the process 48 | _notepadProcess.Kill(); 49 | } 50 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests.Benchmarks/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using BenchmarkDotNet.Configs; 6 | using BenchmarkDotNet.Environments; 7 | using BenchmarkDotNet.Jobs; 8 | using BenchmarkDotNet.Running; 9 | 10 | namespace Dapplo.Windows.Tests.Benchmarks; 11 | 12 | public static class Program 13 | { 14 | [STAThread] 15 | public static void Main(string[] args) 16 | { 17 | 18 | var jobCore50 = Job.Default 19 | .WithMaxIterationCount(20) 20 | .WithRuntime(CoreRuntime.Core50) 21 | .WithPlatform(Platform.X64); 22 | var jobCore31 = Job.Default 23 | .WithMaxIterationCount(20) 24 | .WithRuntime(CoreRuntime.Core31) 25 | .WithPlatform(Platform.X64); 26 | var jobNet472 = Job.Default 27 | .WithMaxIterationCount(20) 28 | .WithRuntime(ClrRuntime.Net472) 29 | .WithPlatform(Platform.X64); 30 | var config = DefaultConfig.Instance 31 | .AddJob(jobCore50) 32 | .AddJob(jobCore31) 33 | .AddJob(jobNet472) 34 | ; 35 | 36 | BenchmarkRunner.Run(config); 37 | BenchmarkRunner.Run(config); 38 | BenchmarkRunner.Run(config); 39 | BenchmarkRunner.Run(config); 40 | Console.ReadLine(); 41 | } 42 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/AppWindowTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Linq; 4 | using System.Windows.Media.Imaging; 5 | using Dapplo.Log; 6 | using Dapplo.Log.XUnit; 7 | using Dapplo.Windows.App; 8 | using Xunit; 9 | using Xunit.Abstractions; 10 | using Dapplo.Windows.Desktop; 11 | using Dapplo.Windows.Icons; 12 | 13 | namespace Dapplo.Windows.Tests; 14 | 15 | public class AppWindowTests 16 | { 17 | private static readonly LogSource Log = new LogSource(); 18 | public AppWindowTests(ITestOutputHelper testOutputHelper) 19 | { 20 | LogSettings.RegisterDefaultLogger(LogLevels.Verbose, testOutputHelper); 21 | } 22 | 23 | /// 24 | /// All apps we find, should give true when IsApp and have a logo. 25 | /// 26 | /// 27 | [WpfFact] 28 | public void TestAppWindowList() 29 | { 30 | var apps = AppQuery.WindowsStoreApps.ToList(); 31 | foreach (var interopWindow in apps) 32 | { 33 | Log.Debug().WriteLine("{0} - {1}", interopWindow.GetCaption(), interopWindow.GetClassname()); 34 | Assert.True(interopWindow.IsApp()); 35 | var iconBitmapSource = interopWindow.GetIcon(); 36 | Assert.NotNull(iconBitmapSource); 37 | } 38 | } 39 | 40 | /// 41 | /// Make sure GetTopLevelWindows doesn't return an App Window. 42 | /// 43 | /// 44 | [WpfFact] 45 | public void TestApp_TopLevel() 46 | { 47 | var topLevelWindows = InteropWindowQuery.GetTopLevelWindows().ToList(); 48 | Assert.DoesNotContain(topLevelWindows, window => window.IsApp()); 49 | } 50 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/CitrixTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using Dapplo.Log; 4 | using Dapplo.Log.XUnit; 5 | using Xunit; 6 | using Xunit.Abstractions; 7 | using Dapplo.Windows.Citrix; 8 | 9 | namespace Dapplo.Windows.Tests; 10 | 11 | public class CitrixTests 12 | { 13 | public CitrixTests(ITestOutputHelper testOutputHelper) 14 | { 15 | LogSettings.RegisterDefaultLogger(LogLevels.Verbose, testOutputHelper); 16 | } 17 | 18 | /// 19 | /// Assume that we are not running on Citrix 20 | /// 21 | /// 22 | [Fact] 23 | public void TestCitrix_NotAvailable() 24 | { 25 | Assert.False(WinFrame.IsAvailabe, "We are running on Citrix????"); 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/ComInterfaces/ExcelApplicationClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Dapplo.Windows.Tests.ComInterfaces; 5 | 6 | [ClassInterface((short)0)] 7 | [ComSourceInterfaces("Microsoft.Office.Interop.Excel.AppEvents")] 8 | [Guid("00024500-0000-0000-C000-000000000046")] 9 | [TypeLibType(2)] 10 | [ComImport] 11 | public class ExcelApplicationClass : IExcelApplication 12 | { 13 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/ComInterfaces/IExcelApplication.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace Dapplo.Windows.Tests.ComInterfaces; 4 | 5 | [Guid("000208D5-0000-0000-C000-000000000046")] 6 | [CoClass(typeof(ExcelApplicationClass))] 7 | [ComImport] 8 | public interface IExcelApplication 9 | { 10 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/DwmTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using Dapplo.Log; 4 | using Dapplo.Log.XUnit; 5 | using Dapplo.Windows.DesktopWindowsManager; 6 | using Xunit; 7 | using Xunit.Abstractions; 8 | 9 | namespace Dapplo.Windows.Tests; 10 | 11 | public class DwmTest 12 | { 13 | public DwmTest(ITestOutputHelper testOutputHelper) 14 | { 15 | LogSettings.RegisterDefaultLogger(LogLevels.Verbose, testOutputHelper); 16 | } 17 | 18 | /// 19 | /// Test is Dwm is Enabled 20 | /// 21 | /// 22 | //[Fact] 23 | private void TestDwmEnabled() 24 | { 25 | Assert.True(DwmApi.IsDwmEnabled); 26 | } 27 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/InteropWindowTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Linq; 4 | using Dapplo.Log; 5 | using Dapplo.Log.XUnit; 6 | using Xunit; 7 | using Xunit.Abstractions; 8 | using Dapplo.Windows.Desktop; 9 | 10 | namespace Dapplo.Windows.Tests; 11 | 12 | public class InteropWindowTests 13 | { 14 | public InteropWindowTests(ITestOutputHelper testOutputHelper) 15 | { 16 | LogSettings.RegisterDefaultLogger(LogLevels.Verbose, testOutputHelper); 17 | } 18 | 19 | /// 20 | /// Test some of the InteropWindowQuery logic by finding the taskbar and the clock on it. 21 | /// 22 | /// 23 | //[Fact] 24 | public void TestTaskbarInfo() 25 | { 26 | var systray = InteropWindowQuery.GetTopWindows().FirstOrDefault(window => window.GetClassname() == "Shell_TrayWnd"); 27 | Assert.NotNull(systray); 28 | var clock = systray.GetChildren().FirstOrDefault(window => window.GetClassname() == "TrayClockWClass"); 29 | Assert.NotNull(clock); 30 | 31 | var info = clock.GetInfo(); 32 | Assert.True(info.ClientBounds.Width * info.ClientBounds.Height > 0); 33 | } 34 | 35 | //[Fact] 36 | public void Test_GetInfo_WithParentCrop() 37 | { 38 | 39 | const int testHandle = 0x000806a6; 40 | var testWindow = InteropWindowFactory.CreateFor(testHandle); 41 | var ws = testWindow.GetWindowScroller(); 42 | var info1 = ws.ScrollingWindow.GetInfo(); 43 | Assert.True(info1.Bounds.Width < 1920); 44 | var info2 = testWindow.GetInfo(); 45 | Assert.True(info2.Bounds.Width < 1920); 46 | } 47 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/Kernel32Tests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using Dapplo.Log; 4 | using Dapplo.Log.XUnit; 5 | using Dapplo.Windows.Kernel32; 6 | using Dapplo.Windows.Kernel32.Structs; 7 | using Xunit; 8 | using Xunit.Abstractions; 9 | 10 | namespace Dapplo.Windows.Tests; 11 | 12 | public class Kernel32Tests 13 | { 14 | public Kernel32Tests(ITestOutputHelper testOutputHelper) 15 | { 16 | LogSettings.RegisterDefaultLogger(LogLevels.Verbose, testOutputHelper); 17 | } 18 | 19 | [Fact] 20 | private void Test_IsRunningAsUwp() 21 | { 22 | Assert.False(PackageInfo.IsRunningOnUwp); 23 | } 24 | 25 | [Fact] 26 | private void Test_GetOsVersionInfoEx() 27 | { 28 | var osVersionInfoEx= OsVersionInfoEx.Create(); 29 | Assert.True(Kernel32Api.GetVersionEx(ref osVersionInfoEx)); 30 | //Assert.NotEmpty(osVersionInfoEx.ServicePackVersion); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/MouseHookTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Reactive.Linq; 4 | using System.Threading.Tasks; 5 | using Dapplo.Log; 6 | using Dapplo.Log.XUnit; 7 | using Dapplo.Windows.Input.Mouse; 8 | using Dapplo.Windows.Messages; 9 | using Dapplo.Windows.Messages.Enumerations; 10 | using Xunit.Abstractions; 11 | 12 | namespace Dapplo.Windows.Tests; 13 | 14 | /// 15 | /// Test mouse hooking 16 | /// 17 | public class MouseHookTests 18 | { 19 | public MouseHookTests(ITestOutputHelper testOutputHelper) 20 | { 21 | LogSettings.RegisterDefaultLogger(LogLevels.Verbose, testOutputHelper); 22 | } 23 | 24 | //[StaFact] 25 | private async Task Test_LeftMouseDownAsync() 26 | { 27 | // This takes care of having a WinProc handler, to make sure the messages arrive 28 | // ReSharper disable once UnusedVariable 29 | var winProcHandler = WinProcHandler.Instance; 30 | await MouseHook.MouseEvents.Where(args => args.WindowsMessage == WindowsMessages.WM_LBUTTONDOWN).FirstAsync(); 31 | } 32 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using Xunit; 4 | 5 | [assembly: CollectionBehavior(DisableTestParallelization = true, MaxParallelThreads = 1)] -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/SafeHandleTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using Dapplo.Log; 5 | using Dapplo.Log.XUnit; 6 | using Dapplo.Windows.Gdi32; 7 | using Dapplo.Windows.Gdi32.SafeHandles; 8 | using Xunit; 9 | using Xunit.Abstractions; 10 | 11 | namespace Dapplo.Windows.Tests; 12 | 13 | public class SafeHandleTests 14 | { 15 | public SafeHandleTests(ITestOutputHelper testOutputHelper) 16 | { 17 | LogSettings.RegisterDefaultLogger(LogLevels.Verbose, testOutputHelper); 18 | } 19 | 20 | [Fact] 21 | public void TestCreateCompatibleDc() 22 | { 23 | using (var desktopDcHandle = SafeWindowDcHandle.FromDesktop()) 24 | { 25 | Assert.False(desktopDcHandle.IsInvalid); 26 | 27 | // create a device context we can copy to 28 | using (var safeCompatibleDcHandle = Gdi32Api.CreateCompatibleDC(desktopDcHandle)) 29 | { 30 | Assert.False(safeCompatibleDcHandle.IsInvalid); 31 | } 32 | } 33 | } 34 | 35 | [Fact] 36 | public void TestSafeWindowDcHandle_IntPtrZero() 37 | { 38 | using (var safeDctHandle = SafeWindowDcHandle.FromWindow(IntPtr.Zero)) 39 | { 40 | Assert.Null(safeDctHandle); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/Shell32Tests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using Dapplo.Log; 4 | using Dapplo.Log.XUnit; 5 | using Xunit; 6 | using Xunit.Abstractions; 7 | using Dapplo.Windows.Shell32; 8 | 9 | namespace Dapplo.Windows.Tests; 10 | 11 | public class Shell32Tests 12 | { 13 | public Shell32Tests(ITestOutputHelper testOutputHelper) 14 | { 15 | LogSettings.RegisterDefaultLogger(LogLevels.Verbose, testOutputHelper); 16 | } 17 | 18 | /// 19 | /// Test AppBarr 20 | /// 21 | /// 22 | [Fact] 23 | private void TestAppBar() 24 | { 25 | var appBarData = Shell32Api.TaskbarPosition; 26 | Assert.False(appBarData.Bounds.IsEmpty); 27 | } 28 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/SoftwareInstallationTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Linq; 4 | using Dapplo.Log; 5 | using Dapplo.Log.XUnit; 6 | using Dapplo.Windows.Software; 7 | using Xunit; 8 | using Xunit.Abstractions; 9 | 10 | namespace Dapplo.Windows.Tests; 11 | 12 | public class SoftwareInstallationTests 13 | { 14 | private static readonly LogSource Log = new LogSource(); 15 | public SoftwareInstallationTests(ITestOutputHelper testOutputHelper) 16 | { 17 | LogSettings.RegisterDefaultLogger(LogLevels.Verbose, testOutputHelper); 18 | } 19 | 20 | [Fact] 21 | private void Test_InstalledSoftware() 22 | { 23 | var software = InstallationInformation.InstalledSoftware().OrderBy(details => details.DisplayName).ToList(); 24 | Assert.True(software.Count > 0); 25 | foreach (var softwareDetails in software) 26 | { 27 | Log.Debug().WriteLine(softwareDetails.ToString(), null); 28 | if (!string.IsNullOrEmpty(softwareDetails.HelpLink)) 29 | { 30 | Log.Debug().WriteLine("Help - {0}" , softwareDetails.HelpLink); 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/VersionTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using Dapplo.Log; 4 | using Dapplo.Log.XUnit; 5 | using Dapplo.Windows.Kernel32; 6 | using Dapplo.Windows.Kernel32.Structs; 7 | using Xunit; 8 | using Xunit.Abstractions; 9 | 10 | namespace Dapplo.Windows.Tests; 11 | 12 | public class VersionTests 13 | { 14 | public VersionTests(ITestOutputHelper testOutputHelper) 15 | { 16 | LogSettings.RegisterDefaultLogger(LogLevels.Verbose, testOutputHelper); 17 | } 18 | 19 | /// 20 | /// Test GetVersionEx 21 | /// 22 | [Fact] 23 | public void TestOsVersionInfoEx() 24 | { 25 | var osVersionInfoEx = OsVersionInfoEx.Create(); 26 | Assert.True(Kernel32Api.GetVersionEx(ref osVersionInfoEx)); 27 | Assert.True(osVersionInfoEx.MajorVersion >= 6); 28 | } 29 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.Tests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Dapplo.Windows.User32.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Dapplo.Windows.User32 provides logic of the Windows User32 API 4 | windows native user32 5 | true 6 | net472;netcoreapp3.1;netstandard2.0;net6.0-windows 7 | true 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/CursorInfoFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.User32.Enums; 6 | 7 | /// 8 | /// Flags for the CURSOR_INFO "flags" field, see: 9 | /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms648381.aspx 10 | /// 11 | [Flags] 12 | public enum CursorInfoFlags : uint 13 | { 14 | /// 15 | /// Cursor is hidden 16 | /// 17 | Hidden = 0, 18 | 19 | /// 20 | /// Cursor is showing 21 | /// 22 | Showing = 1, 23 | 24 | /// 25 | /// Cursor is suppressed 26 | /// 27 | Suppressed = 2 28 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/DesktopAccessRight.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Diagnostics.CodeAnalysis; 5 | 6 | namespace Dapplo.Windows.User32.Enums; 7 | 8 | /// 9 | /// Used to open a desktop 10 | /// 11 | [Flags] 12 | [SuppressMessage("ReSharper", "InconsistentNaming")] 13 | public enum DesktopAccessRight : uint 14 | { 15 | #pragma warning disable 1591 16 | DESKTOP_READOBJECTS = 0x00000001, 17 | DESKTOP_CREATEWINDOW = 0x00000002, 18 | DESKTOP_CREATEMENU = 0x00000004, 19 | DESKTOP_HOOKCONTROL = 0x00000008, 20 | DESKTOP_JOURNALRECORD = 0x00000010, 21 | DESKTOP_JOURNALPLAYBACK = 0x00000020, 22 | DESKTOP_ENUMERATE = 0x00000040, 23 | DESKTOP_WRITEOBJECTS = 0x00000080, 24 | DESKTOP_SWITCHDESKTOP = 0x00000100, 25 | 26 | GENERIC_ALL = DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU | 27 | DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK | 28 | DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP 29 | 30 | #pragma warning restore 1591 31 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/MonitorFrom.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.User32.Enums; 6 | 7 | /// 8 | /// Flags for the MonitorFromRect / MonitorFromWindow "flags" field 9 | /// see MonitorFromRect function 10 | /// or see MonitorFromWindow function 11 | /// 12 | [Flags] 13 | public enum MonitorFrom : uint 14 | { 15 | /// 16 | /// Returns a handle to the display monitor that is nearest to the rectangle. 17 | /// 18 | DefaultToNearest = 0, 19 | 20 | /// 21 | /// Returns NULL. (why??) 22 | /// 23 | DefaultToNull = 1, 24 | 25 | /// 26 | /// Returns a handle to the primary display monitor. 27 | /// 28 | DefaultToPrimary = 2 29 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/MonitorInfoFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.User32.Enums; 6 | 7 | /// 8 | /// A set of flags that represent attributes of the display monitor. 9 | /// 10 | [Flags] 11 | public enum MonitorInfoFlags 12 | { 13 | /// 14 | /// This is the primary display monitor. 15 | /// 16 | Primary = 1 17 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/PrintWindowFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Diagnostics.CodeAnalysis; 5 | 6 | namespace Dapplo.Windows.User32.Enums; 7 | 8 | /// 9 | /// See 10 | /// PrintWindow function 11 | /// 12 | [SuppressMessage("ReSharper", "InconsistentNaming")] 13 | public enum PrintWindowFlags : uint 14 | { 15 | /// 16 | /// Copy the complete window 17 | /// 18 | PW_COMPLETE = 0x00000000, 19 | 20 | /// 21 | /// Only the client area of the window is copied. 22 | /// By default, the entire window is copied. 23 | /// 24 | PW_CLIENTONLY = 0x00000001, 25 | 26 | /// 27 | /// Works on windows that use DirectX or DirectComposition 28 | /// 29 | PW_RENDERFULLCONTENT = 0x00000002 30 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/RegionResults.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.User32.Enums; 4 | 5 | /// 6 | /// See See 7 | /// GetWindowRgn function 8 | /// 9 | public enum RegionResults 10 | { 11 | /// 12 | /// The specified window does not have a region, or an error occurred while attempting to return the region. 13 | /// 14 | Error = 0, 15 | 16 | /// 17 | /// The region is empty. 18 | /// 19 | NullRegion = 1, 20 | 21 | /// 22 | /// The region is a single rectangle. 23 | /// 24 | SimpleRegion = 2, 25 | 26 | /// 27 | /// The region is more than one rectangle. 28 | /// 29 | ComplexRegion = 3 30 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/ScrollBarStateIndexes.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.User32.Enums; 4 | 5 | /// 6 | /// See here 7 | /// 8 | public enum ScrollBarStateIndexes : uint 9 | { 10 | /// 11 | /// The scroll bar itself. 12 | /// 13 | Scrollbar, 14 | 15 | /// 16 | /// The top or right arrow button. 17 | /// 18 | TopOrRightArrow, 19 | 20 | /// 21 | /// The page up or page right region. 22 | /// 23 | PageUpOrRightRegion, 24 | 25 | /// 26 | /// The scroll box (thumb). 27 | /// 28 | ScrollBox, 29 | 30 | /// 31 | /// The page down or page left region. 32 | /// 33 | PageDownOrLeftRegion, 34 | 35 | /// 36 | /// The bottom or left arrow button. 37 | /// 38 | ButtonOrLeftArrow 39 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/ScrollBarTypes.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.User32.Enums; 4 | 5 | /// 6 | /// See here 7 | /// 8 | public enum ScrollBarTypes 9 | { 10 | /// 11 | /// The horizontal scroll bar of the specified window 12 | /// 13 | Horizontal = 0, 14 | 15 | /// 16 | /// The vertical scroll bar of the specified window 17 | /// 18 | Vertical = 1, 19 | 20 | /// 21 | /// A scroll bar control 22 | /// 23 | Control = 2, 24 | 25 | /// 26 | /// The horizontal and vertical scroll bars of the specified window 27 | /// 28 | Both = 3 29 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/ScrollInfoMask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.User32.Enums; 6 | 7 | /// 8 | /// The ScrollInfoMask enum is used for retrieving the SCROLLINFO via the GetScrollInfo 9 | /// See here 10 | /// 11 | [Flags] 12 | public enum ScrollInfoMask 13 | { 14 | /// 15 | /// Copies the scroll range to the Minimum and Maximum members of the SCROLLINFO structure pointed to by lpsi. 16 | /// 17 | Range = 0x1, 18 | 19 | /// 20 | /// Copies the scroll page to the PageSize member of the SCROLLINFO structure pointed to by lpsi. 21 | /// 22 | Page = 0x2, 23 | 24 | /// 25 | /// Copies the scroll position to the Position member of the SCROLLINFO structure pointed to by lpsi. 26 | /// 27 | Pos = 0x4, 28 | 29 | /// 30 | /// Unknown 31 | /// 32 | DisableNoScroll = 0x8, 33 | 34 | /// 35 | /// Copies the current scroll box tracking position to the TrackingPosition member of the SCROLLINFO structure pointed 36 | /// to by 37 | /// lpsi. 38 | /// 39 | Trackpos = 0x10, 40 | 41 | /// 42 | /// All of the above 43 | /// 44 | All = Range | Page | Pos | Trackpos 45 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/ScrollModes.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.User32.Enums; 4 | 5 | /// 6 | /// Scroll-modes for the WindowScroller 7 | /// 8 | public enum ScrollModes 9 | { 10 | /// 11 | /// Send message to the window with an absolute position 12 | /// 13 | AbsoluteWindowMessage, 14 | 15 | /// 16 | /// Send message to the window for page up or down 17 | /// 18 | WindowsMessage, 19 | 20 | /// 21 | /// Send a mousewheel event 22 | /// 23 | MouseWheel, 24 | 25 | /// 26 | /// Send page up or down as key press 27 | /// 28 | KeyboardPageUpDown 29 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/SendMessageTimeoutFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.User32.Enums; 6 | 7 | /// 8 | /// See SendMessageTimeout function 9 | /// 10 | [Flags] 11 | public enum SendMessageTimeoutFlags : uint 12 | { 13 | /// 14 | /// The calling thread is not prevented from processing other requests while waiting for the function to return. 15 | /// 16 | Normal = 0x0, 17 | 18 | /// 19 | /// Prevents the calling thread from processing any other requests until the function returns. 20 | /// 21 | Block = 0x1, 22 | 23 | /// 24 | /// The function returns without waiting for the time-out period to elapse if the receiving thread appears to not 25 | /// respond or "hangs." 26 | /// 27 | AbortIfHung = 0x2, 28 | 29 | /// 30 | /// The function does not enforce the time-out period as long as the receiving thread is processing messages. 31 | /// 32 | NoTimeoutIfNotHung = 0x8, 33 | 34 | /// 35 | /// The function should return 0 if the receiving window is destroyed or its owning thread dies while the message is 36 | /// being processed. 37 | /// 38 | ErrorOnExit = 0x20 39 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/SystemParametersInfoBehaviors.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.User32.Enums; 4 | 5 | /// 6 | /// If a system parameter is being set, specifies whether the user profile is to be updated, and if so, whether the 7 | /// WM_SETTINGCHANGE message is to be broadcast to all top-level windows to notify them of the change. 8 | /// This parameter can be zero if you do not want to update the user profile or broadcast the WM_SETTINGCHANGE message, 9 | /// or it can be one or more of the following values. 10 | /// 11 | public enum SystemParametersInfoBehaviors : uint 12 | { 13 | /// 14 | /// Do nothing 15 | /// 16 | None = 0x00, 17 | 18 | /// Writes the new system-wide parameter setting to the user profile. 19 | UpdateIniFile = 0x01, 20 | 21 | /// Broadcasts the WM_SETTINGCHANGE message after updating the user profile. 22 | SendChange = 0x02, 23 | 24 | /// Same as SPIF_SENDCHANGE. 25 | SendWinIniChange = SendChange 26 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/TitleBarInfoIndexes.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Dapplo.Windows.User32.Enums; 4 | 5 | /// 6 | /// The following are the title bar elements represented in the arrays. 7 | /// 8 | public enum TitleBarInfoIndexes 9 | { 10 | /// 11 | /// Index for the titlebar 12 | /// 13 | TitleBar = 0, 14 | 15 | /// 16 | /// Not used 17 | /// 18 | Reserved = 1, 19 | 20 | /// 21 | /// Index for the minimize button 22 | /// 23 | MinimizeButton = 2, 24 | 25 | /// 26 | /// Index for the maximize button 27 | /// 28 | MaximizeButton = 3, 29 | 30 | /// 31 | /// Index for the help button 32 | /// 33 | HelpButton = 4, 34 | 35 | /// 36 | /// Index for the close button 37 | /// 38 | CloseButton = 5 39 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/WindowDisplayAffinity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Diagnostics.CodeAnalysis; 4 | 5 | namespace Dapplo.Windows.User32.Enums; 6 | 7 | /// 8 | /// GetWindowsDisplayAffinity Enum values are described here: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowdisplayaffinity 9 | /// 10 | [SuppressMessage("ReSharper", "InconsistentNaming")] 11 | public enum WindowDisplayAffinity 12 | { 13 | /// 14 | /// Non affinity. 15 | /// 16 | None = 0, 17 | 18 | /// 19 | /// Enable window contents to be displayed on a monitor. 20 | /// 21 | Monitor = 1 22 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/WindowLongIndex.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Diagnostics.CodeAnalysis; 4 | 5 | namespace Dapplo.Windows.User32.Enums; 6 | 7 | /// 8 | /// Get/Set WindowLong Enum See: http://msdn.microsoft.com/en-us/library/ms633591.aspx 9 | /// 10 | [SuppressMessage("ReSharper", "InconsistentNaming")] 11 | public enum WindowLongIndex 12 | { 13 | /// 14 | /// Sets a new extended window style. 15 | /// 16 | GWL_EXSTYLE = -20, 17 | 18 | /// 19 | /// Sets a new application instance handle. 20 | /// 21 | GWL_HINSTANCE = -6, 22 | 23 | /// 24 | /// Sets a new identifier of the child window. The window cannot be a top-level window. 25 | /// 26 | GWL_ID = -12, 27 | 28 | /// 29 | /// Sets a new window style. 30 | /// 31 | GWL_STYLE = -16, 32 | 33 | /// 34 | /// Sets the user data associated with the window. 35 | /// This data is intended for use by the application that created the window. 36 | /// Its value is initially zero. 37 | /// 38 | GWL_USERDATA = -21, 39 | 40 | /// 41 | /// Sets a new address for the window procedure. 42 | /// You cannot change this attribute if the window does not belong to the same process as the calling thread. 43 | /// 44 | GWL_WNDPROC = -4 45 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Enums/windowPlacementFlags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.User32.Enums; 6 | 7 | /// 8 | /// See 9 | /// WINDOWPLACEMENT structure 10 | /// 11 | [Flags] 12 | public enum WindowPlacementFlags : uint 13 | { 14 | /// 15 | /// When no flags are used 16 | /// 17 | None = 0, 18 | 19 | /// 20 | /// The coordinates of the minimized window may be specified. 21 | /// This flag must be specified if the coordinates are set in the ptMinPosition member. 22 | /// 23 | SetMinPosition = 0x0001, 24 | 25 | /// 26 | /// If the calling thread and the thread that owns the window are attached to different input queues, the system posts 27 | /// the request to the thread that owns the window. 28 | /// This prevents the calling thread from blocking its execution while other threads process the request. 29 | /// 30 | AsyncWindowPlacement = 0x0004, 31 | 32 | /// 33 | /// The restored window will be maximized, regardless of whether it was maximized before it was minimized. 34 | /// This setting is only valid the next time the window is restored. 35 | /// It does not change the default restoration behavior. 36 | /// This flag is only valid when the SW_SHOWMINIMIZED value is specified for the showCmd member. 37 | /// 38 | RestoreToMaximized = 0x0002 39 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Structs/AnimationInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Dapplo.Windows.User32.Structs; 7 | 8 | /// 9 | /// Describes the animation effects associated with user actions. This structure is used with the SystemParametersInfo 10 | /// function when the SPI_GETANIMATION or SPI_SETANIMATION action value is specified. 11 | /// 12 | [SuppressMessage("Sonar Code Smell", "S1450:Private fields only used as local variables in methods should become local variables", Justification = "Interop!")] 13 | [StructLayout(LayoutKind.Sequential)] 14 | public struct AnimationInfo 15 | { 16 | private uint _cbSize; 17 | private int _iMinAnimate; 18 | 19 | /// 20 | /// Factory method to create AnimationInfo 21 | /// 22 | /// 23 | /// 24 | public static AnimationInfo Create(bool enableAnimations = true) 25 | { 26 | return new AnimationInfo 27 | { 28 | _cbSize = (uint) Marshal.SizeOf(typeof(AnimationInfo)), 29 | _iMinAnimate = enableAnimations ? 1 : 0 30 | }; 31 | } 32 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/Structs/CursorInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Runtime.InteropServices; 5 | using Dapplo.Windows.Common.Structs; 6 | using Dapplo.Windows.User32.Enums; 7 | 8 | namespace Dapplo.Windows.User32.Structs; 9 | 10 | /// 11 | /// See 12 | /// 13 | [StructLayout(LayoutKind.Sequential)] 14 | public struct CursorInfo 15 | { 16 | /// 17 | /// Size of the struct 18 | /// 19 | private int _cbSize; 20 | 21 | private readonly CursorInfoFlags _flags; 22 | private readonly IntPtr _hCursor; 23 | private readonly NativePoint _ptScreenPos; 24 | 25 | 26 | /// 27 | /// The cursor state, as CursorInfoFlags 28 | /// 29 | public CursorInfoFlags Flags => _flags; 30 | 31 | /// 32 | /// Handle (IntPtr) to the Cursor 33 | /// 34 | public IntPtr CursorHandle => _hCursor; 35 | 36 | /// 37 | /// A structure that receives the screen coordinates of the cursor. 38 | /// 39 | public NativePoint Location => _ptScreenPos; 40 | 41 | /// 42 | /// Factory for the structure 43 | /// 44 | public static CursorInfo Create() 45 | { 46 | var result = new CursorInfo 47 | { 48 | _cbSize = Marshal.SizeOf(typeof(CursorInfo)) 49 | }; 50 | return result; 51 | } 52 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows.User32/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Dapplo.Windows.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dapplo/Dapplo.Windows/55d2ca3705b75403fbf6d00cf9dd2b8b7a8a3d12/src/Dapplo.Windows.snk -------------------------------------------------------------------------------- /src/Dapplo.Windows/App/IAppVisibility.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Dapplo.Windows.App; 7 | 8 | // This is used for Windows 8 to see if the App Launcher is active 9 | // See https://msdn.microsoft.com/en-us/library/windows/desktop/jj554119.aspx 10 | [ComImport] 11 | [Guid("2246EA2D-CAEA-4444-A3C4-6DE827E44313")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IAppVisibility 14 | { 15 | MonitorAppVisibility GetAppVisibilityOnMonitor(IntPtr hMonitor); 16 | bool IsLauncherVisible { get; } 17 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows/App/MonitorAppVisibility.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System.Diagnostics.CodeAnalysis; 4 | 5 | namespace Dapplo.Windows.App; 6 | 7 | /// 8 | /// A simple enum for the GetAppVisibilityOnMonitor method, this tells us if an App is visible on the supplied monitor. 9 | /// 10 | [SuppressMessage("ReSharper", "InconsistentNaming")] 11 | internal enum MonitorAppVisibility 12 | { 13 | MAV_UNKNOWN = 0, // The mode for the monitor is unknown 14 | MAV_NO_APP_VISIBLE = 1, 15 | MAV_APP_VISIBLE = 2 16 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows/Desktop/InteropWindowFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Dapplo and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | using System; 4 | 5 | namespace Dapplo.Windows.Desktop; 6 | 7 | /// 8 | /// Factory for InteropWindows 9 | /// 10 | public static class InteropWindowFactory 11 | { 12 | /// 13 | /// Factory method to create a InteropWindow for the supplied handle 14 | /// 15 | /// int 16 | /// InteropWindow 17 | public static InteropWindow CreateFor(int handle) 18 | { 19 | return CreateFor(new IntPtr(handle)); 20 | } 21 | 22 | /// 23 | /// Factory method to create a InteropWindow for the supplied handle 24 | /// 25 | /// IntPtr 26 | /// InteropWindow 27 | public static InteropWindow CreateFor(IntPtr handle) 28 | { 29 | return new InteropWindow(handle); 30 | } 31 | } -------------------------------------------------------------------------------- /src/Dapplo.Windows/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "6.0.0", 4 | "rollForward": "latestMajor", 5 | "allowPrerelease": true 6 | } 7 | } -------------------------------------------------------------------------------- /src/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dapplo/Dapplo.Windows/55d2ca3705b75403fbf6d00cf9dd2b8b7a8a3d12/src/icon.png -------------------------------------------------------------------------------- /src/version.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", 3 | "version": "1.0", 4 | "publicReleaseRefSpec": [ 5 | ".*/master$" // we release out of master 6 | ], 7 | "nugetPackageVersion": { 8 | "semVer": 2 // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1. 9 | }, 10 | "cloudBuild": { 11 | "setVersionVariables": true, 12 | "buildNumber": { 13 | "enabled": true, 14 | "includeCommitId": { 15 | "when": "nonPublicReleaseOnly", 16 | "where": "buildMetadata" 17 | } 18 | } 19 | }, 20 | "inherit": false 21 | } --------------------------------------------------------------------------------