├── .github
├── FUNDING.yml
└── dependabot.yml
├── branding
├── nativemethods.png
├── nativemethods.psd
└── nativemethods-256.png
├── src
├── NativeMethods.Wpf
│ ├── Test.cs
│ └── NativeMethods.Wpf.csproj
├── Packages.props
├── NativeMethods
│ ├── NativeMethods.csproj
│ ├── Interop
│ │ ├── Gdi32.cs
│ │ ├── Gdip.cs
│ │ ├── Libraries.cs
│ │ ├── Shell32.cs
│ │ ├── UxTheme.cs
│ │ ├── Kernel32.cs
│ │ ├── Dwmapi.cs
│ │ └── User32.cs
│ ├── WinDef
│ │ ├── RefPOINT.cs
│ │ ├── POINT.cs
│ │ ├── POINTL.cs
│ │ ├── POINTS.cs
│ │ ├── SIZE.cs
│ │ ├── RECT.cs
│ │ └── RECTL.cs
│ └── Attributes
│ │ └── UnmanagedComponentAttribute.cs
├── NativeMethods.WinForms
│ ├── Test.cs
│ └── NativeMethods.WinForms.csproj
├── .vsconfig
├── Directory.Build.props
├── NativeMethods.sln
└── .editorconfig
├── CODEOWNERS
├── LICENSE
├── .gitattributes
├── README.md
├── CODE_OF_CONDUCT.md
└── .gitignore
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [lepoco]
--------------------------------------------------------------------------------
/branding/nativemethods.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lepoco/nativemethods/HEAD/branding/nativemethods.png
--------------------------------------------------------------------------------
/branding/nativemethods.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lepoco/nativemethods/HEAD/branding/nativemethods.psd
--------------------------------------------------------------------------------
/branding/nativemethods-256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lepoco/nativemethods/HEAD/branding/nativemethods-256.png
--------------------------------------------------------------------------------
/src/NativeMethods.Wpf/Test.cs:
--------------------------------------------------------------------------------
1 | namespace NativeMethods.Wpf
2 | {
3 | internal class Test
4 | {
5 | public Test()
6 | {
7 |
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Lines starting with '#' are comments.
2 | # Each line is a file pattern followed by one or more owners.
3 |
4 | # These owners will be the default owners for everything in the repo,
5 | # and will automatically be added as reviewers to all pull requests.
6 | * @pomianowski
7 |
--------------------------------------------------------------------------------
/src/Packages.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/NativeMethods/NativeMethods.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NativeMethods
6 | NativeMethods
7 | NativeMethods
8 | Set of tools and ready-made methods that are wrappers over the core functionalities of Windows, such as User32, Shell32 or Kernel32.
9 | windows native methods interop reflection pinvoke invoke win32 winapi win user32 shell32 kernel32 libraries lepo lepoco
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5 |
6 | version: 2
7 |
8 | updates:
9 | # Maintain dependencies for GitHub Actions
10 | - package-ecosystem: "github-actions"
11 | directory: "/"
12 | schedule:
13 | interval: "daily"
14 |
15 | # Maintain dependencies for nuget
16 | - package-ecosystem: "nuget"
17 | directory: "src/"
18 | schedule:
19 | interval: "daily"
--------------------------------------------------------------------------------
/src/NativeMethods.WinForms/Test.cs:
--------------------------------------------------------------------------------
1 | namespace NativeMethods.WinForms
2 | {
3 | internal class Test
4 | {
5 | public Test()
6 | {
7 | //User32.CreateWindowEx(
8 | // User32.WS_EX.APPWINDOW | User32.WS_EX.CLIENTEDGE,
9 | // "name",
10 | // "name",
11 | // User32.WS.BORDER,
12 | // 0,
13 | // 0,
14 | // 200,
15 | // 200,
16 | // IntPtr.Zero,
17 | // IntPtr.Zero,
18 | // IntPtr.Zero,
19 | // IntPtr.Zero);
20 |
21 | // Interop.Dwmapi.DwmGetColorizationParameters(out var colorizationParameters);
22 |
23 | // var x = NativeMethods.Interop.Kernel32.GetCurrentProcessId();
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/NativeMethods/Interop/Gdi32.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System;
10 | using System.Runtime.InteropServices;
11 |
12 | namespace NativeMethods.Interop;
13 |
14 | public static class Gdi32
15 | {
16 | [DllImport(Libraries.Gdi32)]
17 | [return: MarshalAs(UnmanagedType.Bool)]
18 | public static extern bool DeleteObject([In] IntPtr hObject);
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/src/NativeMethods.Wpf/NativeMethods.Wpf.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | true
6 | NativeMethods.Wpf
7 | NativeMethods.Wpf
8 | NativeMethods.Wpf
9 | Set of tools and ready-made methods that are wrappers over the core functionalities of Windows, such as User32, Shell32 or Kernel32. Along with special add-ons for Windows Presentation Foundation.
10 | windows native methods interop wpf presentation foundation reflection win32 winapi win user32 shell32 kernel32 libraries lepo lepoco
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/NativeMethods.WinForms/NativeMethods.WinForms.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | true
6 | NativeMethods.WinForms
7 | NativeMethods.WinForms
8 | NativeMethods.WinForms
9 | Set of tools and ready-made methods that are wrappers over the core functionalities of Windows, such as User32, Shell32 or Kernel32. Along with special add-ons for Windows Forms.
10 | windows native methods interop reflection winforms forms win32 winapi win user32 shell32 kernel32 libraries lepo lepoco
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/NativeMethods/WinDef/RefPOINT.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System.Runtime.InteropServices;
10 |
11 | namespace NativeMethods.WinDef;
12 |
13 | ///
14 | /// structure by reference.
15 | ///
16 | [StructLayout(LayoutKind.Sequential)]
17 | public class RefPOINT
18 | {
19 | ///
20 | /// Specifies the x-coordinate of the point.
21 | ///
22 | public int x;
23 |
24 | ///
25 | /// Specifies the y-coordinate of the point.
26 | ///
27 | public int y;
28 | }
29 |
--------------------------------------------------------------------------------
/src/NativeMethods/WinDef/POINT.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System.Runtime.InteropServices;
10 |
11 | namespace NativeMethods.WinDef;
12 |
13 | ///
14 | /// The POINT structure defines the x- and y-coordinates of a point.
15 | ///
16 | [StructLayout(LayoutKind.Sequential)]
17 | public struct POINT
18 | {
19 | ///
20 | /// Specifies the x-coordinate of the point.
21 | ///
22 | public int x;
23 |
24 | ///
25 | /// Specifies the y-coordinate of the point.
26 | ///
27 | public int y;
28 | }
29 |
--------------------------------------------------------------------------------
/src/NativeMethods/WinDef/POINTL.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System.Runtime.InteropServices;
10 |
11 | namespace NativeMethods.WinDef;
12 |
13 | ///
14 | /// The POINTL structure defines the x- and y-coordinates of a point.
15 | ///
16 | [StructLayout(LayoutKind.Sequential)]
17 | public struct POINTL
18 | {
19 | ///
20 | /// Specifies the x-coordinate of the point.
21 | ///
22 | public long x;
23 |
24 | ///
25 | /// Specifies the y-coordinate of the point.
26 | ///
27 | public long y;
28 | }
29 |
--------------------------------------------------------------------------------
/src/NativeMethods/WinDef/POINTS.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System.Runtime.InteropServices;
10 |
11 | namespace NativeMethods.WinDef;
12 |
13 | ///
14 | /// The POINTL structure defines the x- and y-coordinates of a point.
15 | ///
16 | [StructLayout(LayoutKind.Sequential)]
17 | public struct POINTS
18 | {
19 | ///
20 | /// Specifies the x-coordinate of the point.
21 | ///
22 | public short x;
23 |
24 | ///
25 | /// Specifies the y-coordinate of the point.
26 | ///
27 | public short y;
28 | }
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Leszek Pomianowski.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/src/NativeMethods/WinDef/SIZE.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System.Runtime.InteropServices;
10 |
11 | namespace NativeMethods.WinDef;
12 |
13 | ///
14 | /// The SIZE structure defines the width and height of a rectangle.
15 | ///
16 | [StructLayout(LayoutKind.Sequential)]
17 | public struct SIZE
18 | {
19 | ///
20 | /// Specifies the rectangle's width. The units depend on which function uses this structure.
21 | ///
22 | public long cx;
23 |
24 | ///
25 | /// Specifies the rectangle's height. The units depend on which function uses this structure.
26 | ///
27 | public long cy;
28 | }
29 |
--------------------------------------------------------------------------------
/src/NativeMethods/Interop/Gdip.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System;
10 | using System.Runtime.InteropServices;
11 |
12 | namespace NativeMethods.Interop;
13 |
14 | ///
15 | /// Windows GDI+ exposes a flat API that consists of about 600 functions, which are implemented in Gdiplus.dll and declared in Gdiplusflat.h.
16 | ///
17 | public static class Gdip
18 | {
19 | ///
20 | /// The Bitmap::GetHICON method creates an icon from this Bitmap object.
21 | ///
22 | ///
23 | ///
24 | /// GpStatus HRESULT
25 | [DllImport(Libraries.Gdip, CharSet = CharSet.Auto)]
26 | public static extern int GdipCreateHICONFromBitmap(IntPtr nativeBitmap, out IntPtr hicon);
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/src/.vsconfig:
--------------------------------------------------------------------------------
1 | {
2 | "version": "1.0",
3 | "components": [
4 | "Microsoft.VisualStudio.Component.NuGet",
5 | "Microsoft.VisualStudio.Component.Roslyn.Compiler",
6 | "Microsoft.Component.MSBuild",
7 | "Microsoft.NetCore.Component.Runtime.6.0",
8 | "Microsoft.NetCore.Component.SDK",
9 | "Microsoft.Net.Component.4.7.2.TargetingPack",
10 | "Microsoft.VisualStudio.Component.Roslyn.LanguageServices",
11 | "Microsoft.ComponentGroup.ClickOnce.Publish",
12 | "Microsoft.NetCore.Component.DevelopmentTools",
13 | "Microsoft.Net.Component.4.8.SDK",
14 | "Microsoft.Net.ComponentGroup.DevelopmentPrerequisites",
15 | "Microsoft.Component.ClickOnce",
16 | "Microsoft.VisualStudio.Component.ManagedDesktop.Core",
17 | "Microsoft.Net.Component.4.8.TargetingPack",
18 | "Microsoft.Net.Component.4.7.TargetingPack",
19 | "Microsoft.VisualStudio.Component.ManagedDesktop.Prerequisites",
20 | "Microsoft.VisualStudio.Component.PortableLibrary",
21 | "Microsoft.VisualStudio.Workload.ManagedDesktop",
22 | "Microsoft.Net.ComponentGroup.TargetingPacks.Common",
23 | "Microsoft.Component.CodeAnalysis.SDK",
24 | "Microsoft.Net.Component.4.6.TargetingPack",
25 | "Microsoft.NetCore.Component.Runtime.3.1",
26 | "Microsoft.NetCore.Component.Runtime.5.0",
27 | "Microsoft.Net.Component.4.6.1.TargetingPack"
28 | ]
29 | }
30 |
--------------------------------------------------------------------------------
/src/NativeMethods/Attributes/UnmanagedComponentAttribute.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System;
10 |
11 | namespace NativeMethods.Attributes;
12 |
13 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum |
14 | AttributeTargets.Interface | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Delegate,
15 | Inherited = false)]
16 |
17 | public class UnmanagedComponentAttribute : Attribute
18 | {
19 | public UnmanagedComponentAttribute()
20 | {
21 | }
22 |
23 | public UnmanagedComponentAttribute(string? message)
24 | {
25 | Message = message;
26 | }
27 |
28 | public UnmanagedComponentAttribute(string? message, bool error)
29 | {
30 | Message = message;
31 | IsError = error;
32 | }
33 |
34 | public string? Message { get; }
35 |
36 | public bool IsError { get; }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 0.0.3
6 | $(Version)
7 |
8 |
9 |
10 |
11 | net6.0-windows;net5.0-windows;netcoreapp3.1;net48;net47;net46
12 |
13 |
14 |
15 | lepo.co
16 | lepo.co
17 | Copyright (C) 2022 Leszek Pomianowski
18 | MIT
19 | https://raw.githubusercontent.com/lepoco/nativemethods/main/LICENSE
20 | https://github.com/lepoco/nativemethods
21 | https://github.com/lepoco/nativemethods
22 |
23 |
24 |
25 | nativemethods-256.png
26 |
27 |
28 |
29 | True
30 | \
31 |
32 |
33 |
34 |
35 | 10.0
36 | Library
37 | true
38 | true
39 | true
40 | false
41 |
42 |
43 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Set default behavior to automatically normalize line endings.
2 | * text=auto
3 |
4 | *.doc binary
5 | *.DOC binary
6 | *.docx binary
7 | *.DOCX binary
8 | *.dot binary
9 | *.DOT binary
10 | *.pdf binary
11 | *.PDF binary
12 | *.rtf binary
13 | *.RTF binary
14 |
15 | *.jpg binary
16 | *.png binary
17 | *.gif binary
18 |
19 | # Force bash scripts to always use lf line endings so that if a repo is accessed
20 | # in Unix via a file share from Windows, the scripts will work.
21 | *.in text eol=lf
22 | *.sh text eol=lf
23 |
24 | # Likewise, force cmd and batch scripts to always use crlf
25 | *.cmd text eol=crlf
26 | *.bat text eol=crlf
27 |
28 | *.cs text=auto diff=csharp
29 | *.vb text=auto
30 | *.resx text=auto
31 | *.c text=auto
32 | *.cpp text=auto
33 | *.cxx text=auto
34 | *.h text=auto
35 | *.hxx text=auto
36 | *.py text=auto
37 | *.rb text=auto
38 | *.java text=auto
39 | *.html text=auto
40 | *.htm text=auto
41 | *.css text=auto
42 | *.scss text=auto
43 | *.sass text=auto
44 | *.less text=auto
45 | *.js text=auto
46 | *.lisp text=auto
47 | *.clj text=auto
48 | *.sql text=auto
49 | *.php text=auto
50 | *.lua text=auto
51 | *.m text=auto
52 | *.asm text=auto
53 | *.erl text=auto
54 | *.fs text=auto
55 | *.fsx text=auto
56 | *.hs text=auto
57 |
58 | *.csproj text=auto
59 | *.vbproj text=auto
60 | *.fsproj text=auto
61 | *.dbproj text=auto
62 | *.sln text=auto eol=crlf
63 |
64 | # Set linguist language for .h files explicitly based on
65 | # https://github.com/github/linguist/issues/1626#issuecomment-401442069
66 | # this only affects the repo's language statistics
67 | *.h linguist-language=C
68 |
--------------------------------------------------------------------------------
/src/NativeMethods.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.1.32421.90
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeMethods", "NativeMethods\NativeMethods.csproj", "{875DE025-E259-4932-B7B8-2B393FD371C0}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeMethods.WinForms", "NativeMethods.WinForms\NativeMethods.WinForms.csproj", "{9008DE43-EAEF-4678-A47D-99D4137F3B72}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeMethods.Wpf", "NativeMethods.Wpf\NativeMethods.Wpf.csproj", "{144159A9-453E-4F71-B48B-9FDEC2F226E5}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {875DE025-E259-4932-B7B8-2B393FD371C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {875DE025-E259-4932-B7B8-2B393FD371C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {875DE025-E259-4932-B7B8-2B393FD371C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {875DE025-E259-4932-B7B8-2B393FD371C0}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {9008DE43-EAEF-4678-A47D-99D4137F3B72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {9008DE43-EAEF-4678-A47D-99D4137F3B72}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {9008DE43-EAEF-4678-A47D-99D4137F3B72}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {9008DE43-EAEF-4678-A47D-99D4137F3B72}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {144159A9-453E-4F71-B48B-9FDEC2F226E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {144159A9-453E-4F71-B48B-9FDEC2F226E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {144159A9-453E-4F71-B48B-9FDEC2F226E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {144159A9-453E-4F71-B48B-9FDEC2F226E5}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {C8FA893E-A05A-4594-B5CC-F82941ED2005}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/src/NativeMethods/Interop/Libraries.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | namespace NativeMethods.Interop;
10 |
11 | internal static class Libraries
12 | {
13 | public const string Advapi32 = "advapi32.dll";
14 | public const string BCrypt = "BCrypt.dll";
15 | public const string CoreComm_L1_1_1 = "api-ms-win-core-comm-l1-1-1.dll";
16 | public const string Crypt32 = "crypt32.dll";
17 | public const string Dwmapi = "dwmapi.dll";
18 | public const string Error_L1 = "api-ms-win-core-winrt-error-l1-1-0.dll";
19 | public const string HttpApi = "httpapi.dll";
20 | public const string IpHlpApi = "iphlpapi.dll";
21 | public const string Kernel32 = "kernel32.dll";
22 | public const string Memory_L1_3 = "api-ms-win-core-memory-l1-1-3.dll";
23 | public const string Mswsock = "mswsock.dll";
24 | public const string NCrypt = "ncrypt.dll";
25 | public const string NtDll = "ntdll.dll";
26 | public const string Odbc32 = "odbc32.dll";
27 | public const string OleAut32 = "oleaut32.dll";
28 | public const string PerfCounter = "perfcounter.dll";
29 | public const string RoBuffer = "api-ms-win-core-winrt-robuffer-l1-1-0.dll";
30 | public const string Secur32 = "secur32.dll";
31 | public const string Shell32 = "shell32.dll";
32 | public const string SspiCli = "sspicli.dll";
33 | public const string User32 = "user32.dll";
34 | public const string UxTheme = "uxtheme.dll";
35 | public const string Gdi32 = "gdi32.dll";
36 | public const string Gdip = "gdiplus.dll";
37 | public const string Version = "version.dll";
38 | public const string WebSocket = "websocket.dll";
39 | public const string WinHttp = "winhttp.dll";
40 | public const string WinMM = "winmm.dll";
41 | public const string Ws2_32 = "ws2_32.dll";
42 | public const string Wtsapi32 = "wtsapi32.dll";
43 | public const string CompressionNative = "System.IO.Compression.Native.dll";
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NativeMethods
2 | [Created with ❤ in Poland by lepo.co](https://dev.lepo.co/)
3 | Set of tools and ready-made methods that are wrappers over the core functionalities of Windows, such as `User32`, `Shell32` or `Kernel32`.
4 |
5 | [](https://github.com/lepoco/nativemethods/blob/master/LICENSE) [](https://www.nuget.org/packages/NativeMethods/) [](https://www.nuget.org/packages/NativeMethods/) [](https://www.nuget.org/packages/NativeMethods/) [](https://github.com/lepoco/nativemethods) [](https://github.com/sponsors/lepoco)
6 |
7 | ## 🚀 Getting started
8 | **NativeMethods** is delivered via **NuGet** package manager. You can find the package here: https://www.nuget.org/packages/NativeMethods/
9 |
10 | ## Wrapped Methods
11 | | Library | Method |
12 | | --- | --- |
13 | | **User32** | User32.SetWindowCompositionAttribute() |
14 | | **Shell32** | Shell32.Shell_NotifyIcon() |
15 | | **Kernel32** | Kernel32.CopyMemory() |
16 | | **Gdip** | Gdip.GdipCreateHICONFromBitmap() |
17 | | **Gdi32** | Gdi32.DeleteObject() |
18 |
19 | ## Microsoft Property
20 | NativeMethods is based on source code provided by the .NET Foundation, WinApi headers and reverse engineer Windows libraries. The purpose of the library is to facilitate the management of WinApi via C# and it's designed exclusively for Windows systems.
21 |
22 | ## Compilation
23 | Use Visual Studio 2022 and invoke the .sln.
24 |
25 | Visual Studio
26 | **NativeMethods** is an Open Source project. You are entitled to download and use the freely available Visual Studio Community Edition to build, run or develop for NativeMethods. As per the Visual Studio Community Edition license, this applies regardless of whether you are an individual or a corporate user.
27 |
28 | ## Code of Conduct
29 |
30 | This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.
31 |
32 | ## License
33 | NativeMethods is free and open source software licensed under **MIT License**. You can use it in private and commercial projects.
34 | Keep in mind that you must include a copy of the license in your project.
--------------------------------------------------------------------------------
/src/NativeMethods/WinDef/RECT.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System;
10 | using System.Runtime.InteropServices;
11 |
12 | namespace NativeMethods.WinDef;
13 |
14 | ///
15 | /// The RECT structure defines a rectangle by the coordinates of its upper-left and lower-right corners.
16 | ///
17 | [StructLayout(LayoutKind.Sequential)]
18 | public struct RECT
19 | {
20 | private int _left;
21 | private int _top;
22 | private int _right;
23 | private int _bottom;
24 |
25 | ///
26 | /// Specifies the x-coordinate of the upper-left corner of the rectangle.
27 | ///
28 | public int Left
29 | {
30 | get { return _left; }
31 | set { _left = value; }
32 | }
33 |
34 | ///
35 | /// Specifies the x-coordinate of the lower-right corner of the rectangle.
36 | ///
37 | public int Right
38 | {
39 | get { return _right; }
40 | set { _right = value; }
41 | }
42 |
43 | ///
44 | /// Specifies the y-coordinate of the upper-left corner of the rectangle.
45 | ///
46 | public int Top
47 | {
48 | get { return _top; }
49 | set { _top = value; }
50 | }
51 |
52 | ///
53 | /// Specifies the y-coordinate of the lower-right corner of the rectangle.
54 | ///
55 | public int Bottom
56 | {
57 | get { return _bottom; }
58 | set { _bottom = value; }
59 | }
60 |
61 | ///
62 | /// Specifies the width of the rectangle.
63 | ///
64 | public int Width
65 | {
66 | get { return _right - _left; }
67 | }
68 |
69 | ///
70 | /// Specifies the height of the rectangle.
71 | ///
72 | public int Height
73 | {
74 | get { return _bottom - _top; }
75 | }
76 |
77 | ///
78 | /// Specifies the position of the rectangle.
79 | ///
80 | public POINT Position
81 | {
82 | get { return new POINT { x = _left, y = _top }; }
83 | }
84 |
85 | ///
86 | /// Specifies the size of the rectangle.
87 | ///
88 | public SIZE Size
89 | {
90 | get { return new SIZE { cx = Width, cy = Height }; }
91 | }
92 |
93 | ///
94 | /// Sets offset of the rectangle.
95 | ///
96 | public void Offset(int dx, int dy)
97 | {
98 | _left += dx;
99 | _top += dy;
100 | _right += dx;
101 | _bottom += dy;
102 | }
103 |
104 | public static RECT Union(RECT rect1, RECT rect2)
105 | {
106 | return new RECT
107 | {
108 | Left = Math.Min(rect1.Left, rect2.Left),
109 | Top = Math.Min(rect1.Top, rect2.Top),
110 | Right = Math.Max(rect1.Right, rect2.Right),
111 | Bottom = Math.Max(rect1.Bottom, rect2.Bottom),
112 | };
113 | }
114 |
115 | public override bool Equals(object obj)
116 | {
117 | try
118 | {
119 | var rc = (RECT)obj;
120 | return rc._bottom == _bottom
121 | && rc._left == _left
122 | && rc._right == _right
123 | && rc._top == _top;
124 | }
125 | catch (InvalidCastException)
126 | {
127 | return false;
128 | }
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/NativeMethods/WinDef/RECTL.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System;
10 | using System.Runtime.InteropServices;
11 |
12 | namespace NativeMethods.WinDef;
13 |
14 | ///
15 | /// The RECTL structure defines a rectangle by the coordinates of its upper-left and lower-right corners.
16 | ///
17 | [StructLayout(LayoutKind.Sequential)]
18 | public struct RECTL
19 | {
20 | private long _left;
21 | private long _top;
22 | private long _right;
23 | private long _bottom;
24 |
25 | ///
26 | /// Specifies the x-coordinate of the upper-left corner of the rectangle.
27 | ///
28 | public long Left
29 | {
30 | get { return _left; }
31 | set { _left = value; }
32 | }
33 |
34 | ///
35 | /// Specifies the x-coordinate of the lower-right corner of the rectangle.
36 | ///
37 | public long Right
38 | {
39 | get { return _right; }
40 | set { _right = value; }
41 | }
42 |
43 | ///
44 | /// Specifies the y-coordinate of the upper-left corner of the rectangle.
45 | ///
46 | public long Top
47 | {
48 | get { return _top; }
49 | set { _top = value; }
50 | }
51 |
52 | ///
53 | /// Specifies the y-coordinate of the lower-right corner of the rectangle.
54 | ///
55 | public long Bottom
56 | {
57 | get { return _bottom; }
58 | set { _bottom = value; }
59 | }
60 |
61 | ///
62 | /// Specifies the width of the rectangle.
63 | ///
64 | public long Width
65 | {
66 | get { return _right - _left; }
67 | }
68 |
69 | ///
70 | /// Specifies the height of the rectangle.
71 | ///
72 | public long Height
73 | {
74 | get { return _bottom - _top; }
75 | }
76 |
77 | ///
78 | /// Specifies the position of the rectangle.
79 | ///
80 | public POINTL Position
81 | {
82 | get { return new POINTL { x = _left, y = _top }; }
83 | }
84 |
85 | ///
86 | /// Specifies the size of the rectangle.
87 | ///
88 | public SIZE Size
89 | {
90 | get { return new SIZE { cx = Width, cy = Height }; }
91 | }
92 |
93 | ///
94 | /// Sets offset of the rectangle.
95 | ///
96 | public void Offset(int dx, int dy)
97 | {
98 | _left += dx;
99 | _top += dy;
100 | _right += dx;
101 | _bottom += dy;
102 | }
103 |
104 | public static RECTL Union(RECTL rect1, RECTL rect2)
105 | {
106 | return new RECTL
107 | {
108 | Left = Math.Min(rect1.Left, rect2.Left),
109 | Top = Math.Min(rect1.Top, rect2.Top),
110 | Right = Math.Max(rect1.Right, rect2.Right),
111 | Bottom = Math.Max(rect1.Bottom, rect2.Bottom),
112 | };
113 | }
114 |
115 | public override bool Equals(object obj)
116 | {
117 | try
118 | {
119 | var rc = (RECTL)obj;
120 | return rc._bottom == _bottom
121 | && rc._left == _left
122 | && rc._right == _right
123 | && rc._top == _top;
124 | }
125 | catch (InvalidCastException)
126 | {
127 | return false;
128 | }
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/NativeMethods/Interop/Shell32.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System;
10 | using System.Runtime.InteropServices;
11 | using System.Runtime.InteropServices.ComTypes;
12 |
13 | namespace NativeMethods.Interop;
14 |
15 | ///
16 | /// The Windows UI provides users with access to a wide variety of objects necessary to run applications and manage the operating system.
17 | ///
18 | // ReSharper disable IdentifierTypo
19 | // ReSharper disable InconsistentNaming
20 | public static class Shell32
21 | {
22 | ///
23 | /// DATAOBJ_GET_ITEM_FLAGS. DOGIF_*.
24 | ///
25 | public enum DOGIF
26 | {
27 | DEFAULT = 0x0000,
28 | TRAVERSE_LINK = 0x0001, // if the item is a link get the target
29 | NO_HDROP = 0x0002, // don't fallback and use CF_HDROP clipboard format
30 | NO_URL = 0x0004, // don't fallback and use URL clipboard format
31 | ONLY_IF_ONE = 0x0008, // only return the item if there is one item in the array
32 | }
33 |
34 | ///
35 | /// Shell_NotifyIcon messages. NIM_*
36 | ///
37 | public enum NIM : uint
38 | {
39 | ADD = 0,
40 | MODIFY = 1,
41 | DELETE = 2,
42 | SETFOCUS = 3,
43 | SETVERSION = 4,
44 | }
45 |
46 | ///
47 | /// Shell_NotifyIcon flags. NIF_*
48 | ///
49 | [Flags]
50 | public enum NIF : uint
51 | {
52 | MESSAGE = 0x0001,
53 | ICON = 0x0002,
54 | TIP = 0x0004,
55 | STATE = 0x0008,
56 | INFO = 0x0010,
57 | GUID = 0x0020,
58 |
59 | ///
60 | /// Vista only.
61 | ///
62 | REALTIME = 0x0040,
63 |
64 | ///
65 | /// Vista only.
66 | ///
67 | SHOWTIP = 0x0080,
68 |
69 | XP_MASK = MESSAGE | ICON | STATE | INFO | GUID,
70 | VISTA_MASK = XP_MASK | REALTIME | SHOWTIP,
71 | }
72 |
73 | [StructLayout(LayoutKind.Sequential)]
74 | public class NOTIFYICONDATA
75 | {
76 | public int cbSize;
77 | public IntPtr hWnd;
78 | public int uID;
79 | public NIF uFlags;
80 | public int uCallbackMessage;
81 | public IntPtr hIcon;
82 |
83 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
84 | public char[] szTip = new char[128];
85 |
86 | ///
87 | /// The state of the icon. There are two flags that can be set independently.
88 | /// NIS_HIDDEN = 1. The icon is hidden.
89 | /// NIS_SHAREDICON = 2. The icon is shared.
90 | ///
91 | public uint dwState;
92 |
93 | public uint dwStateMask;
94 |
95 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
96 | public char[] szInfo = new char[256];
97 |
98 | // Prior to Vista this was a union of uTimeout and uVersion. As of Vista, uTimeout has been deprecated.
99 | public uint uVersion; // Used with Shell_NotifyIcon flag NIM_SETVERSION.
100 |
101 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
102 | public char[] szInfoTitle = new char[64];
103 |
104 | public uint dwInfoFlags;
105 |
106 | public Guid guidItem;
107 |
108 | // Vista only
109 | IntPtr hBalloonIcon;
110 | }
111 |
112 | [DllImport(Libraries.Shell32, PreserveSig = false)]
113 | public static extern void SHGetItemFromDataObject(IDataObject pdtobj, DOGIF dwFlags, [In] ref Guid riid,
114 | [Out, MarshalAs(UnmanagedType.Interface)]
115 | out object ppv);
116 |
117 | [DllImport(Libraries.Shell32)]
118 | public static extern int SHCreateItemFromParsingName([MarshalAs(UnmanagedType.LPWStr)] string pszPath, IBindCtx pbc,
119 | [In] ref Guid riid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppv);
120 |
121 | [DllImport(Libraries.Shell32)]
122 | [return: MarshalAs(UnmanagedType.Bool)]
123 | public static extern bool Shell_NotifyIcon([In] NIM dwMessage, [In] NOTIFYICONDATA lpdata);
124 |
125 | ///
126 | /// Sets the User Model AppID for the current process, enabling Windows to retrieve this ID
127 | ///
128 | ///
129 | [DllImport(Libraries.Shell32, PreserveSig = false)]
130 | public static extern void SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID);
131 |
132 | ///
133 | /// Retrieves the User Model AppID that has been explicitly set for the current process via SetCurrentProcessExplicitAppUserModelID
134 | ///
135 | ///
136 | [DllImport(Libraries.Shell32)]
137 | public static extern int GetCurrentProcessExplicitAppUserModelID(
138 | [Out, MarshalAs(UnmanagedType.LPWStr)] out string AppID);
139 | }
140 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, religion, or sexual identity
10 | and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | * Demonstrating empathy and kindness toward other people
21 | * Being respectful of differing opinions, viewpoints, and experiences
22 | * Giving and gracefully accepting constructive feedback
23 | * Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | * Focusing on what is best not just for us as individuals, but for the
26 | overall community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | * The use of sexualized language or imagery, and sexual attention or
31 | advances of any kind
32 | * Trolling, insulting or derogatory comments, and personal or political attacks
33 | * Public or private harassment
34 | * Publishing others' private information, such as a physical or email
35 | address, without their explicit permission
36 | * Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | support@lepo.co.
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series
86 | of actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or
93 | permanent ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within
113 | the community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.0, available at
119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120 |
121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct
122 | enforcement ladder](https://github.com/mozilla/diversity).
123 |
124 | [homepage]: https://www.contributor-covenant.org
125 |
126 | For answers to common questions about this code of conduct, see the FAQ at
127 | https://www.contributor-covenant.org/faq. Translations are available at
128 | https://www.contributor-covenant.org/translations.
129 |
--------------------------------------------------------------------------------
/src/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | # Default settings:
4 | # A newline ending every file
5 | # Use 4 spaces as indentation
6 | [*]
7 | trim_trailing_whitespace = true
8 | insert_final_newline = true
9 | indent_style = space
10 | indent_size = 4
11 |
12 | [project.json]
13 | indent_size = 2
14 |
15 | # C# files
16 | [*.cs]
17 | # New line preferences
18 | csharp_new_line_before_open_brace = all
19 | csharp_new_line_before_else = true
20 | csharp_new_line_before_catch = true
21 | csharp_new_line_before_finally = true
22 | csharp_new_line_before_members_in_object_initializers = true
23 | csharp_new_line_before_members_in_anonymous_types = true
24 | csharp_new_line_between_query_expression_clauses = true
25 |
26 | # Indentation preferences
27 | csharp_indent_block_contents = true
28 | csharp_indent_braces = false
29 | csharp_indent_case_contents = true
30 | csharp_indent_switch_labels = true
31 | csharp_indent_labels = one_less_than_current
32 |
33 | # avoid this. unless absolutely necessary
34 | dotnet_style_qualification_for_field = false:suggestion
35 | dotnet_style_qualification_for_property = false:suggestion
36 | dotnet_style_qualification_for_method = false:suggestion
37 | dotnet_style_qualification_for_event = false:suggestion
38 |
39 | # only use var when it's obvious what the variable type is
40 | csharp_style_var_for_built_in_types = false:none
41 | csharp_style_var_when_type_is_apparent = false:none
42 | csharp_style_var_elsewhere = false:suggestion
43 |
44 | # use language keywords instead of BCL types
45 | dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
46 | dotnet_style_predefined_type_for_member_access = true:suggestion
47 |
48 | # name all constant fields using PascalCase
49 | dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
50 | dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
51 | dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
52 |
53 | dotnet_naming_symbols.constant_fields.applicable_kinds = field
54 | dotnet_naming_symbols.constant_fields.required_modifiers = const
55 |
56 | dotnet_naming_style.pascal_case_style.capitalization = pascal_case
57 |
58 | # static fields should have s_ prefix
59 | dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
60 | dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
61 | dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
62 |
63 | dotnet_naming_symbols.static_fields.applicable_kinds = field
64 | dotnet_naming_symbols.static_fields.required_modifiers = static
65 |
66 | dotnet_naming_style.static_prefix_style.required_prefix = s_
67 | dotnet_naming_style.static_prefix_style.capitalization = camel_case
68 |
69 | # internal and private fields should be _camelCase
70 | dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
71 | dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
72 | dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
73 |
74 | dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
75 | dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
76 |
77 | dotnet_naming_style.camel_case_underscore_style.required_prefix = _
78 | dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
79 |
80 | # Code style defaults
81 | dotnet_sort_system_directives_first = true
82 | csharp_preserve_single_line_blocks = true
83 | csharp_preserve_single_line_statements = false
84 |
85 | # Expression-level preferences
86 | dotnet_style_object_initializer = true:suggestion
87 | dotnet_style_collection_initializer = true:suggestion
88 | dotnet_style_explicit_tuple_names = true:suggestion
89 | dotnet_style_coalesce_expression = true:suggestion
90 | dotnet_style_null_propagation = true:suggestion
91 |
92 | # Expression-bodied members
93 | csharp_style_expression_bodied_methods = false:none
94 | csharp_style_expression_bodied_constructors = false:none
95 | csharp_style_expression_bodied_operators = false:none
96 | csharp_style_expression_bodied_properties = true:none
97 | csharp_style_expression_bodied_indexers = true:none
98 | csharp_style_expression_bodied_accessors = true:none
99 |
100 | # Pattern matching
101 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
102 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
103 | csharp_style_inlined_variable_declaration = true:suggestion
104 |
105 | # Null checking preferences
106 | csharp_style_throw_expression = true:suggestion
107 | csharp_style_conditional_delegate_call = true:suggestion
108 |
109 | # Space preferences
110 | csharp_space_after_cast = false
111 | csharp_space_after_colon_in_inheritance_clause = true
112 | csharp_space_after_comma = true
113 | csharp_space_after_dot = false
114 | csharp_space_after_keywords_in_control_flow_statements = true
115 | csharp_space_after_semicolon_in_for_statement = true
116 | csharp_space_around_binary_operators = before_and_after
117 | csharp_space_around_declaration_statements = do_not_ignore
118 | csharp_space_before_colon_in_inheritance_clause = true
119 | csharp_space_before_comma = false
120 | csharp_space_before_dot = false
121 | csharp_space_before_open_square_brackets = false
122 | csharp_space_before_semicolon_in_for_statement = false
123 | csharp_space_between_empty_square_brackets = false
124 | csharp_space_between_method_call_empty_parameter_list_parentheses = false
125 | csharp_space_between_method_call_name_and_opening_parenthesis = false
126 | csharp_space_between_method_call_parameter_list_parentheses = false
127 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
128 | csharp_space_between_method_declaration_name_and_open_parenthesis = false
129 | csharp_space_between_method_declaration_parameter_list_parentheses = false
130 | csharp_space_between_parentheses = false
131 | csharp_space_between_square_brackets = false
132 |
133 | # C++ Files
134 | [*.{cpp,h,in}]
135 | curly_bracket_next_line = true
136 | indent_brace_style = Allman
137 |
138 | # Visual Studio Solution files
139 | [*.sln]
140 | end_of_line = lf
141 |
142 | # Xml project files
143 | [*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
144 | indent_size = 2
145 |
146 | # Xml build files
147 | [*.builds]
148 | indent_size = 2
149 |
150 | # Xml files
151 | [*.{xml,stylecop,resx,ruleset}]
152 | indent_size = 2
153 |
154 | # Xml config files
155 | [*.{props,targets,config,nuspec}]
156 | indent_size = 2
157 |
158 | # Shell scripts
159 | [*.sh]
160 | end_of_line = lf
161 | [*.{cmd, bat}]
162 | end_of_line = crlf
163 |
--------------------------------------------------------------------------------
/src/NativeMethods/Interop/UxTheme.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System;
10 | using System.Runtime.InteropServices;
11 | using System.Text;
12 |
13 | namespace NativeMethods.Interop;
14 |
15 | // ReSharper disable IdentifierTypo
16 | // ReSharper disable InconsistentNaming
17 | public static class UxTheme
18 | {
19 | ///
20 | /// Returned by the GetThemeMargins function to define the margins of windows that have visual styles applied.
21 | ///
22 | public struct MARGINS
23 | {
24 | ///
25 | /// Width of left border that retains its size.
26 | ///
27 | public int cxLeftWidth;
28 |
29 | ///
30 | /// Width of right border that retains its size.
31 | ///
32 | public int cxRightWidth;
33 |
34 | ///
35 | /// Height of top border that retains its size.
36 | ///
37 | public int cyTopHeight;
38 |
39 | ///
40 | /// Height of bottom border that retains its size.
41 | ///
42 | public int cyBottomHeight;
43 | }
44 |
45 | ///
46 | /// Specifies the type of visual style attribute to set on a window.
47 | ///
48 | public enum WINDOWTHEMEATTRIBUTETYPE : uint
49 | {
50 | ///
51 | /// Non-client area window attributes will be set.
52 | ///
53 | WTA_NONCLIENT = 1,
54 | }
55 |
56 | ///
57 | /// WindowThemeNonClientAttributes
58 | ///
59 | [Flags]
60 | public enum WTNCA : uint
61 | {
62 | ///
63 | /// Prevents the window caption from being drawn.
64 | ///
65 | NODRAWCAPTION = 0x00000001,
66 |
67 | ///
68 | /// Prevents the system icon from being drawn.
69 | ///
70 | NODRAWICON = 0x00000002,
71 |
72 | ///
73 | /// Prevents the system icon menu from appearing.
74 | ///
75 | NOSYSMENU = 0x00000004,
76 |
77 | ///
78 | /// Prevents mirroring of the question mark, even in right-to-left (RTL) layout.
79 | ///
80 | NOMIRRORHELP = 0x00000008,
81 |
82 | ///
83 | /// A mask that contains all the valid bits.
84 | ///
85 | VALIDBITS = NODRAWCAPTION | NODRAWICON | NOMIRRORHELP | NOSYSMENU,
86 | }
87 |
88 | ///
89 | /// Defines options that are used to set window visual style attributes.
90 | ///
91 | [StructLayout(LayoutKind.Explicit)]
92 | public struct WTA_OPTIONS
93 | {
94 | // public static readonly uint Size = (uint)Marshal.SizeOf(typeof(WTA_OPTIONS));
95 | public const uint Size = 8;
96 |
97 | ///
98 | /// A combination of flags that modify window visual style attributes.
99 | /// Can be a combination of the WTNCA constants.
100 | ///
101 | [FieldOffset(0)]
102 | public WTNCA dwFlags;
103 |
104 | ///
105 | /// A bitmask that describes how the values specified in dwFlags should be applied.
106 | /// If the bit corresponding to a value in dwFlags is 0, that flag will be removed.
107 | /// If the bit is 1, the flag will be added.
108 | ///
109 | [FieldOffset(4)]
110 | public WTNCA dwMask;
111 | }
112 |
113 | ///
114 | /// Sets attributes to control how visual styles are applied to a specified window.
115 | ///
116 | ///
117 | /// Handle to a window to apply changes to.
118 | ///
119 | ///
120 | /// Value of type WINDOWTHEMEATTRIBUTETYPE that specifies the type of attribute to set.
121 | /// The value of this parameter determines the type of data that should be passed in the pvAttribute parameter.
122 | /// Can be the following value:
123 | /// WTA_NONCLIENT (Specifies non-client related attributes).
124 | /// pvAttribute must be a pointer of type WTA_OPTIONS.
125 | ///
126 | ///
127 | /// A pointer that specifies attributes to set. Type is determined by the value of the eAttribute value.
128 | ///
129 | ///
130 | /// Specifies the size, in bytes, of the data pointed to by pvAttribute.
131 | ///
132 | [DllImport(Libraries.UxTheme, PreserveSig = false)]
133 | public static extern void SetWindowThemeAttribute([In] IntPtr hWnd, [In] WINDOWTHEMEATTRIBUTETYPE eAttribute, [In] ref WTA_OPTIONS pvAttribute, [In] uint cbAttribute);
134 |
135 | ///
136 | /// Tests if a visual style for the current application is active.
137 | ///
138 | /// if a visual style is enabled, and windows with visual styles applied should call OpenThemeData to start using theme drawing services.
139 | [DllImport(Libraries.UxTheme)]
140 | [return: MarshalAs(UnmanagedType.Bool)]
141 | public static extern bool IsThemeActive();
142 |
143 | ///
144 | /// Retrieves the name of the current visual style, and optionally retrieves the color scheme name and size name.
145 | ///
146 | /// Pointer to a string that receives the theme path and file name.
147 | /// Value of type int that contains the maximum number of characters allowed in the theme file name.
148 | /// Pointer to a string that receives the color scheme name. This parameter may be set to NULL.
149 | /// Value of type int that contains the maximum number of characters allowed in the color scheme name.
150 | /// Pointer to a string that receives the size name. This parameter may be set to NULL.
151 | /// Value of type int that contains the maximum number of characters allowed in the size name.
152 | /// HRESULT
153 | [DllImport(Libraries.UxTheme, CharSet = CharSet.Unicode)]
154 | private static extern int GetCurrentThemeName(
155 | [Out] StringBuilder pszThemeFileName,
156 | [In] int dwMaxNameChars,
157 | [Out] StringBuilder pszColorBuff,
158 | [In] int cchMaxColorChars,
159 | [Out] StringBuilder pszSizeBuff,
160 | [In] int cchMaxSizeChars);
161 | }
162 |
163 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
4 |
5 | # User-specific files
6 | *.rsuser
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Mono auto generated files
16 | mono_crash.*
17 |
18 | # Build results
19 | [Dd]ebug/
20 | [Dd]ebugPublic/
21 | [Rr]elease/
22 | [Rr]eleases/
23 | x64/
24 | x86/
25 | [Aa][Rr][Mm]/
26 | [Aa][Rr][Mm]64/
27 | bld/
28 | [Bb]in/
29 | [Oo]bj/
30 | [Ll]og/
31 | [Ll]ogs/
32 |
33 | # Visual Studio 2015/2017 cache/options directory
34 | .vs/
35 | # Uncomment if you have tasks that create the project's static files in wwwroot
36 | #wwwroot/
37 |
38 | # Visual Studio 2017 auto generated files
39 | Generated\ Files/
40 |
41 | # MSTest test Results
42 | [Tt]est[Rr]esult*/
43 | [Bb]uild[Ll]og.*
44 |
45 | # NUnit
46 | *.VisualState.xml
47 | TestResult.xml
48 | nunit-*.xml
49 |
50 | # Build Results of an ATL Project
51 | [Dd]ebugPS/
52 | [Rr]eleasePS/
53 | dlldata.c
54 |
55 | # Benchmark Results
56 | BenchmarkDotNet.Artifacts/
57 |
58 | # .NET Core
59 | project.lock.json
60 | project.fragment.lock.json
61 | artifacts/
62 |
63 | # StyleCop
64 | StyleCopReport.xml
65 |
66 | # Files built by Visual Studio
67 | *_i.c
68 | *_p.c
69 | *_h.h
70 | *.ilk
71 | *.meta
72 | *.obj
73 | *.iobj
74 | *.pch
75 | *.pdb
76 | *.ipdb
77 | *.pgc
78 | *.pgd
79 | *.rsp
80 | *.sbr
81 | *.tlb
82 | *.tli
83 | *.tlh
84 | *.tmp
85 | *.tmp_proj
86 | *_wpftmp.csproj
87 | *.log
88 | *.vspscc
89 | *.vssscc
90 | .builds
91 | *.pidb
92 | *.svclog
93 | *.scc
94 |
95 | # Chutzpah Test files
96 | _Chutzpah*
97 |
98 | # Visual C++ cache files
99 | ipch/
100 | *.aps
101 | *.ncb
102 | *.opendb
103 | *.opensdf
104 | *.sdf
105 | *.cachefile
106 | *.VC.db
107 | *.VC.VC.opendb
108 |
109 | # Visual Studio profiler
110 | *.psess
111 | *.vsp
112 | *.vspx
113 | *.sap
114 |
115 | # Visual Studio Trace Files
116 | *.e2e
117 |
118 | # TFS 2012 Local Workspace
119 | $tf/
120 |
121 | # Guidance Automation Toolkit
122 | *.gpState
123 |
124 | # ReSharper is a .NET coding add-in
125 | _ReSharper*/
126 | *.[Rr]e[Ss]harper
127 | *.DotSettings.user
128 |
129 | # TeamCity is a build add-in
130 | _TeamCity*
131 |
132 | # DotCover is a Code Coverage Tool
133 | *.dotCover
134 |
135 | # AxoCover is a Code Coverage Tool
136 | .axoCover/*
137 | !.axoCover/settings.json
138 |
139 | # Visual Studio code coverage results
140 | *.coverage
141 | *.coveragexml
142 |
143 | # NCrunch
144 | _NCrunch_*
145 | .*crunch*.local.xml
146 | nCrunchTemp_*
147 |
148 | # MightyMoose
149 | *.mm.*
150 | AutoTest.Net/
151 |
152 | # Web workbench (sass)
153 | .sass-cache/
154 |
155 | # Installshield output folder
156 | [Ee]xpress/
157 |
158 | # DocProject is a documentation generator add-in
159 | DocProject/buildhelp/
160 | DocProject/Help/*.HxT
161 | DocProject/Help/*.HxC
162 | DocProject/Help/*.hhc
163 | DocProject/Help/*.hhk
164 | DocProject/Help/*.hhp
165 | DocProject/Help/Html2
166 | DocProject/Help/html
167 |
168 | # Click-Once directory
169 | publish/
170 |
171 | # Publish Web Output
172 | *.[Pp]ublish.xml
173 | *.azurePubxml
174 | # Note: Comment the next line if you want to checkin your web deploy settings,
175 | # but database connection strings (with potential passwords) will be unencrypted
176 | *.pubxml
177 | *.publishproj
178 |
179 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
180 | # checkin your Azure Web App publish settings, but sensitive information contained
181 | # in these scripts will be unencrypted
182 | PublishScripts/
183 |
184 | # NuGet Packages
185 | *.nupkg
186 | # NuGet Symbol Packages
187 | *.snupkg
188 | # The packages folder can be ignored because of Package Restore
189 | **/[Pp]ackages/*
190 | # except build/, which is used as an MSBuild target.
191 | !**/[Pp]ackages/build/
192 | # Uncomment if necessary however generally it will be regenerated when needed
193 | #!**/[Pp]ackages/repositories.config
194 | # NuGet v3's project.json files produces more ignorable files
195 | *.nuget.props
196 | *.nuget.targets
197 |
198 | # Microsoft Azure Build Output
199 | csx/
200 | *.build.csdef
201 |
202 | # Microsoft Azure Emulator
203 | ecf/
204 | rcf/
205 |
206 | # Windows Store app package directories and files
207 | AppPackages/
208 | BundleArtifacts/
209 | Package.StoreAssociation.xml
210 | _pkginfo.txt
211 | *.appx
212 | *.appxbundle
213 | *.appxupload
214 |
215 | # Visual Studio cache files
216 | # files ending in .cache can be ignored
217 | *.[Cc]ache
218 | # but keep track of directories ending in .cache
219 | !?*.[Cc]ache/
220 |
221 | # Others
222 | ClientBin/
223 | ~$*
224 | *~
225 | *.dbmdl
226 | *.dbproj.schemaview
227 | *.jfm
228 | *.pfx
229 | *.publishsettings
230 | orleans.codegen.cs
231 |
232 | # Including strong name files can present a security risk
233 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
234 | #*.snk
235 |
236 | # Since there are multiple workflows, uncomment next line to ignore bower_components
237 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
238 | #bower_components/
239 |
240 | # RIA/Silverlight projects
241 | Generated_Code/
242 |
243 | # Backup & report files from converting an old project file
244 | # to a newer Visual Studio version. Backup files are not needed,
245 | # because we have git ;-)
246 | _UpgradeReport_Files/
247 | Backup*/
248 | UpgradeLog*.XML
249 | UpgradeLog*.htm
250 | ServiceFabricBackup/
251 | *.rptproj.bak
252 |
253 | # SQL Server files
254 | *.mdf
255 | *.ldf
256 | *.ndf
257 |
258 | # Business Intelligence projects
259 | *.rdl.data
260 | *.bim.layout
261 | *.bim_*.settings
262 | *.rptproj.rsuser
263 | *- [Bb]ackup.rdl
264 | *- [Bb]ackup ([0-9]).rdl
265 | *- [Bb]ackup ([0-9][0-9]).rdl
266 |
267 | # Microsoft Fakes
268 | FakesAssemblies/
269 |
270 | # GhostDoc plugin setting file
271 | *.GhostDoc.xml
272 |
273 | # Node.js Tools for Visual Studio
274 | .ntvs_analysis.dat
275 | node_modules/
276 |
277 | # Visual Studio 6 build log
278 | *.plg
279 |
280 | # Visual Studio 6 workspace options file
281 | *.opt
282 |
283 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
284 | *.vbw
285 |
286 | # Visual Studio LightSwitch build output
287 | **/*.HTMLClient/GeneratedArtifacts
288 | **/*.DesktopClient/GeneratedArtifacts
289 | **/*.DesktopClient/ModelManifest.xml
290 | **/*.Server/GeneratedArtifacts
291 | **/*.Server/ModelManifest.xml
292 | _Pvt_Extensions
293 |
294 | # Paket dependency manager
295 | .paket/paket.exe
296 | paket-files/
297 |
298 | # FAKE - F# Make
299 | .fake/
300 |
301 | # CodeRush personal settings
302 | .cr/personal
303 |
304 | # Python Tools for Visual Studio (PTVS)
305 | __pycache__/
306 | *.pyc
307 |
308 | # Cake - Uncomment if you are using it
309 | # tools/**
310 | # !tools/packages.config
311 |
312 | # Tabs Studio
313 | *.tss
314 |
315 | # Telerik's JustMock configuration file
316 | *.jmconfig
317 |
318 | # BizTalk build output
319 | *.btp.cs
320 | *.btm.cs
321 | *.odx.cs
322 | *.xsd.cs
323 |
324 | # OpenCover UI analysis results
325 | OpenCover/
326 |
327 | # Azure Stream Analytics local run output
328 | ASALocalRun/
329 |
330 | # MSBuild Binary and Structured Log
331 | *.binlog
332 |
333 | # NVidia Nsight GPU debugger configuration file
334 | *.nvuser
335 |
336 | # MFractors (Xamarin productivity tool) working folder
337 | .mfractor/
338 |
339 | # Local History for Visual Studio
340 | .localhistory/
341 |
342 | # BeatPulse healthcheck temp database
343 | healthchecksdb
344 |
345 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
346 | MigrationBackup/
347 |
348 | # Ionide (cross platform F# VS Code tools) working folder
349 | .ionide/
350 |
--------------------------------------------------------------------------------
/src/NativeMethods/Interop/Kernel32.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System;
10 | using System.Runtime.InteropServices;
11 | using NativeMethods.Attributes;
12 |
13 | namespace NativeMethods.Interop;
14 |
15 | ///
16 | /// Used by multiple technologies.
17 | ///
18 | // ReSharper disable IdentifierTypo
19 | // ReSharper disable InconsistentNaming
20 | #pragma warning disable CA1401 // P/Invokes should not be visible
21 | [UnmanagedComponent]
22 | public static class Kernel32
23 | {
24 | ///
25 | /// Copies a block of memory from one location to another.
26 | ///
27 | /// A pointer to the starting address of the copied block's destination.
28 | /// A pointer to the starting address of the block of memory to copy.
29 | /// The size of the block of memory to copy, in bytes.
30 | [DllImport(Libraries.Kernel32, SetLastError = false, CharSet = CharSet.Auto)]
31 | public static extern void CopyMemory([In] IntPtr destination, [In] IntPtr source, [In] uint length);
32 |
33 | ///
34 | /// Retrieves the calling thread's last-error code value. The last-error code is maintained on a per-thread basis. Multiple threads do not overwrite each other's last-error code.
35 | ///
36 | /// The return value is the calling thread's last-error code.
37 | [DllImport(Libraries.Kernel32)]
38 | public static extern int GetLastError();
39 |
40 | ///
41 | /// Sets the last-error code for the calling thread.
42 | ///
43 | /// The last-error code for the thread.
44 | [DllImport(Libraries.Kernel32, ExactSpelling = true, CharSet = CharSet.Auto)]
45 | public static extern void SetLastError([In] int dwErrorCode);
46 |
47 | ///
48 | /// Closes a file search handle opened by the FindFirstFile, FindFirstFileEx, FindFirstFileNameW, FindFirstFileNameTransactedW, FindFirstFileTransacted, FindFirstStreamTransactedW, or FindFirstStreamW functions.
49 | ///
50 | /// The file search handle.
51 | /// If the function succeeds, the return value is nonzero.
52 | [DllImport(Libraries.Kernel32)]
53 |
54 | [return: MarshalAs(UnmanagedType.Bool)]
55 | public static extern bool FindClose([In, Out] IntPtr hFindFile);
56 |
57 | ///
58 | /// Frees the specified global memory object and invalidates its handle.
59 | ///
60 | /// A handle to the global memory object. This handle is returned by either the GlobalAlloc or GlobalReAlloc function. It is not safe to free memory allocated with LocalAlloc.
61 | /// If the function succeeds, the return value is NULL.
62 | [DllImport(Libraries.Kernel32)]
63 |
64 | public static extern IntPtr GlobalFree(IntPtr hMem);
65 |
66 | ///
67 | /// Frees the specified local memory object and invalidates its handle.
68 | ///
69 | /// A handle to the local memory object. This handle is returned by either the LocalAlloc or LocalReAlloc function. It is not safe to free memory allocated with GlobalAlloc.
70 | /// If the function succeeds, the return value is NULL.
71 | [DllImport(Libraries.Kernel32)]
72 | public static extern IntPtr LocalFree([In] IntPtr hMem);
73 |
74 | ///
75 | /// Locks a global memory object and returns a pointer to the first byte of the object's memory block.
76 | ///
77 | /// A handle to the global memory object. This handle is returned by either the GlobalAlloc or GlobalReAlloc function.
78 | /// If the function succeeds, the return value is a pointer to the first byte of the memory block.
79 | [DllImport(Libraries.Kernel32)]
80 | public static extern IntPtr GlobalLock([In] IntPtr hMem);
81 |
82 | ///
83 | /// Decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE. This function has no effect on memory objects allocated with GMEM_FIXED.
84 | ///
85 | /// A handle to the global memory object. This handle is returned by either the GlobalAlloc or GlobalReAlloc function.
86 | /// If the memory object is still locked after decrementing the lock count, the return value is a nonzero value. If the memory object is unlocked after decrementing the lock count, the function returns zero and GetLastError returns NO_ERROR.
87 | [DllImport(Libraries.Kernel32)]
88 | public static extern bool GlobalUnlock([In] IntPtr hMem);
89 |
90 | ///
91 | /// Closes an open object handle.
92 | ///
93 | /// A valid handle to an open object.
94 | /// If the function succeeds, the return value is nonzero.
95 | [DllImport(Libraries.Kernel32, SetLastError = true)]
96 | [return: MarshalAs(UnmanagedType.Bool)]
97 | public static extern bool CloseHandle(IntPtr hObject);
98 |
99 | ///
100 | /// Frees the loaded dynamic-link library (DLL) module and, if necessary, decrements its reference count. When the reference count reaches zero, the module is unloaded from the address space of the calling process and the handle is no longer valid.
101 | ///
102 | /// A handle to the loaded library module. The LoadLibrary, LoadLibraryEx, GetModuleHandle, or GetModuleHandleEx function returns this handle.
103 | /// If the function succeeds, the return value is nonzero.
104 | [DllImport(Libraries.Kernel32, SetLastError = true)]
105 | [return: MarshalAs(UnmanagedType.Bool)]
106 | public static extern bool FreeLibrary([In] IntPtr hLibModule);
107 |
108 | ///
109 | /// Retrieves the address of an exported function or variable from the specified dynamic-link library (DLL).
110 | ///
111 | /// A handle to the DLL module that contains the function or variable. The LoadLibrary, LoadLibraryEx, LoadPackagedLibrary, or GetModuleHandle function returns this handle.
112 | /// The function or variable name, or the function's ordinal value. If this parameter is an ordinal value, it must be in the low-order word; the high-order word must be zero.
113 | /// If the function succeeds, the return value is the address of the exported function or variable.
114 | [DllImport(Libraries.Kernel32, SetLastError = true)]
115 | public static extern IntPtr GetProcAddress([In] IntPtr hModule, [In][MarshalAs(UnmanagedType.LPStr)] string lpProcName);
116 |
117 | ///
118 | /// Opens an existing local process object.
119 | ///
120 | /// The access to the process object. This access right is checked against the security descriptor for the process. This parameter can be one or more of the process access rights.
121 | /// If this value is TRUE, processes created by this process will inherit the handle. Otherwise, the processes do not inherit this handle.
122 | /// The identifier of the local process to be opened.
123 | /// If the function succeeds, the return value is an open handle to the specified process.
124 | [DllImport(Libraries.Kernel32, SetLastError = true)]
125 | public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, uint dwProcessId);
126 |
127 | ///
128 | /// Retrieves the process identifier of the calling process.
129 | ///
130 | /// The return value is the process identifier of the calling process.
131 | [DllImport(Libraries.Kernel32, ExactSpelling = true, CharSet = CharSet.Auto)]
132 | public static extern int GetCurrentProcessId();
133 |
134 | ///
135 | /// Retrieves the Remote Desktop Services session associated with a specified process.
136 | ///
137 | /// Specifies a process identifier. Use the GetCurrentProcessId function to retrieve the process identifier for the current process.
138 | /// Pointer to a variable that receives the identifier of the Remote Desktop Services session under which the specified process is running.
139 | /// If the function succeeds, the return value is a nonzero value.
140 | [DllImport(Libraries.Kernel32, ExactSpelling = true, CharSet = CharSet.Auto)]
141 | [return: MarshalAs(UnmanagedType.Bool)]
142 | public static extern bool ProcessIdToSessionId([In] int dwProcessId, [Out] out int pSessionId);
143 |
144 | ///
145 | /// Loads the specified module into the address space of the calling process. The specified module may cause other modules to be loaded.
146 | ///
147 | /// A string that specifies the file name of the module to load. This name is not related to the name stored in a library module itself, as specified by the LIBRARY keyword in the module-definition (.def) file.
148 | /// This parameter is reserved for future use. It must be NULL.
149 | /// The action to be taken when loading the module. If no flags are specified, the behavior of this function is identical to that of the LoadLibrary function.
150 | /// If the function succeeds, the return value is a handle to the loaded module.
151 | [DllImport(Libraries.Kernel32, SetLastError = true)]
152 | public static extern IntPtr LoadLibraryExW([In][MarshalAs(UnmanagedType.LPWStr)] string lpLibFileName, IntPtr hFile, [In] uint dwFlags);
153 |
154 | ///
155 | /// Formats a message string. The function requires a message definition as input. The message definition can come from a buffer passed into the function.
156 | ///
157 | /// The formatting options, and how to interpret the lpSource parameter. The low-order byte of dwFlags specifies how the function handles line breaks in the output buffer. The low-order byte can also specify the maximum width of a formatted output line.
158 | /// The location of the message definition.
159 | /// The message identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
160 | /// The language identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
161 | /// A pointer to a buffer that receives the null-terminated string that specifies the formatted message. If dwFlags includes FORMAT_MESSAGE_ALLOCATE_BUFFER, the function allocates a buffer using the LocalAlloc function, and places the pointer to the buffer at the address specified in lpBuffer.
162 | /// If the FORMAT_MESSAGE_ALLOCATE_BUFFER flag is not set, this parameter specifies the size of the output buffer, in TCHARs. If FORMAT_MESSAGE_ALLOCATE_BUFFER is set, this parameter specifies the minimum number of TCHARs to allocate for an output buffer.
163 | /// An array of values that are used as insert values in the formatted message. A %1 in the format string indicates the first value in the Arguments array; a %2 indicates the second argument; and so on.
164 | /// If the function succeeds, the return value is the number of TCHARs stored in the output buffer, excluding the terminating null character.
165 | [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.Winapi)]
166 | public extern static int FormatMessageW([In] int dwFlags, [In, Optional] IntPtr lpSource, [In] int dwMessageId, [In] int dwLanguageId, [Out] System.Text.StringBuilder lpBuffer, [In] int nSize, [In, Optional] IntPtr arguments);
167 |
168 | ///
169 | /// Retrieves the thread identifier of the calling thread.
170 | ///
171 | /// The return value is the thread identifier of the calling thread.
172 | [DllImport(Libraries.Kernel32, ExactSpelling = true, CharSet = CharSet.Auto)]
173 | public static extern int GetCurrentThreadId();
174 |
175 | ///
176 | /// Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days.
177 | ///
178 | /// The return value is the number of milliseconds that have elapsed since the system was started.
179 | [DllImport(Libraries.Kernel32, ExactSpelling = true, CharSet = CharSet.Auto)]
180 | public static extern int GetTickCount();
181 |
182 | ///
183 | /// Retrieves the number of milliseconds that have elapsed since the system was started.
184 | ///
185 | /// The number of milliseconds.
186 | [DllImport(Libraries.Kernel32, ExactSpelling = true, CharSet = CharSet.Auto)]
187 | public static extern ulong GetTickCount64();
188 |
189 | ///
190 | /// Determines whether the calling process is being debugged by a user-mode debugger.
191 | ///
192 | /// If the current process is running in the context of a debugger, the return value is nonzero.
193 | [DllImport(Libraries.Kernel32, ExactSpelling = true, CharSet = CharSet.Auto)]
194 | [return: MarshalAs(UnmanagedType.Bool)]
195 | public static extern bool IsDebuggerPresent();
196 |
197 | ///
198 | /// Retrieves the current value of the performance counter, which is a high resolution (<1us) time stamp that can be used for time-interval measurements.
199 | ///
200 | /// A pointer to a variable that receives the current performance-counter value, in counts.
201 | /// If the function succeeds, the return value is nonzero.
202 | [DllImport(Libraries.Kernel32, SetLastError = true)]
203 | [return: MarshalAs(UnmanagedType.Bool)]
204 | public static extern bool QueryPerformanceCounter([Out] out long lpPerformanceCount);
205 |
206 | ///
207 | /// Retrieves the frequency of the performance counter. The frequency of the performance counter is fixed at system boot and is consistent across all processors. Therefore, the frequency need only be queried upon application initialization, and the result can be cached.
208 | ///
209 | /// A pointer to a variable that receives the current performance-counter frequency, in counts per second. If the installed hardware doesn't support a high-resolution performance counter, this parameter can be zero (this will not occur on systems that run Windows XP or later).
210 | /// If the installed hardware supports a high-resolution performance counter, the return value is nonzero.
211 | [DllImport(Libraries.Kernel32, SetLastError = true)]
212 | [return: MarshalAs(UnmanagedType.Bool)]
213 | public static extern bool QueryPerformanceFrequency(out long lpFrequency);
214 |
215 | ///
216 | /// Adds a character string to the global atom table and returns a unique value (an atom) identifying the string.
217 | ///
218 | /// The null-terminated string to be added. The string can have a maximum size of 255 bytes. Strings that differ only in case are considered identical.
219 | /// If the function succeeds, the return value is the newly created atom.
220 | [DllImport(Libraries.Kernel32, CharSet = CharSet.Auto, SetLastError = true)]
221 | public static extern short GlobalAddAtom(string lpString);
222 |
223 | [DllImport(Libraries.Kernel32, SetLastError = true)]
224 | public static extern IntPtr VirtualAlloc(IntPtr address, UIntPtr size, int allocationType, int protect);
225 |
226 | [DllImport(Libraries.Kernel32, SetLastError = true)]
227 | public static extern bool VirtualFree(IntPtr address, UIntPtr size, int freeType);
228 |
229 | ///
230 | /// Determines the length of the specified string (not including the terminating null character).
231 | ///
232 | /// The null-terminated string to be checked.
233 | /// The function returns the length of the string, in characters. If lpString is NULL, the function returns 0.
234 | [DllImport(Libraries.Kernel32, CharSet = CharSet.Auto, BestFitMapping = false)]
235 | public static extern int lstrlen(String lpString);
236 | }
237 | #pragma warning restore CA1401 // P/Invokes should not be visible
238 |
--------------------------------------------------------------------------------
/src/NativeMethods/Interop/Dwmapi.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System;
10 | using System.Runtime.InteropServices;
11 | using NativeMethods.Attributes;
12 | using NativeMethods.WinDef;
13 |
14 | // Windows Kits\10\Include\10.0.22000.0\um\dwmapi.h
15 |
16 | namespace NativeMethods.Interop;
17 |
18 | ///
19 | /// Desktop Window Manager (DWM).
20 | ///
21 | // ReSharper disable IdentifierTypo
22 | // ReSharper disable InconsistentNaming
23 | [UnmanagedComponent]
24 | public static class Dwmapi
25 | {
26 | ///
27 | /// Flags used by the DwmSetWindowAttribute function to specify the rounded corner preference for a window.
28 | ///
29 | [Flags]
30 | public enum DWM_WINDOW_CORNER_PREFERENCE
31 | {
32 | DEFAULT = 0,
33 | DONOTROUND = 1,
34 | ROUND = 2,
35 | ROUNDSMALL = 3
36 | }
37 |
38 | ///
39 | /// Backdrop types.
40 | ///
41 | [Flags]
42 | public enum DWMSBT : uint
43 | {
44 | ///
45 | /// Automatically selects backdrop effect.
46 | ///
47 | DWMSBT_AUTO = 0,
48 |
49 | ///
50 | /// Turns off the backdrop effect.
51 | ///
52 | DWMSBT_DISABLE = 1,
53 |
54 | ///
55 | /// Sets Mica effect with generated wallpaper tint.
56 | ///
57 | DWMSBT_MAINWINDOW = 2,
58 |
59 | ///
60 | /// Sets acrlic effect.
61 | ///
62 | DWMSBT_TRANSIENTWINDOW = 3,
63 |
64 | ///
65 | /// Sets blurred wallpaper effect, like Mica without tint.
66 | ///
67 | DWMSBT_TABBEDWINDOW = 4
68 | }
69 |
70 | ///
71 | /// Non-client rendering policy attribute values
72 | ///
73 | public enum DWMNCRENDERINGPOLICY
74 | {
75 | ///
76 | /// Enable/disable non-client rendering based on window style
77 | ///
78 | DWMNCRP_USEWINDOWSTYLE,
79 |
80 | ///
81 | /// Disabled non-client rendering; window style is ignored
82 | ///
83 | DWMNCRP_DISABLED,
84 |
85 | ///
86 | /// Enabled non-client rendering; window style is ignored
87 | ///
88 | DWMNCRP_ENABLED,
89 |
90 | ///
91 | /// Sentinel value.
92 | ///
93 | DWMNCRP_LAST
94 | }
95 |
96 | ///
97 | /// Values designating how Flip3D treats a given window.
98 | ///
99 | public enum DWMFLIP3DWINDOWPOLICY
100 | {
101 | ///
102 | /// Hide or include the window in Flip3D based on window style and visibility.
103 | ///
104 | DWMFLIP3D_DEFAULT,
105 |
106 | ///
107 | /// Display the window under Flip3D and disabled.
108 | ///
109 | DWMFLIP3D_EXCLUDEBELOW,
110 |
111 | ///
112 | /// Display the window above Flip3D and enabled.
113 | ///
114 | DWMFLIP3D_EXCLUDEABOVE,
115 |
116 | ///
117 | /// Sentinel value.
118 | ///
119 | DWMFLIP3D_LAST
120 | }
121 |
122 | ///
123 | /// Options used by the DwmGetWindowAttribute and DwmSetWindowAttribute functions.
124 | ///
125 | ///
126 | [Flags]
127 | public enum DWMWINDOWATTRIBUTE
128 | {
129 | ///
130 | /// Is non-client rendering enabled/disabled
131 | ///
132 | DWMWA_NCRENDERING_ENABLED = 1,
133 |
134 | ///
135 | /// DWMNCRENDERINGPOLICY - Non-client rendering policy
136 | ///
137 | DWMWA_NCRENDERING_POLICY = 2,
138 |
139 | ///
140 | /// Potentially enable/forcibly disable transitions
141 | ///
142 | DWMWA_TRANSITIONS_FORCEDISABLED = 3,
143 |
144 | ///
145 | /// Enables content rendered in the non-client area to be visible on the frame drawn by DWM.
146 | ///
147 | DWMWA_ALLOW_NCPAINT = 4,
148 |
149 | ///
150 | /// Retrieves the bounds of the caption button area in the window-relative space.
151 | ///
152 | DWMWA_CAPTION_BUTTON_BOUNDS = 5,
153 |
154 | ///
155 | /// Is non-client content RTL mirrored
156 | ///
157 | DWMWA_NONCLIENT_RTL_LAYOUT = 6,
158 |
159 | ///
160 | /// Forces the window to display an iconic thumbnail or peek representation (a static bitmap), even if a live or snapshot representation of the window is available.
161 | ///
162 | DWMWA_FORCE_ICONIC_REPRESENTATION = 7,
163 |
164 | ///
165 | /// Designates how Flip3D will treat the window.
166 | ///
167 | DWMWA_FLIP3D_POLICY = 8,
168 |
169 | ///
170 | /// Gets the extended frame bounds rectangle in screen space
171 | ///
172 | DWMWA_EXTENDED_FRAME_BOUNDS = 9,
173 |
174 | ///
175 | /// Indicates an available bitmap when there is no better thumbnail representation.
176 | ///
177 | DWMWA_HAS_ICONIC_BITMAP = 10,
178 |
179 | ///
180 | /// Don't invoke Peek on the window.
181 | ///
182 | DWMWA_DISALLOW_PEEK = 11,
183 |
184 | ///
185 | /// LivePreview exclusion information
186 | ///
187 | DWMWA_EXCLUDED_FROM_PEEK = 12,
188 |
189 | ///
190 | /// Cloaks the window such that it is not visible to the user.
191 | ///
192 | DWMWA_CLOAK = 13,
193 |
194 | ///
195 | /// If the window is cloaked, provides one of the following values explaining why.
196 | ///
197 | DWMWA_CLOAKED = 14,
198 |
199 | ///
200 | /// Freeze the window's thumbnail image with its current visuals. Do no further live updates on the thumbnail image to match the window's contents.
201 | ///
202 | DWMWA_FREEZE_REPRESENTATION = 15,
203 |
204 | ///
205 | /// BOOL, Updates the window only when desktop composition runs for other reasons
206 | ///
207 | DWMWA_PASSIVE_UPDATE_MODE = 16,
208 |
209 | ///
210 | /// BOOL, Allows the use of host backdrop brushes for the window.
211 | ///
212 | DWMWA_USE_HOSTBACKDROPBRUSH = 17,
213 |
214 | ///
215 | /// Allows a window to either use the accent color, or dark, according to the user Color Mode preferences.
216 | ///
217 | DMWA_USE_IMMERSIVE_DARK_MODE_OLD = 19,
218 |
219 | ///
220 | /// Allows a window to either use the accent color, or dark, according to the user Color Mode preferences.
221 | ///
222 | DWMWA_USE_IMMERSIVE_DARK_MODE = 20,
223 |
224 | ///
225 | /// Controls the policy that rounds top-level window corners.
226 | /// Windows 11 and above.
227 | ///
228 | DWMWA_WINDOW_CORNER_PREFERENCE = 33,
229 |
230 | ///
231 | /// The color of the thin border around a top-level window.
232 | ///
233 | DWMWA_BORDER_COLOR = 34,
234 |
235 | ///
236 | /// The color of the caption.
237 | /// Windows 11 and above.
238 | ///
239 | DWMWA_CAPTION_COLOR = 35,
240 |
241 | ///
242 | /// The color of the caption text.
243 | /// Windows 11 and above.
244 | ///
245 | DWMWA_TEXT_COLOR = 36,
246 |
247 | ///
248 | /// Width of the visible border around a thick frame window.
249 | /// Windows 11 and above.
250 | ///
251 | DWMWA_VISIBLE_FRAME_BORDER_THICKNESS = 37,
252 |
253 | ///
254 | /// Allows to enter a value from 0 to 4 deciding on the imposed backdrop effect.
255 | ///
256 | DWMWA_SYSTEMBACKDROP_TYPE = 38,
257 |
258 | ///
259 | /// Indicates whether the window should use the Mica effect.
260 | /// Windows 11 and above.
261 | ///
262 | DWMWA_MICA_EFFECT = 1029
263 | }
264 |
265 | ///
266 | /// Represents the current DWM color accent settings.
267 | ///
268 | [StructLayout(LayoutKind.Sequential)]
269 | public struct DWMCOLORIZATIONPARAMS
270 | {
271 | ///
272 | /// ColorizationColor
273 | ///
274 | public uint clrColor;
275 |
276 | ///
277 | /// ColorizationAfterglow.
278 | ///
279 | public uint clrAfterGlow;
280 |
281 | ///
282 | /// ColorizationColorBalance.
283 | ///
284 | public uint nIntensity;
285 |
286 | ///
287 | /// ColorizationAfterglowBalance.
288 | ///
289 | public uint clrAfterGlowBalance;
290 |
291 | ///
292 | /// ColorizationBlurBalance.
293 | ///
294 | public uint clrBlurBalance;
295 |
296 | ///
297 | /// ColorizationGlassReflectionIntensity.
298 | ///
299 | public uint clrGlassReflectionIntensity;
300 |
301 | ///
302 | /// ColorizationOpaqueBlend.
303 | ///
304 | public bool fOpaque;
305 | }
306 |
307 | ///
308 | /// Defines a data type used by the Desktop Window Manager (DWM) APIs. It represents a generic ratio and is used for different purposes and units even within a single API.
309 | ///
310 | [StructLayout(LayoutKind.Sequential)]
311 | public struct UNSIGNED_RATIO
312 | {
313 | ///
314 | /// The ratio numerator.
315 | ///
316 | public uint uiNumerator;
317 |
318 | ///
319 | /// The ratio denominator.
320 | ///
321 | public uint uiDenominator;
322 | }
323 |
324 | ///
325 | /// Specifies the input operations for which visual feedback should be provided. This enumeration is used by the DwmShowContact function.
326 | ///
327 | public enum DWM_SHOWCONTACT
328 | {
329 | DWMSC_DOWN,
330 | DWMSC_UP,
331 | DWMSC_DRAG,
332 | DWMSC_HOLD,
333 | DWMSC_PENBARREL,
334 | DWMSC_NONE,
335 | DWMSC_ALL
336 | }
337 |
338 | ///
339 | /// Flags used by the DwmSetPresentParameters function to specify the frame sampling type.
340 | ///
341 | public enum DWM_SOURCE_FRAME_SAMPLING
342 | {
343 | ///
344 | /// Use the first source frame that includes the first refresh of the output frame
345 | ///
346 | DWM_SOURCE_FRAME_SAMPLING_POINT,
347 |
348 | ///
349 | /// Use the source frame that includes the most refreshes of out the output frame
350 | /// in case of multiple source frames with the same coverage the last will be used
351 | ///
352 | DWM_SOURCE_FRAME_SAMPLING_COVERAGE,
353 |
354 | ///
355 | /// Sentinel value.
356 | ///
357 | DWM_SOURCE_FRAME_SAMPLING_LAST
358 | }
359 |
360 | ///
361 | /// Specifies Desktop Window Manager (DWM) composition timing information. Used by the function.
362 | ///
363 | [StructLayout(LayoutKind.Sequential, Pack = 1)]
364 | public struct DWM_TIMING_INFO
365 | {
366 | public int cbSize;
367 | public UNSIGNED_RATIO rateRefresh;
368 | public ulong qpcRefreshPeriod;
369 | public UNSIGNED_RATIO rateCompose;
370 | public ulong qpcVBlank;
371 | public ulong cRefresh;
372 | public uint cDXRefresh;
373 | public ulong qpcCompose;
374 | public ulong cFrame;
375 | public uint cDXPresent;
376 | public ulong cRefreshFrame;
377 | public ulong cFrameSubmitted;
378 | public uint cDXPresentSubmitted;
379 | public ulong cFrameConfirmed;
380 | public uint cDXPresentConfirmed;
381 | public ulong cRefreshConfirmed;
382 | public uint cDXRefreshConfirmed;
383 | public ulong cFramesLate;
384 | public uint cFramesOutstanding;
385 | public ulong cFrameDisplayed;
386 | public ulong qpcFrameDisplayed;
387 | public ulong cRefreshFrameDisplayed;
388 | public ulong cFrameComplete;
389 | public ulong qpcFrameComplete;
390 | public ulong cFramePending;
391 | public ulong qpcFramePending;
392 | public ulong cFramesDisplayed;
393 | public ulong cFramesComplete;
394 | public ulong cFramesPending;
395 | public ulong cFramesAvailable;
396 | public ulong cFramesDropped;
397 | public ulong cFramesMissed;
398 | public ulong cRefreshNextDisplayed;
399 | public ulong cRefreshNextPresented;
400 | public ulong cRefreshesDisplayed;
401 | public ulong cRefreshesPresented;
402 | public ulong cRefreshStarted;
403 | public ulong cPixelsReceived;
404 | public ulong cPixelsDrawn;
405 | public ulong cBuffersEmpty;
406 | }
407 |
408 | ///
409 | /// SIT flags.
410 | ///
411 | public enum DWM_SIT
412 | {
413 | ///
414 | /// None.
415 | ///
416 | NONE,
417 |
418 | ///
419 | /// Displays a frame around the provided bitmap.
420 | ///
421 | DISPLAYFRAME = 1,
422 | }
423 |
424 | ///
425 | /// Obtains a value that indicates whether Desktop Window Manager (DWM) composition is enabled.
426 | ///
427 | /// A pointer to a value that, when this function returns successfully, receives TRUE if DWM composition is enabled; otherwise, FALSE.
428 | /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
429 | [DllImport(Libraries.Dwmapi, BestFitMapping = false)]
430 | public static extern int DwmIsCompositionEnabled([Out] out int pfEnabled);
431 |
432 | ///
433 | /// Extends the window frame into the client area.
434 | ///
435 | /// The handle to the window in which the frame will be extended into the client area.
436 | /// A pointer to a MARGINS structure that describes the margins to use when extending the frame into the client area.
437 | [DllImport(Libraries.Dwmapi, PreserveSig = false)]
438 | public static extern void DwmExtendFrameIntoClientArea([In] IntPtr hWnd, [In] ref UxTheme.MARGINS pMarInset);
439 |
440 | ///
441 | /// Retrieves the current composition timing information for a specified window.
442 | ///
443 | /// The handle to the window for which the composition timing information should be retrieved.
444 | /// A pointer to a structure that, when this function returns successfully, receives the current composition timing information for the window.
445 | [DllImport(Libraries.Dwmapi)]
446 | public static extern void DwmGetCompositionTimingInfo([In] IntPtr hWnd, [In] ref DWM_TIMING_INFO pTimingInfo);
447 |
448 | ///
449 | /// Called by an application to indicate that all previously provided iconic bitmaps from a window, both thumbnails and peek representations, should be refreshed.
450 | ///
451 | /// A handle to the window or tab whose bitmaps are being invalidated through this call. This window must belong to the calling process.
452 | [DllImport(Libraries.Dwmapi, PreserveSig = false)]
453 | public static extern void DwmInvalidateIconicBitmaps([In] IntPtr hWnd);
454 |
455 | ///
456 | /// Sets a static, iconic bitmap on a window or tab to use as a thumbnail representation. The taskbar can use this bitmap as a thumbnail switch target for the window or tab.
457 | ///
458 | /// A handle to the window or tab. This window must belong to the calling process.
459 | /// A handle to the bitmap to represent the window that hwnd specifies.
460 | /// The display options for the thumbnail.
461 | [DllImport(Libraries.Dwmapi, PreserveSig = false)]
462 | public static extern void DwmSetIconicThumbnail([In] IntPtr hWnd, [In] IntPtr hbmp, [In] DWM_SIT dwSITFlags);
463 |
464 | ///
465 | /// Sets a static, iconic bitmap to display a live preview (also known as a Peek preview) of a window or tab. The taskbar can use this bitmap to show a full-sized preview of a window or tab.
466 | ///
467 | /// A handle to the window. This window must belong to the calling process.
468 | /// A handle to the bitmap to represent the window that hwnd specifies.
469 | /// The offset of a tab window's client region (the content area inside the client window frame) from the host window's frame. This offset enables the tab window's contents to be drawn correctly in a live preview when it is drawn without its frame.
470 | /// The display options for the live preview.
471 | [DllImport(Libraries.Dwmapi, PreserveSig = false)]
472 | public static extern int DwmSetIconicLivePreviewBitmap([In] IntPtr hWnd, [In] IntPtr hbmp,
473 | [In, Optional] RefPOINT pptClient, [In] DWM_SIT dwSITFlags);
474 |
475 | ///
476 | /// Sets the value of Desktop Window Manager (DWM) non-client rendering attributes for a window.
477 | ///
478 | /// The handle to the window for which the attribute value is to be set.
479 | /// A flag describing which value to set, specified as a value of the DWMWINDOWATTRIBUTE enumeration.
480 | /// A pointer to an object containing the attribute value to set.
481 | /// The size, in bytes, of the attribute value being set via the pvAttribute parameter.
482 | /// If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
483 | [DllImport(Libraries.Dwmapi)]
484 | public static extern int DwmSetWindowAttribute([In] IntPtr hWnd, [In] int dwAttribute,
485 | [In] ref int pvAttribute,
486 | [In] int cbAttribute);
487 |
488 | ///
489 | /// Sets the value of Desktop Window Manager (DWM) non-client rendering attributes for a window.
490 | ///
491 | /// The handle to the window for which the attribute value is to be set.
492 | /// A flag describing which value to set, specified as a value of the DWMWINDOWATTRIBUTE enumeration.
493 | /// A pointer to an object containing the attribute value to set.
494 | /// The size, in bytes, of the attribute value being set via the pvAttribute parameter.
495 | /// If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
496 | [DllImport(Libraries.Dwmapi)]
497 | public static extern int DwmSetWindowAttribute([In] IntPtr hWnd, [In] DWMWINDOWATTRIBUTE dwAttribute,
498 | [In] ref int pvAttribute,
499 | [In] int cbAttribute);
500 |
501 | ///
502 | /// Retrieves the current value of a specified Desktop Window Manager (DWM) attribute applied to a window. For programming guidance, and code examples, see Controlling non-client region rendering.
503 | ///
504 | /// The handle to the window from which the attribute value is to be retrieved.
505 | /// A flag describing which value to retrieve, specified as a value of the enumeration.
506 | /// A pointer to a value which, when this function returns successfully, receives the current value of the attribute. The type of the retrieved value depends on the value of the dwAttribute parameter.
507 | /// The size, in bytes, of the attribute value being received via the pvAttribute parameter.
508 | /// If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
509 | [DllImport(Libraries.Dwmapi)]
510 | public static extern int DwmGetWindowAttribute([In] IntPtr hWnd, [In] DWMWINDOWATTRIBUTE dwAttributeToGet,
511 | [In] ref int pvAttributeValue,
512 | [In] int cbAttribute);
513 |
514 | ///
515 | /// Retrieves the current value of a specified Desktop Window Manager (DWM) attribute applied to a window. For programming guidance, and code examples, see Controlling non-client region rendering.
516 | ///
517 | /// The handle to the window from which the attribute value is to be retrieved.
518 | /// A flag describing which value to retrieve, specified as a value of the enumeration.
519 | /// A pointer to a value which, when this function returns successfully, receives the current value of the attribute. The type of the retrieved value depends on the value of the dwAttribute parameter.
520 | /// The size, in bytes, of the attribute value being received via the pvAttribute parameter.
521 | /// If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
522 | [DllImport(Libraries.Dwmapi)]
523 | public static extern int DwmGetWindowAttribute([In] IntPtr hWnd, [In] int dwAttributeToGet,
524 | [In] ref int pvAttributeValue,
525 | [In] int cbAttribute);
526 |
527 | ///
528 | /// The feature is not included in the Microsoft documentation. Reads Desktop Window Manager (DWM) color information.
529 | ///
530 | /// A pointer to a reference value that will hold the color information.
531 | [DllImport(Libraries.Dwmapi, EntryPoint = "#127", PreserveSig = false, CharSet = CharSet.Unicode)]
532 | public static extern void DwmGetColorizationParameters([Out] out DWMCOLORIZATIONPARAMS dwParameters);
533 | }
534 |
--------------------------------------------------------------------------------
/src/NativeMethods/Interop/User32.cs:
--------------------------------------------------------------------------------
1 | // This Source Code is partially based on reverse engineering of the Windows Operating System,
2 | // and is intended for use on Windows systems only.
3 | // This Source Code is partially based on the source code provided by the .NET Foundation.
4 | // This Source Code Form is subject to the terms of the MIT License.
5 | // If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
6 | // Copyright (C) Leszek Pomianowski.
7 | // All Rights Reserved.
8 |
9 | using System;
10 | using System.Runtime.InteropServices;
11 | using NativeMethods.Attributes;
12 | using NativeMethods.WinDef;
13 |
14 | // Windows Kits\10\Include\10.0.22000.0\um\WinUser.h
15 |
16 | namespace NativeMethods.Interop;
17 |
18 | ///
19 | /// USER procedure declarations, constant definitions and macros.
20 | ///
21 | // ReSharper disable IdentifierTypo
22 | // ReSharper disable InconsistentNaming
23 | [UnmanagedComponent]
24 | public static class User32
25 | {
26 | ///
27 | /// WM_NCHITTEST and MOUSEHOOKSTRUCT Mouse Position Codes
28 | ///
29 | /* TODO: Fix HT NCHIT TEST
30 | #define HTERROR (-2)
31 | #define HTTRANSPARENT (-1)
32 | #define HTNOWHERE 0
33 | #define HTCLIENT 1
34 | #define HTCAPTION 2
35 | #define HTSYSMENU 3
36 | #define HTGROWBOX 4
37 | #define HTSIZE HTGROWBOX
38 | #define HTMENU 5
39 | #define HTHSCROLL 6
40 | #define HTVSCROLL 7
41 | #define HTMINBUTTON 8
42 | #define HTMAXBUTTON 9
43 | #define HTLEFT 10
44 | #define HTRIGHT 11
45 | #define HTTOP 12
46 | #define HTTOPLEFT 13
47 | #define HTTOPRIGHT 14
48 | #define HTBOTTOM 15
49 | #define HTBOTTOMLEFT 16
50 | #define HTBOTTOMRIGHT 17
51 | #define HTBORDER 18
52 | #define HTREDUCE HTMINBUTTON
53 | #define HTZOOM HTMAXBUTTON
54 | #define HTSIZEFIRST HTLEFT
55 | #define HTSIZELAST HTBOTTOMRIGHT
56 | #if(WINVER >= 0x0400)
57 | #define HTOBJECT 19
58 | #define HTCLOSE 20
59 | #define HTHELP 21
60 | */
61 | public enum WM_NCHITTEST
62 | {
63 | ///
64 | /// On the screen background or on a dividing line between windows.
65 | ///
66 | NOWHERE = 0,
67 |
68 | ///
69 | /// In a client area.
70 | ///
71 | CLIENT = 1,
72 |
73 | ///
74 | /// In a title bar.
75 | ///
76 | CAPTION = 2,
77 |
78 | ///
79 | /// In a window menu or in a Close button in a child window.
80 | ///
81 | SYSMENU = 3,
82 |
83 | ///
84 | /// In a size box (same as HTSIZE).
85 | ///
86 | GROWBOX = 4,
87 | //SIZE = 4,
88 |
89 | ///
90 | /// In a menu.
91 | ///
92 | MENU = 5,
93 |
94 | ///
95 | /// In a horizontal scroll bar.
96 | ///
97 | HSCROLL = 6,
98 |
99 | ///
100 | /// In the vertical scroll bar.
101 | ///
102 | VSCROLL = 7,
103 |
104 | ///
105 | /// In a Minimize button.
106 | ///
107 | MINBUTTON = 8,
108 |
109 | ///
110 | /// In a Maximize button.
111 | ///
112 | MAXBUTTON = 9,
113 | // ZOOM = 9,
114 |
115 | ///
116 | /// In the left border of a resizable window (the user can click the mouse to resize the window horizontally).
117 | ///
118 | LEFT = 10,
119 |
120 | ///
121 | /// In the right border of a resizable window (the user can click the mouse to resize the window horizontally).
122 | ///
123 | RIGHT = 11,
124 |
125 | ///
126 | /// In the upper-horizontal border of a window.
127 | ///
128 | TOP = 12,
129 | }
130 |
131 | ///
132 | /// Window long flags.
133 | ///
134 | ///
135 | [Flags]
136 | public enum GWL
137 | {
138 | ///
139 | /// Sets a new extended window style.
140 | ///
141 | GWL_EXSTYLE = -20,
142 |
143 | ///
144 | /// Sets a new application instance handle.
145 | ///
146 | GWLP_HINSTANCE = -6,
147 |
148 | ///
149 | /// Sets a new hWnd parent.
150 | ///
151 | GWLP_HWNDPARENT = -8,
152 |
153 | ///
154 | /// Sets a new identifier of the child window. The window cannot be a top-level window.
155 | ///
156 | GWL_ID = -12,
157 |
158 | ///
159 | /// Sets a new window style.
160 | ///
161 | GWL_STYLE = -16,
162 |
163 | ///
164 | /// Sets the user data associated with the window.
165 | /// This data is intended for use by the application that created the window. Its value is initially zero.
166 | ///
167 | GWL_USERDATA = -21,
168 |
169 | ///
170 | /// Sets a new address for the window procedure.
171 | /// You cannot change this attribute if the window does not belong to the same process as the calling thread.
172 | ///
173 | GWL_WNDPROC = -4,
174 |
175 | ///
176 | /// Sets new extra information that is private to the application, such as handles or pointers.
177 | ///
178 | DWLP_USER = 0x8,
179 |
180 | ///
181 | /// Sets the return value of a message processed in the dialog box procedure.
182 | ///
183 | DWLP_MSGRESULT = 0x0,
184 |
185 | ///
186 | /// Sets the new address of the dialog box procedure.
187 | ///
188 | DWLP_DLGPROC = 0x4
189 | }
190 |
191 | ///
192 | /// Window composition attributes.
193 | ///
194 | public enum WCA
195 | {
196 | WCA_UNDEFINED = 0,
197 | WCA_NCRENDERING_ENABLED = 1,
198 | WCA_NCRENDERING_POLICY = 2,
199 | WCA_TRANSITIONS_FORCEDISABLED = 3,
200 | WCA_ALLOW_NCPAINT = 4,
201 | WCA_CAPTION_BUTTON_BOUNDS = 5,
202 | WCA_NONCLIENT_RTL_LAYOUT = 6,
203 | WCA_FORCE_ICONIC_REPRESENTATION = 7,
204 | WCA_EXTENDED_FRAME_BOUNDS = 8,
205 | WCA_HAS_ICONIC_BITMAP = 9,
206 | WCA_THEME_ATTRIBUTES = 10,
207 | WCA_NCRENDERING_EXILED = 11,
208 | WCA_NCADORNMENTINFO = 12,
209 | WCA_EXCLUDED_FROM_LIVEPREVIEW = 13,
210 | WCA_VIDEO_OVERLAY_ACTIVE = 14,
211 | WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15,
212 | WCA_DISALLOW_PEEK = 16,
213 | WCA_CLOAK = 17,
214 | WCA_CLOAKED = 18,
215 | WCA_ACCENT_POLICY = 19,
216 | WCA_FREEZE_REPRESENTATION = 20,
217 | WCA_EVER_UNCLOAKED = 21,
218 | WCA_VISUAL_OWNER = 22,
219 | WCA_HOLOGRAPHIC = 23,
220 | WCA_EXCLUDED_FROM_DDA = 24,
221 | WCA_PASSIVEUPDATEMODE = 25,
222 | WCA_USEDARKMODECOLORS = 26,
223 | WCA_CORNER_STYLE = 27,
224 | WCA_PART_COLOR = 28,
225 | WCA_DISABLE_MOVESIZE_FEEDBACK = 29,
226 | WCA_LAST = 30
227 | }
228 |
229 | [StructLayout(LayoutKind.Sequential)]
230 | public struct WINCOMPATTRDATA
231 | {
232 | public WCA Attribute;
233 | public IntPtr Data;
234 | public int SizeOfData;
235 | }
236 |
237 | ///
238 | /// CS_*
239 | ///
240 | [Flags]
241 | public enum CS : uint
242 | {
243 | VREDRAW = 0x0001,
244 | HREDRAW = 0x0002,
245 | DBLCLKS = 0x0008,
246 | OWNDC = 0x0020,
247 | CLASSDC = 0x0040,
248 | PARENTDC = 0x0080,
249 | NOCLOSE = 0x0200,
250 | SAVEBITS = 0x0800,
251 | BYTEALIGNCLIENT = 0x1000,
252 | BYTEALIGNWINDOW = 0x2000,
253 | GLOBALCLASS = 0x4000,
254 | IME = 0x00010000,
255 | DROPSHADOW = 0x00020000
256 | }
257 |
258 | ///
259 | /// MSGFLT_*. New in Vista. Realiased in Windows 7.
260 | ///
261 | public enum MSGFLT
262 | {
263 | // Win7 versions of this enum:
264 |
265 | ///
266 | /// Resets the window message filter for hWnd to the default. Any message allowed globally or process-wide will get through, but any message not included in those two categories, and which comes from a lower privileged process, will be blocked.
267 | ///
268 | RESET = 0,
269 |
270 | ///
271 | /// Allows the message through the filter. This enables the message to be received by hWnd, regardless of the source of the message, even it comes from a lower privileged process.
272 | ///
273 | ALLOW = 1,
274 |
275 | ///
276 | /// Blocks the message to be delivered to hWnd if it comes from a lower privileged process, unless the message is allowed process-wide by using the ChangeWindowMessageFilter function or globally.
277 | ///
278 | DISALLOW = 2,
279 |
280 | // Vista versions of this enum:
281 | // ADD = 1,
282 | // REMOVE = 2,
283 | }
284 |
285 | ///
286 | /// MSGFLTINFO.
287 | ///
288 | public enum MSGFLTINFO
289 | {
290 | NONE = 0,
291 | ALREADYALLOWED_FORWND = 1,
292 | ALREADYDISALLOWED_FORWND = 2,
293 | ALLOWED_HIGHER = 3,
294 | }
295 |
296 | ///
297 | /// Win7 only.
298 | ///
299 | [StructLayout(LayoutKind.Sequential)]
300 | public struct CHANGEFILTERSTRUCT
301 | {
302 | public uint cbSize;
303 | public MSGFLTINFO ExtStatus;
304 | }
305 |
306 | ///
307 | /// Window message values, WM_*
308 | ///
309 | public enum WM
310 | {
311 | NULL = 0x0000,
312 | CREATE = 0x0001,
313 | DESTROY = 0x0002,
314 | MOVE = 0x0003,
315 | SIZE = 0x0005,
316 | ACTIVATE = 0x0006,
317 | SETFOCUS = 0x0007,
318 | KILLFOCUS = 0x0008,
319 | ENABLE = 0x000A,
320 | SETREDRAW = 0x000B,
321 | SETTEXT = 0x000C,
322 | GETTEXT = 0x000D,
323 | GETTEXTLENGTH = 0x000E,
324 | PAINT = 0x000F,
325 | CLOSE = 0x0010,
326 | QUERYENDSESSION = 0x0011,
327 | QUIT = 0x0012,
328 | QUERYOPEN = 0x0013,
329 | ERASEBKGND = 0x0014,
330 | SYSCOLORCHANGE = 0x0015,
331 | SHOWWINDOW = 0x0018,
332 | CTLCOLOR = 0x0019,
333 | WININICHANGE = 0x001A,
334 | SETTINGCHANGE = 0x001A,
335 | ACTIVATEAPP = 0x001C,
336 | SETCURSOR = 0x0020,
337 | MOUSEACTIVATE = 0x0021,
338 | CHILDACTIVATE = 0x0022,
339 | QUEUESYNC = 0x0023,
340 | GETMINMAXINFO = 0x0024,
341 |
342 | WINDOWPOSCHANGING = 0x0046,
343 | WINDOWPOSCHANGED = 0x0047,
344 |
345 | CONTEXTMENU = 0x007B,
346 | STYLECHANGING = 0x007C,
347 | STYLECHANGED = 0x007D,
348 | DISPLAYCHANGE = 0x007E,
349 | GETICON = 0x007F,
350 | SETICON = 0x0080,
351 | NCCREATE = 0x0081,
352 | NCDESTROY = 0x0082,
353 | NCCALCSIZE = 0x0083,
354 | NCHITTEST = 0x0084,
355 | NCPAINT = 0x0085,
356 | NCACTIVATE = 0x0086,
357 | GETDLGCODE = 0x0087,
358 | SYNCPAINT = 0x0088,
359 | NCMOUSEMOVE = 0x00A0,
360 | NCLBUTTONDOWN = 0x00A1,
361 | NCLBUTTONUP = 0x00A2,
362 | NCLBUTTONDBLCLK = 0x00A3,
363 | NCRBUTTONDOWN = 0x00A4,
364 | NCRBUTTONUP = 0x00A5,
365 | NCRBUTTONDBLCLK = 0x00A6,
366 | NCMBUTTONDOWN = 0x00A7,
367 | NCMBUTTONUP = 0x00A8,
368 | NCMBUTTONDBLCLK = 0x00A9,
369 |
370 | SYSKEYDOWN = 0x0104,
371 | SYSKEYUP = 0x0105,
372 | SYSCHAR = 0x0106,
373 | SYSDEADCHAR = 0x0107,
374 | COMMAND = 0x0111,
375 | SYSCOMMAND = 0x0112,
376 |
377 | MOUSEMOVE = 0x0200,
378 | LBUTTONDOWN = 0x0201,
379 | LBUTTONUP = 0x0202,
380 | LBUTTONDBLCLK = 0x0203,
381 | RBUTTONDOWN = 0x0204,
382 | RBUTTONUP = 0x0205,
383 | RBUTTONDBLCLK = 0x0206,
384 | MBUTTONDOWN = 0x0207,
385 | MBUTTONUP = 0x0208,
386 | MBUTTONDBLCLK = 0x0209,
387 | MOUSEWHEEL = 0x020A,
388 | XBUTTONDOWN = 0x020B,
389 | XBUTTONUP = 0x020C,
390 | XBUTTONDBLCLK = 0x020D,
391 | MOUSEHWHEEL = 0x020E,
392 | PARENTNOTIFY = 0x0210,
393 |
394 | CAPTURECHANGED = 0x0215,
395 | POWERBROADCAST = 0x0218,
396 | DEVICECHANGE = 0x0219,
397 |
398 | ENTERSIZEMOVE = 0x0231,
399 | EXITSIZEMOVE = 0x0232,
400 |
401 | IME_SETCONTEXT = 0x0281,
402 | IME_NOTIFY = 0x0282,
403 | IME_CONTROL = 0x0283,
404 | IME_COMPOSITIONFULL = 0x0284,
405 | IME_SELECT = 0x0285,
406 | IME_CHAR = 0x0286,
407 | IME_REQUEST = 0x0288,
408 | IME_KEYDOWN = 0x0290,
409 | IME_KEYUP = 0x0291,
410 |
411 | NCMOUSELEAVE = 0x02A2,
412 |
413 | TABLET_DEFBASE = 0x02C0,
414 | //WM_TABLET_MAXOFFSET = 0x20,
415 |
416 | TABLET_ADDED = TABLET_DEFBASE + 8,
417 | TABLET_DELETED = TABLET_DEFBASE + 9,
418 | TABLET_FLICK = TABLET_DEFBASE + 11,
419 | TABLET_QUERYSYSTEMGESTURESTATUS = TABLET_DEFBASE + 12,
420 |
421 | CUT = 0x0300,
422 | COPY = 0x0301,
423 | PASTE = 0x0302,
424 | CLEAR = 0x0303,
425 | UNDO = 0x0304,
426 | RENDERFORMAT = 0x0305,
427 | RENDERALLFORMATS = 0x0306,
428 | DESTROYCLIPBOARD = 0x0307,
429 | DRAWCLIPBOARD = 0x0308,
430 | PAINTCLIPBOARD = 0x0309,
431 | VSCROLLCLIPBOARD = 0x030A,
432 | SIZECLIPBOARD = 0x030B,
433 | ASKCBFORMATNAME = 0x030C,
434 | CHANGECBCHAIN = 0x030D,
435 | HSCROLLCLIPBOARD = 0x030E,
436 | QUERYNEWPALETTE = 0x030F,
437 | PALETTEISCHANGING = 0x0310,
438 | PALETTECHANGED = 0x0311,
439 | HOTKEY = 0x0312,
440 | PRINT = 0x0317,
441 | PRINTCLIENT = 0x0318,
442 | APPCOMMAND = 0x0319,
443 | THEMECHANGED = 0x031A,
444 |
445 | DWMCOMPOSITIONCHANGED = 0x031E,
446 | DWMNCRENDERINGCHANGED = 0x031F,
447 | DWMCOLORIZATIONCOLORCHANGED = 0x0320,
448 | DWMWINDOWMAXIMIZEDCHANGE = 0x0321,
449 |
450 | GETTITLEBARINFOEX = 0x033F,
451 |
452 | #region Windows 7
453 |
454 | DWMSENDICONICTHUMBNAIL = 0x0323,
455 | DWMSENDICONICLIVEPREVIEWBITMAP = 0x0326,
456 |
457 | #endregion
458 |
459 | USER = 0x0400,
460 |
461 | ///
462 | /// This is the hard-coded message value used by WinForms for Shell_NotifyIcon.
463 | /// It's relatively safe to reuse.
464 | ///
465 | TRAYMOUSEMESSAGE = 0x800, //WM_USER + 1024
466 | APP = 0x8000,
467 | }
468 |
469 | ///
470 | /// WindowStyle values, WS_*
471 | ///
472 | [Flags]
473 | public enum WS : uint
474 | {
475 | OVERLAPPED = 0x00000000,
476 | POPUP = 0x80000000,
477 | CHILD = 0x40000000,
478 | MINIMIZE = 0x20000000,
479 | VISIBLE = 0x10000000,
480 | DISABLED = 0x08000000,
481 | CLIPSIBLINGS = 0x04000000,
482 | CLIPCHILDREN = 0x02000000,
483 | MAXIMIZE = 0x01000000,
484 | BORDER = 0x00800000,
485 | DLGFRAME = 0x00400000,
486 | VSCROLL = 0x00200000,
487 | HSCROLL = 0x00100000,
488 | SYSMENU = 0x00080000,
489 | THICKFRAME = 0x00040000,
490 | GROUP = 0x00020000,
491 | TABSTOP = 0x00010000,
492 |
493 | MINIMIZEBOX = 0x00020000,
494 | MAXIMIZEBOX = 0x00010000,
495 |
496 | CAPTION = BORDER | DLGFRAME,
497 | TILED = OVERLAPPED,
498 | ICONIC = MINIMIZE,
499 | SIZEBOX = THICKFRAME,
500 | TILEDWINDOW = OVERLAPPEDWINDOW,
501 |
502 | OVERLAPPEDWINDOW = OVERLAPPED | CAPTION | SYSMENU | THICKFRAME | MINIMIZEBOX | MAXIMIZEBOX,
503 | POPUPWINDOW = POPUP | BORDER | SYSMENU,
504 | CHILDWINDOW = CHILD,
505 | }
506 |
507 | ///
508 | /// Window style extended values, WS_EX_*
509 | ///
510 | [Flags]
511 | public enum WS_EX : uint
512 | {
513 | NONE = 0,
514 | DLGMODALFRAME = 0x00000001,
515 | NOPARENTNOTIFY = 0x00000004,
516 | TOPMOST = 0x00000008,
517 | ACCEPTFILES = 0x00000010,
518 | TRANSPARENT = 0x00000020,
519 | MDICHILD = 0x00000040,
520 | TOOLWINDOW = 0x00000080,
521 | WINDOWEDGE = 0x00000100,
522 | CLIENTEDGE = 0x00000200,
523 | CONTEXTHELP = 0x00000400,
524 | RIGHT = 0x00001000,
525 | LEFT = 0x00000000,
526 | RTLREADING = 0x00002000,
527 | LTRREADING = 0x00000000,
528 | LEFTSCROLLBAR = 0x00004000,
529 | RIGHTSCROLLBAR = 0x00000000,
530 | CONTROLPARENT = 0x00010000,
531 | STATICEDGE = 0x00020000,
532 | APPWINDOW = 0x00040000,
533 | LAYERED = 0x00080000,
534 | NOINHERITLAYOUT = 0x00100000, // Disable inheritence of mirroring by children
535 | LAYOUTRTL = 0x00400000, // Right to left mirroring
536 | COMPOSITED = 0x02000000,
537 | NOACTIVATE = 0x08000000,
538 | OVERLAPPEDWINDOW = (WINDOWEDGE | CLIENTEDGE),
539 | PALETTEWINDOW = (WINDOWEDGE | TOOLWINDOW | TOPMOST),
540 | }
541 |
542 | ///
543 | /// SystemMetrics. SM_*
544 | ///
545 | public enum SM
546 | {
547 | CXSCREEN = 0,
548 | CYSCREEN = 1,
549 | CXVSCROLL = 2,
550 | CYHSCROLL = 3,
551 | CYCAPTION = 4,
552 | CXBORDER = 5,
553 | CYBORDER = 6,
554 | CXFIXEDFRAME = 7,
555 | CYFIXEDFRAME = 8,
556 | CYVTHUMB = 9,
557 | CXHTHUMB = 10,
558 | CXICON = 11,
559 | CYICON = 12,
560 | CXCURSOR = 13,
561 | CYCURSOR = 14,
562 | CYMENU = 15,
563 | CXFULLSCREEN = 16,
564 | CYFULLSCREEN = 17,
565 | CYKANJIWINDOW = 18,
566 | MOUSEPRESENT = 19,
567 | CYVSCROLL = 20,
568 | CXHSCROLL = 21,
569 | DEBUG = 22,
570 | SWAPBUTTON = 23,
571 | CXMIN = 28,
572 | CYMIN = 29,
573 | CXSIZE = 30,
574 | CYSIZE = 31,
575 | CXFRAME = 32,
576 | CXSIZEFRAME = CXFRAME,
577 | CYFRAME = 33,
578 | CYSIZEFRAME = CYFRAME,
579 | CXMINTRACK = 34,
580 | CYMINTRACK = 35,
581 | CXDOUBLECLK = 36,
582 | CYDOUBLECLK = 37,
583 | CXICONSPACING = 38,
584 | CYICONSPACING = 39,
585 | MENUDROPALIGNMENT = 40,
586 | PENWINDOWS = 41,
587 | DBCSENABLED = 42,
588 | CMOUSEBUTTONS = 43,
589 | SECURE = 44,
590 | CXEDGE = 45,
591 | CYEDGE = 46,
592 | CXMINSPACING = 47,
593 | CYMINSPACING = 48,
594 | CXSMICON = 49,
595 | CYSMICON = 50,
596 | CYSMCAPTION = 51,
597 | CXSMSIZE = 52,
598 | CYSMSIZE = 53,
599 | CXMENUSIZE = 54,
600 | CYMENUSIZE = 55,
601 | ARRANGE = 56,
602 | CXMINIMIZED = 57,
603 | CYMINIMIZED = 58,
604 | CXMAXTRACK = 59,
605 | CYMAXTRACK = 60,
606 | CXMAXIMIZED = 61,
607 | CYMAXIMIZED = 62,
608 | NETWORK = 63,
609 | CLEANBOOT = 67,
610 | CXDRAG = 68,
611 | CYDRAG = 69,
612 | SHOWSOUNDS = 70,
613 | CXMENUCHECK = 71,
614 | CYMENUCHECK = 72,
615 | SLOWMACHINE = 73,
616 | MIDEASTENABLED = 74,
617 | MOUSEWHEELPRESENT = 75,
618 | XVIRTUALSCREEN = 76,
619 | YVIRTUALSCREEN = 77,
620 | CXVIRTUALSCREEN = 78,
621 | CYVIRTUALSCREEN = 79,
622 | CMONITORS = 80,
623 | SAMEDISPLAYFORMAT = 81,
624 | IMMENABLED = 82,
625 | CXFOCUSBORDER = 83,
626 | CYFOCUSBORDER = 84,
627 | TABLETPC = 86,
628 | MEDIACENTER = 87,
629 | REMOTESESSION = 0x1000,
630 | REMOTECONTROL = 0x2001,
631 | }
632 |
633 | ///
634 | /// ShowWindow options
635 | ///
636 | public enum SW
637 | {
638 | HIDE = 0,
639 | SHOWNORMAL = 1,
640 | NORMAL = 1,
641 | SHOWMINIMIZED = 2,
642 | SHOWMAXIMIZED = 3,
643 | MAXIMIZE = 3,
644 | SHOWNOACTIVATE = 4,
645 | SHOW = 5,
646 | MINIMIZE = 6,
647 | SHOWMINNOACTIVE = 7,
648 | SHOWNA = 8,
649 | RESTORE = 9,
650 | SHOWDEFAULT = 10,
651 | FORCEMINIMIZE = 11,
652 | }
653 |
654 | [StructLayout(LayoutKind.Sequential)]
655 | public class WINDOWPLACEMENT
656 | {
657 | public int length = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
658 | public int flags;
659 | public SW showCmd;
660 | public POINT ptMinPosition;
661 | public POINT ptMaxPosition;
662 | public RECT rcNormalPosition;
663 | }
664 |
665 | ///
666 | /// Contains window class information. It is used with the and GetClassInfoEx functions.
667 | ///
668 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
669 | public struct WNDCLASSEX
670 | {
671 | ///
672 | /// The size, in bytes, of this structure. Set this member to sizeof(WNDCLASSEX). Be sure to set this member before calling the GetClassInfoEx function.
673 | ///
674 | public int cbSize;
675 |
676 | ///
677 | /// The class style(s). This member can be any combination of the Class Styles.
678 | ///
679 | public CS style;
680 |
681 | ///
682 | /// A pointer to the window procedure. You must use the CallWindowProc function to call the window procedure. For more information, see WindowProc.
683 | ///
684 | public WndProc lpfnWndProc;
685 |
686 | ///
687 | /// The number of extra bytes to allocate following the window-class structure. The system initializes the bytes to zero.
688 | ///
689 | public int cbClsExtra;
690 |
691 | ///
692 | /// The number of extra bytes to allocate following the window instance. The system initializes the bytes to zero. If an application uses WNDCLASSEX to register a dialog box created by using the CLASS directive in the resource file, it must set this member to DLGWINDOWEXTRA.
693 | ///
694 | public int cbWndExtra;
695 |
696 | ///
697 | /// A handle to the instance that contains the window procedure for the class.
698 | ///
699 | public IntPtr hInstance;
700 |
701 | ///
702 | /// A handle to the class icon. This member must be a handle to an icon resource. If this member is NULL, the system provides a default icon.
703 | ///
704 | public IntPtr hIcon;
705 |
706 | ///
707 | /// A handle to the class cursor. This member must be a handle to a cursor resource. If this member is NULL, an application must explicitly set the cursor shape whenever the mouse moves into the application's window.
708 | ///
709 | public IntPtr hCursor;
710 |
711 | ///
712 | /// A handle to the class background brush. This member can be a handle to the brush to be used for painting the background, or it can be a color value.
713 | ///
714 | public IntPtr hbrBackground;
715 |
716 | ///
717 | /// Pointer to a null-terminated character string that specifies the resource name of the class menu, as the name appears in the resource file. If you use an integer to identify the menu, use the MAKEINTRESOURCE macro. If this member is NULL, windows belonging to this class have no default menu.
718 | ///
719 | [MarshalAs(UnmanagedType.LPWStr)] public string lpszMenuName;
720 |
721 | ///
722 | /// A pointer to a null-terminated string or is an atom. If this parameter is an atom, it must be a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpszClassName; the high-order word must be zero.
723 | ///
724 | [MarshalAs(UnmanagedType.LPWStr)] public string lpszClassName;
725 |
726 | ///
727 | /// A handle to a small icon that is associated with the window class. If this member is NULL, the system searches the icon resource specified by the hIcon member for an icon of the appropriate size to use as the small icon.
728 | ///
729 | public IntPtr hIconSm;
730 | }
731 |
732 | ///
733 | /// Delegate declaration that matches native WndProc signatures.
734 | ///
735 | public delegate IntPtr WndProc(IntPtr hWnd, WM uMsg, IntPtr wParam, IntPtr lParam);
736 |
737 | ///
738 | /// Delegate declaration that matches native WndProc signatures.
739 | ///
740 | public delegate IntPtr WndProcHook(IntPtr hWnd, WM uMsg, IntPtr wParam, IntPtr lParam, ref bool handled);
741 |
742 | ///
743 | /// Delegate declaration that matches managed WndProc signatures.
744 | ///
745 | public delegate IntPtr MessageHandler(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled);
746 |
747 | ///
748 | /// The ReleaseDC function releases a device context (DC), freeing it for use by other applications.
749 | /// The effect of the ReleaseDC function depends on the type of DC. It frees only common and window DCs. It has no effect on class or private DCs.
750 | ///
751 | /// A handle to the window whose DC is to be released.
752 | /// A handle to the DC to be released.
753 | /// The return value indicates whether the DC was released. If the DC was released, the return value is 1. If the DC was not released, the return value is zero.
754 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
755 | public static extern int ReleaseDC([In] IntPtr hWnd, [In] IntPtr hDC);
756 |
757 | ///
758 | /// Calculates the required size of the window rectangle, based on the desired size of the client rectangle.
759 | /// The window rectangle can then be passed to the CreateWindowEx function to create a window whose client area is the desired size.
760 | ///
761 | /// A pointer to a RECT structure that contains the coordinates of the top-left and bottom-right corners of the desired client area.
762 | /// The window style of the window whose required size is to be calculated. Note that you cannot specify the WS_OVERLAPPED style.
763 | /// Indicates whether the window has a menu.
764 | /// The extended window style of the window whose required size is to be calculated.
765 | /// If the function succeeds, the return value is nonzero.
766 | [DllImport(Libraries.User32, CharSet = CharSet.Auto, SetLastError = true)]
767 | [return: MarshalAs(UnmanagedType.Bool)]
768 | public static extern bool AdjustWindowRectEx([In] ref RECT lpRect, [In] WS dwStyle,
769 | [In][MarshalAs(UnmanagedType.Bool)] bool bMenu, [In] WS_EX dwExStyle);
770 |
771 | ///
772 | /// [Using the ChangeWindowMessageFilter function is not recommended, as it has process-wide scope. Instead, use the ChangeWindowMessageFilterEx function to control access to specific windows as needed. ChangeWindowMessageFilter may not be supported in future versions of Windows.
773 | /// Adds or removes a message from the User Interface Privilege Isolation(UIPI) message filter.
774 | ///
775 | /// The message to add to or remove from the filter.
776 | /// The action to be performed. One of the following values.
777 | /// if successful; otherwise, . To get extended error information, call .
778 | [DllImport(Libraries.User32, CharSet = CharSet.Auto, SetLastError = true)]
779 | [return: MarshalAs(UnmanagedType.Bool)]
780 | public static extern bool ChangeWindowMessageFilter([In] WM message, [In] MSGFLT dwFlag);
781 |
782 | ///
783 | /// Modifies the User Interface Privilege Isolation (UIPI) message filter for a specified window.
784 | ///
785 | /// A handle to the window whose UIPI message filter is to be modified.
786 | /// The message that the message filter allows through or blocks.
787 | /// The action to be performed.
788 | /// Optional pointer to a structure.
789 | /// If the function succeeds, it returns ; otherwise, it returns . To get extended error information, call .
790 | [DllImport(Libraries.User32, CharSet = CharSet.Auto, SetLastError = true)]
791 | [return: MarshalAs(UnmanagedType.Bool)]
792 | public static extern bool ChangeWindowMessageFilterEx([In] IntPtr hWnd, [In] WM message, [In] MSGFLT action,
793 | [In, Out, Optional] ref CHANGEFILTERSTRUCT pChangeFilterStruct);
794 |
795 | ///
796 | /// Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.
797 | /// Unicode declaration for
798 | ///
799 | /// A handle to the window whose window procedure is to receive the message.
800 | /// The message to be posted.
801 | /// Additional message-specific information.
802 | /// Additional message-specific information.
803 | /// If the function succeeds, the return value is nonzero.
804 | [DllImport(Libraries.User32, SetLastError = true)]
805 | [return: MarshalAs(UnmanagedType.Bool)]
806 | private static extern bool PostMessageW([In, Optional] IntPtr hWnd, [In] WM Msg, [In] IntPtr wParam,
807 | [In] IntPtr lParam);
808 |
809 | ///
810 | /// Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.
811 | /// ANSI declaration for
812 | ///
813 | /// A handle to the window whose window procedure is to receive the message.
814 | /// The message to be posted.
815 | /// Additional message-specific information.
816 | /// Additional message-specific information.
817 | /// If the function succeeds, the return value is nonzero.
818 | [DllImport(Libraries.User32, SetLastError = true)]
819 | [return: MarshalAs(UnmanagedType.Bool)]
820 | private static extern bool PostMessageA([In, Optional] IntPtr hWnd, [In] WM Msg, [In] IntPtr wParam,
821 | [In] IntPtr lParam);
822 |
823 | ///
824 | /// Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.
825 | ///
826 | /// A handle to the window whose window procedure is to receive the message.
827 | /// The message to be posted.
828 | /// Additional message-specific information.
829 | /// Additional message-specific information.
830 | /// If the function succeeds, the return value is nonzero.
831 | [DllImport(Libraries.User32, SetLastError = true)]
832 | [return: MarshalAs(UnmanagedType.Bool)]
833 | private static extern bool PostMessage([In, Optional] IntPtr hWnd, [In] WM Msg, [In] IntPtr wParam,
834 | [In] IntPtr lParam);
835 |
836 | ///
837 | /// Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.
838 | ///
839 | /// A handle to the window whose window procedure will receive the message.
840 | /// The message to be sent.
841 | /// Additional message-specific information.
842 | /// Additional message-specific information.
843 | /// The return value specifies the result of the message processing; it depends on the message sent.
844 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
845 | public static extern int SendMessage([In] IntPtr hWnd, [In] WM wMsg, [In] IntPtr wParam, [In] IntPtr lParam);
846 |
847 | ///
848 | /// Creates an overlapped, pop-up, or child window with an extended window style; otherwise,
849 | /// this function is identical to the CreateWindow function. For more information about
850 | /// creating a window and for full descriptions of the other parameters of CreateWindowEx, see CreateWindow.
851 | ///
852 | /// The extended window style of the window being created.
853 | /// A null-terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassEx function.
854 | /// The window name. If the window style specifies a title bar, the window title pointed to by lpWindowName is displayed in the title bar.
855 | /// The style of the window being created. This parameter can be a combination of the window style values, plus the control styles indicated in the Remarks section.
856 | /// The initial horizontal position of the window. For an overlapped or pop-up window, the x parameter is the initial x-coordinate of the window's upper-left corner, in screen coordinates.
857 | /// The initial vertical position of the window. For an overlapped or pop-up window, the y parameter is the initial y-coordinate of the window's upper-left corner, in screen coordinates.
858 | /// The width, in device units, of the window. For overlapped windows, nWidth is the window's width, in screen coordinates, or CW_USEDEFAULT.
859 | /// The height, in device units, of the window. For overlapped windows, nHeight is the window's height, in screen coordinates. If the nWidth parameter is set to CW_USEDEFAULT, the system ignores nHeight.
860 | /// A handle to the parent or owner window of the window being created. To create a child window or an owned window, supply a valid window handle. This parameter is optional for pop-up windows.
861 | /// A handle to a menu, or specifies a child-window identifier, depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used.
862 | /// A handle to the instance of the module to be associated with the window.
863 | /// Pointer to a value to be passed to the window through the CREATESTRUCT structure (lpCreateParams member) pointed to by the lParam param of the WM_CREATE message. This message is sent to the created window by this function before it returns.
864 | /// If the function succeeds, the return value is a handle to the new window.
865 | [DllImport(Libraries.User32, SetLastError = true, CharSet = CharSet.Unicode)]
866 | public static extern IntPtr CreateWindowExW(
867 | [In] WS_EX dwExStyle,
868 | [In, Optional] [MarshalAs(UnmanagedType.LPWStr)]
869 | string lpClassName,
870 | [In, Optional] [MarshalAs(UnmanagedType.LPWStr)]
871 | string lpWindowName,
872 | [In] WS dwStyle,
873 | [In] int x,
874 | [In] int y,
875 | [In] int nWidth,
876 | [In] int nHeight,
877 | [In, Optional] IntPtr hWndParent,
878 | [In, Optional] IntPtr hMenu,
879 | [In, Optional] IntPtr hInstance,
880 | [In, Optional] IntPtr lpParam);
881 |
882 | ///
883 | /// Creates an overlapped, pop-up, or child window with an extended window style; otherwise,
884 | /// this function is identical to the CreateWindow function. For more information about
885 | /// creating a window and for full descriptions of the other parameters of CreateWindowEx, see CreateWindow.
886 | ///
887 | /// The extended window style of the window being created.
888 | /// A null-terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassEx function.
889 | /// The window name. If the window style specifies a title bar, the window title pointed to by lpWindowName is displayed in the title bar.
890 | /// The style of the window being created. This parameter can be a combination of the window style values, plus the control styles indicated in the Remarks section.
891 | /// The initial horizontal position of the window. For an overlapped or pop-up window, the x parameter is the initial x-coordinate of the window's upper-left corner, in screen coordinates.
892 | /// The initial vertical position of the window. For an overlapped or pop-up window, the y parameter is the initial y-coordinate of the window's upper-left corner, in screen coordinates.
893 | /// The width, in device units, of the window. For overlapped windows, nWidth is the window's width, in screen coordinates, or CW_USEDEFAULT.
894 | /// The height, in device units, of the window. For overlapped windows, nHeight is the window's height, in screen coordinates. If the nWidth parameter is set to CW_USEDEFAULT, the system ignores nHeight.
895 | /// A handle to the parent or owner window of the window being created. To create a child window or an owned window, supply a valid window handle. This parameter is optional for pop-up windows.
896 | /// A handle to a menu, or specifies a child-window identifier, depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used.
897 | /// A handle to the instance of the module to be associated with the window.
898 | /// Pointer to a value to be passed to the window through the CREATESTRUCT structure (lpCreateParams member) pointed to by the lParam param of the WM_CREATE message. This message is sent to the created window by this function before it returns.
899 | /// If the function succeeds, the return value is a handle to the new window.
900 | public static IntPtr CreateWindowEx(
901 | [In] WS_EX dwExStyle,
902 | [In] string lpClassName,
903 | [In] string lpWindowName,
904 | [In] WS dwStyle,
905 | [In] int x,
906 | [In] int y,
907 | [In] int nWidth,
908 | [In] int nHeight,
909 | [In, Optional] IntPtr hWndParent,
910 | [In, Optional] IntPtr hMenu,
911 | [In, Optional] IntPtr hInstance,
912 | [In, Optional] IntPtr lpParam)
913 | {
914 | IntPtr ret = CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent,
915 | hMenu, hInstance, lpParam);
916 | if (IntPtr.Zero == ret)
917 | {
918 | throw new Exception("Unable to create a window");
919 | // HRESULT.ThrowLastError();
920 | }
921 |
922 | return ret;
923 | }
924 |
925 | ///
926 | /// Registers a window class for subsequent use in calls to the CreateWindow or CreateWindowEx function.
927 | /// Unicode declaration for
928 | ///
929 | /// A pointer to a structure. You must fill the structure with the appropriate class attributes before passing it to the function.
930 | /// If the function succeeds, the return value is a class atom that uniquely identifies the class being registered.
931 | [DllImport(Libraries.User32, SetLastError = true, CharSet = CharSet.Unicode)]
932 | private static extern short RegisterClassExW([In] ref WNDCLASSEX lpwcx);
933 |
934 | ///
935 | /// Registers a window class for subsequent use in calls to the CreateWindow or CreateWindowEx function.
936 | /// ANSI declaration for
937 | ///
938 | /// A pointer to a structure. You must fill the structure with the appropriate class attributes before passing it to the function.
939 | /// If the function succeeds, the return value is a class atom that uniquely identifies the class being registered.
940 | [DllImport(Libraries.User32, SetLastError = true)]
941 | private static extern short RegisterClassExA([In] ref WNDCLASSEX lpwcx);
942 |
943 | ///
944 | /// Registers a window class for subsequent use in calls to the CreateWindow or CreateWindowEx function.
945 | ///
946 | /// A pointer to a structure. You must fill the structure with the appropriate class attributes before passing it to the function.
947 | /// If the function succeeds, the return value is a class atom that uniquely identifies the class being registered.
948 | [DllImport(Libraries.User32, SetLastError = true)]
949 | private static extern short RegisterClassEx([In] ref WNDCLASSEX lpwcx);
950 |
951 | ///
952 | /// Calls the default window procedure to provide default processing for any window messages that an application does not process.
953 | /// This function ensures that every message is processed. DefWindowProc is called with the same parameters received by the window procedure.
954 | /// Unicode declaration for
955 | ///
956 | /// A handle to the window procedure that received the message.
957 | /// The message.
958 | /// Additional message information. The content of this parameter depends on the value of the Msg parameter.
959 | /// Additional message information. The content of this parameter depends on the value of the Msg parameter.
960 | /// The return value is the result of the message processing and depends on the message.
961 | [DllImport(Libraries.User32, CharSet = CharSet.Unicode)]
962 | public static extern IntPtr DefWindowProcW([In] IntPtr hWnd, [In] WM Msg, [In] IntPtr wParam, [In] IntPtr lParam);
963 |
964 | ///
965 | /// Calls the default window procedure to provide default processing for any window messages that an application does not process.
966 | /// This function ensures that every message is processed. DefWindowProc is called with the same parameters received by the window procedure.
967 | /// ANSI declaration for
968 | ///
969 | /// A handle to the window procedure that received the message.
970 | /// The message.
971 | /// Additional message information. The content of this parameter depends on the value of the Msg parameter.
972 | /// Additional message information. The content of this parameter depends on the value of the Msg parameter.
973 | /// The return value is the result of the message processing and depends on the message.
974 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
975 | public static extern IntPtr DefWindowProcA([In] IntPtr hWnd, [In] WM Msg, [In] IntPtr wParam, [In] IntPtr lParam);
976 |
977 | ///
978 | /// Calls the default window procedure to provide default processing for any window messages that an application does not process.
979 | /// This function ensures that every message is processed. DefWindowProc is called with the same parameters received by the window procedure.
980 | ///
981 | /// A handle to the window procedure that received the message.
982 | /// The message.
983 | /// Additional message information. The content of this parameter depends on the value of the Msg parameter.
984 | /// Additional message information. The content of this parameter depends on the value of the Msg parameter.
985 | /// The return value is the result of the message processing and depends on the message.
986 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
987 | public static extern IntPtr DefWindowProc([In] IntPtr hWnd, [In] WM Msg, [In] IntPtr wParam, [In] IntPtr lParam);
988 |
989 | ///
990 | /// Retrieves information about the specified window. The function also retrieves the 32-bit (DWORD) value at the specified offset into the extra window memory.
991 | /// If you are retrieving a pointer or a handle, this function has been superseded by the function.
992 | /// Unicode declaration for
993 | ///
994 | /// A handle to the window and, indirectly, the class to which the window belongs.
995 | /// The zero-based offset to the value to be retrieved.
996 | /// If the function succeeds, the return value is the requested value.
997 | [DllImport(Libraries.User32, CharSet = CharSet.Unicode)]
998 | public static extern int GetWindowLongW([In] IntPtr hWnd, [In] int nIndex);
999 |
1000 | ///
1001 | /// Retrieves information about the specified window. The function also retrieves the 32-bit (DWORD) value at the specified offset into the extra window memory.
1002 | /// If you are retrieving a pointer or a handle, this function has been superseded by the function.
1003 | /// ANSI declaration for
1004 | ///
1005 | /// A handle to the window and, indirectly, the class to which the window belongs.
1006 | /// The zero-based offset to the value to be retrieved.
1007 | /// If the function succeeds, the return value is the requested value.
1008 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1009 | public static extern int GetWindowLongA([In] IntPtr hWnd, [In] int nIndex);
1010 |
1011 | ///
1012 | /// Retrieves information about the specified window. The function also retrieves the 32-bit (DWORD) value at the specified offset into the extra window memory.
1013 | /// If you are retrieving a pointer or a handle, this function has been superseded by the function.
1014 | ///
1015 | /// A handle to the window and, indirectly, the class to which the window belongs.
1016 | /// The zero-based offset to the value to be retrieved.
1017 | /// If the function succeeds, the return value is the requested value.
1018 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1019 | public static extern int GetWindowLong([In] IntPtr hWnd, [In] int nIndex);
1020 |
1021 | ///
1022 | /// Retrieves information about the specified window. The function also retrieves the 32-bit (DWORD) value at the specified offset into the extra window memory.
1023 | /// If you are retrieving a pointer or a handle, this function has been superseded by the function.
1024 | ///
1025 | /// A handle to the window and, indirectly, the class to which the window belongs.
1026 | /// The zero-based offset to the value to be retrieved.
1027 | /// If the function succeeds, the return value is the requested value.
1028 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1029 | public static extern int GetWindowLong([In] IntPtr hWnd, [In] GWL nIndex);
1030 |
1031 | ///
1032 | /// Retrieves information about the specified window. The function also retrieves the value at a specified offset into the extra window memory.
1033 | /// Unicode declaration for
1034 | ///
1035 | /// A handle to the window and, indirectly, the class to which the window belongs.
1036 | /// The zero-based offset to the value to be retrieved.
1037 | /// If the function succeeds, the return value is the requested value.
1038 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1039 | public static extern int GetWindowLongPtrW([In] IntPtr hWnd, [In] int nIndex);
1040 |
1041 | ///
1042 | /// Retrieves information about the specified window. The function also retrieves the value at a specified offset into the extra window memory.
1043 | /// ANSI declaration for
1044 | ///
1045 | /// A handle to the window and, indirectly, the class to which the window belongs.
1046 | /// The zero-based offset to the value to be retrieved.
1047 | /// If the function succeeds, the return value is the requested value.
1048 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1049 | public static extern int GetWindowLongPtrA([In] IntPtr hWnd, [In] int nIndex);
1050 |
1051 | ///
1052 | /// Retrieves information about the specified window. The function also retrieves the value at a specified offset into the extra window memory.
1053 | ///
1054 | /// A handle to the window and, indirectly, the class to which the window belongs.
1055 | /// The zero-based offset to the value to be retrieved.
1056 | /// If the function succeeds, the return value is the requested value.
1057 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1058 | public static extern int GetWindowLongPtr([In] IntPtr hWnd, [In] int nIndex);
1059 |
1060 | ///
1061 | /// Changes an attribute of the specified window. The function also sets the 32-bit (long) value at the specified offset into the extra window memory.
1062 | /// Note: This function has been superseded by the function. To write code that is compatible with both 32-bit and 64-bit versions of Windows, use the SetWindowLongPtr function.
1063 | /// Unicode declaration for
1064 | ///
1065 | /// A handle to the window and, indirectly, the class to which the window belongs.
1066 | /// The zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window memory, minus the size of an integer.
1067 | /// The replacement value.
1068 | /// If the function succeeds, the return value is the previous value of the specified 32-bit integer.
1069 | [DllImport(Libraries.User32, CharSet = CharSet.Unicode)]
1070 | public static extern int SetWindowLongW([In] IntPtr hWnd, [In] int nIndex, [In] long dwNewLong);
1071 |
1072 | ///
1073 | /// Changes an attribute of the specified window. The function also sets the 32-bit (long) value at the specified offset into the extra window memory.
1074 | /// Note: This function has been superseded by the function. To write code that is compatible with both 32-bit and 64-bit versions of Windows, use the SetWindowLongPtr function.
1075 | /// ANSI declaration for
1076 | ///
1077 | /// A handle to the window and, indirectly, the class to which the window belongs.
1078 | /// The zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window memory, minus the size of an integer.
1079 | /// The replacement value.
1080 | /// If the function succeeds, the return value is the previous value of the specified 32-bit integer.
1081 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1082 | public static extern int SetWindowLongA([In] IntPtr hWnd, [In] int nIndex, [In] long dwNewLong);
1083 |
1084 | ///
1085 | /// Changes an attribute of the specified window. The function also sets the 32-bit (long) value at the specified offset into the extra window memory.
1086 | /// Note: This function has been superseded by the function. To write code that is compatible with both 32-bit and 64-bit versions of Windows, use the SetWindowLongPtr function.
1087 | /// ANSI declaration for
1088 | ///
1089 | /// A handle to the window and, indirectly, the class to which the window belongs.
1090 | /// The zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window memory, minus the size of an integer.
1091 | /// The replacement value.
1092 | /// If the function succeeds, the return value is the previous value of the specified 32-bit integer.
1093 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1094 | public static extern int SetWindowLong([In] IntPtr hWnd, [In] int nIndex, [In] long dwNewLong);
1095 |
1096 | ///
1097 | /// Changes an attribute of the specified window. The function also sets the 32-bit (long) value at the specified offset into the extra window memory.
1098 | /// Note: This function has been superseded by the function. To write code that is compatible with both 32-bit and 64-bit versions of Windows, use the SetWindowLongPtr function.
1099 | /// ANSI declaration for
1100 | ///
1101 | /// A handle to the window and, indirectly, the class to which the window belongs.
1102 | /// The zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window memory, minus the size of an integer.
1103 | /// The replacement value.
1104 | /// If the function succeeds, the return value is the previous value of the specified 32-bit integer.
1105 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1106 | public static extern int SetWindowLong([In] IntPtr hWnd, [In] GWL nIndex, [In] long dwNewLong);
1107 |
1108 | ///
1109 | /// Changes an attribute of the specified window. The function also sets a value at the specified offset in the extra window memory.
1110 | /// Unicode declaration for
1111 | ///
1112 | /// A handle to the window and, indirectly, the class to which the window belongs.
1113 | /// The zero-based offset to the value to be set.
1114 | /// The replacement value.
1115 | /// If the function succeeds, the return value is the previous value of the specified offset.
1116 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1117 | private static extern IntPtr SetWindowLongPtrW([In] IntPtr hWnd, [In] int nIndex, [In] IntPtr dwNewLong);
1118 |
1119 | ///
1120 | /// Changes an attribute of the specified window. The function also sets a value at the specified offset in the extra window memory.
1121 | /// ANSI declaration for
1122 | ///
1123 | /// A handle to the window and, indirectly, the class to which the window belongs.
1124 | /// The zero-based offset to the value to be set.
1125 | /// The replacement value.
1126 | /// If the function succeeds, the return value is the previous value of the specified offset.
1127 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1128 | private static extern IntPtr SetWindowLongPtrA([In] IntPtr hWnd, [In] int nIndex, [In] IntPtr dwNewLong);
1129 |
1130 | ///
1131 | /// Changes an attribute of the specified window. The function also sets a value at the specified offset in the extra window memory.
1132 | ///
1133 | /// A handle to the window and, indirectly, the class to which the window belongs.
1134 | /// The zero-based offset to the value to be set.
1135 | /// The replacement value.
1136 | /// If the function succeeds, the return value is the previous value of the specified offset.
1137 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1138 | private static extern IntPtr SetWindowLongPtr([In] IntPtr hWnd, [In] int nIndex, [In] IntPtr dwNewLong);
1139 |
1140 | ///
1141 | /// Destroys an icon and frees any memory the icon occupied.
1142 | ///
1143 | /// A handle to the icon to be destroyed. The icon must not be in use.
1144 | /// If the function succeeds, the return value is nonzero.
1145 | [DllImport(Libraries.User32)]
1146 | [return: MarshalAs(UnmanagedType.Bool)]
1147 | public static extern bool DestroyIcon([In] IntPtr handle);
1148 |
1149 | ///
1150 | /// Determines whether the specified window handle identifies an existing window.
1151 | ///
1152 | /// A handle to the window to be tested.
1153 | /// If the window handle identifies an existing window, the return value is nonzero.
1154 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1155 | [return: MarshalAs(UnmanagedType.Bool)]
1156 | public static extern bool IsWindow([In] IntPtr hWnd);
1157 |
1158 | ///
1159 | /// Destroys the specified window. The function sends WM_DESTROY and WM_NCDESTROY messages to the window to deactivate it and remove the keyboard focus from it.
1160 | ///
1161 | /// A handle to the window to be destroyed.
1162 | /// If the function succeeds, the return value is nonzero.
1163 | [DllImport(Libraries.User32, CharSet = CharSet.Auto, SetLastError = true)]
1164 | [return: MarshalAs(UnmanagedType.Bool)]
1165 | public static extern bool DestroyWindow([In] IntPtr hWnd);
1166 |
1167 | ///
1168 | /// Retrieves the show state and the restored, minimized, and maximized positions of the specified window.
1169 | ///
1170 | /// A handle to the window.
1171 | /// A pointer to the structure that receives the show state and position information. Before calling GetWindowPlacement, set the length member to sizeof(WINDOWPLACEMENT). GetWindowPlacement fails if lpwndpl-> length is not set correctly.
1172 | /// If the function succeeds, the return value is nonzero.
1173 | [DllImport(Libraries.User32, SetLastError = true)]
1174 | [return: MarshalAs(UnmanagedType.Bool)]
1175 | public static extern bool GetWindowPlacement([In] IntPtr hWnd, [In] WINDOWPLACEMENT lpwndpl);
1176 |
1177 | ///
1178 | /// Retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
1179 | ///
1180 | /// A handle to the window.
1181 | /// A pointer to a RECT structure that receives the screen coordinates of the upper-left and lower-right corners of the window.
1182 | /// If the function succeeds, the return value is nonzero.
1183 | [DllImport(Libraries.User32, SetLastError = true)]
1184 | [return: MarshalAs(UnmanagedType.Bool)]
1185 | public static extern bool GetWindowRect([In] IntPtr hWnd, [Out] out RECT lpRect);
1186 |
1187 | ///
1188 | /// Determines the visibility state of the specified window.
1189 | ///
1190 | /// A handle to the window to be tested.
1191 | /// If the specified window, its parent window, its parent's parent window, and so forth, have the WS_VISIBLE style, the return value is nonzero. Otherwise, the return value is zero.
1192 | [DllImport(Libraries.User32)]
1193 | [return: MarshalAs(UnmanagedType.Bool)]
1194 | public static extern bool IsWindowVisible([In] IntPtr hWnd);
1195 |
1196 | ///
1197 | /// The MonitorFromWindow function retrieves a handle to the display monitor that has the largest area of intersection with the bounding rectangle of a specified window.
1198 | ///
1199 | /// A handle to the window of interest.
1200 | /// Determines the function's return value if the window does not intersect any display monitor.
1201 | /// If the window intersects one or more display monitor rectangles, the return value is an HMONITOR handle to the display monitor that has the largest area of intersection with the window.
1202 | [DllImport(Libraries.User32)]
1203 | public static extern IntPtr MonitorFromWindow(IntPtr hWnd, uint dwFlags);
1204 |
1205 | ///
1206 | /// Retrieves the specified system metric or system configuration setting.
1207 | /// Note that all dimensions retrieved by GetSystemMetrics are in pixels.
1208 | ///
1209 | /// The system metric or configuration setting to be retrieved. This parameter can be one of the values.
1210 | /// Note that all SM_CX* values are widths and all SM_CY* values are heights. Also note that all settings designed to return Boolean data represent as any nonzero value, and as a zero value.
1211 | /// If the function succeeds, the return value is the requested system metric or configuration setting.
1212 | [DllImport(Libraries.User32)]
1213 | public static extern int GetSystemMetrics([In] SM nIndex);
1214 |
1215 | ///
1216 | /// Defines a new window message that is guaranteed to be unique throughout the system. The message value can be used when sending or posting messages.
1217 | /// Unicode declaration for
1218 | ///
1219 | /// The message to be registered.
1220 | /// If the message is successfully registered, the return value is a message identifier in the range 0xC000 through 0xFFFF.
1221 | [DllImport(Libraries.User32, SetLastError = true, CharSet = CharSet.Unicode)]
1222 | public static extern uint RegisterWindowMessageW([MarshalAs(UnmanagedType.LPWStr)] string lpString);
1223 |
1224 | ///
1225 | /// Defines a new window message that is guaranteed to be unique throughout the system. The message value can be used when sending or posting messages.
1226 | /// ANSI declaration for
1227 | ///
1228 | /// The message to be registered.
1229 | /// If the message is successfully registered, the return value is a message identifier in the range 0xC000 through 0xFFFF.
1230 | [DllImport(Libraries.User32, SetLastError = true, CharSet = CharSet.Auto)]
1231 | public static extern uint RegisterWindowMessageA([MarshalAs(UnmanagedType.LPWStr)] string lpString);
1232 |
1233 | ///
1234 | /// Defines a new window message that is guaranteed to be unique throughout the system. The message value can be used when sending or posting messages.
1235 | ///
1236 | /// The message to be registered.
1237 | /// If the message is successfully registered, the return value is a message identifier in the range 0xC000 through 0xFFFF.
1238 | [DllImport(Libraries.User32, SetLastError = true, CharSet = CharSet.Auto)]
1239 | public static extern uint RegisterWindowMessage([MarshalAs(UnmanagedType.LPWStr)] string lpString);
1240 |
1241 | ///
1242 | /// Activates a window. The window must be attached to the calling thread's message queue.
1243 | ///
1244 | /// A handle to the top-level window to be activated.
1245 | /// If the function succeeds, the return value is the handle to the window that was previously active.
1246 | [DllImport(Libraries.User32, SetLastError = true)]
1247 | public static extern IntPtr SetActiveWindow(IntPtr hWnd);
1248 |
1249 | ///
1250 | /// Brings the thread that created the specified window into the foreground and activates the window.
1251 | /// Keyboard input is directed to the window, and various visual cues are changed for the user.
1252 | /// The system assigns a slightly higher priority to the thread that created the foreground window than it does to other threads.
1253 | ///
1254 | /// A handle to the window that should be activated and brought to the foreground.
1255 | /// If the window was brought to the foreground, the return value is nonzero.
1256 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1257 | [return: MarshalAs(UnmanagedType.Bool)]
1258 | public static extern bool SetForegroundWindow(IntPtr hWnd);
1259 |
1260 | ///
1261 | /// Retrieves the position of the mouse cursor, in screen coordinates.
1262 | ///
1263 | /// A pointer to a structure that receives the screen coordinates of the cursor.
1264 | /// Returns nonzero if successful or zero otherwise. To get extended error information, call .
1265 | [DllImport(Libraries.User32, SetLastError = true)]
1266 | [return: MarshalAs(UnmanagedType.Bool)]
1267 | public static extern bool GetCursorPos([Out] out POINT lpPoint);
1268 |
1269 | ///
1270 | /// Sets various information regarding DWM window attributes.
1271 | ///
1272 | [DllImport(Libraries.User32, CharSet = CharSet.Auto)]
1273 | public static extern int SetWindowCompositionAttribute([In] IntPtr hWnd, [In] ref WINCOMPATTRDATA data);
1274 | }
1275 |
--------------------------------------------------------------------------------