Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f74f8da

Browse files
committed
Trying to deal with the CsWin32 NativeMethods.txt strange functionality
1 parent 44d1055 commit f74f8da

File tree

3 files changed

+249
-0
lines changed

3 files changed

+249
-0
lines changed
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
// ------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
// ------------------------------------------------------------------------------
9+
10+
#pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981
11+
using global::System;
12+
using global::System.Diagnostics;
13+
using global::System.Diagnostics.CodeAnalysis;
14+
using global::System.Runtime.CompilerServices;
15+
using global::System.Runtime.InteropServices;
16+
using winmdroot = global::Windows.Win32;
17+
[assembly: global::System.Reflection.AssemblyMetadata("Microsoft.Windows.CsWin32", "0.3.49-beta+91f5c15987")]
18+
namespace Windows.Win32
19+
{
20+
21+
/// <content>
22+
/// Contains extern methods from "KERNEL32.dll".
23+
/// </content>
24+
[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.49-beta+91f5c15987")]
25+
internal static partial class PInvoke
26+
{
27+
/// <summary>Closes an open object handle.</summary>
28+
/// <param name="hObject">A valid handle to an open object.</param>
29+
/// <returns>
30+
/// <para>If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>. If the application is running under a debugger, the function will throw an exception if it receives either a handle value that is not valid or a pseudo-handle value. This can happen if you close a handle twice, or if you call <b>CloseHandle</b> on a handle returned by the <a href="https://docs.microsoft.com/windows/desktop/api/fileapi/nf-fileapi-findfirstfilea">FindFirstFile</a> function instead of calling the <a href="https://docs.microsoft.com/windows/desktop/api/fileapi/nf-fileapi-findclose">FindClose</a> function.</para>
31+
/// </returns>
32+
/// <remarks>
33+
/// <para>The <b>CloseHandle</b> function closes handles to the following objects: </para>
34+
/// <para>This doc was truncated.</para>
35+
/// <para><see href="https://learn.microsoft.com/windows/win32/api/handleapi/nf-handleapi-closehandle#">Read more on docs.microsoft.com</see>.</para>
36+
/// </remarks>
37+
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
38+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
39+
internal static extern winmdroot.Foundation.BOOL CloseHandle(winmdroot.Foundation.HANDLE hObject);
40+
}
41+
42+
43+
/// <content>
44+
/// Contains extern methods from "USER32.dll".
45+
/// </content>
46+
internal static partial class PInvoke
47+
{
48+
/// <summary>Changes the parent window of the specified child window.</summary>
49+
/// <param name="hWndChild">
50+
/// <para>Type: <b>HWND</b> A handle to the child window.</para>
51+
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-setparent#parameters">Read more on docs.microsoft.com</see>.</para>
52+
/// </param>
53+
/// <param name="hWndNewParent">
54+
/// <para>Type: <b>HWND</b> A handle to the new parent window. If this parameter is <b>NULL</b>, the desktop window becomes the new parent window. If this parameter is <b>HWND_MESSAGE</b>, the child window becomes a <a href="https://docs.microsoft.com/windows/desktop/winmsg/window-features">message-only window</a>.</para>
55+
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-setparent#parameters">Read more on docs.microsoft.com</see>.</para>
56+
/// </param>
57+
/// <returns>
58+
/// <para>Type: <b>HWND</b> If the function succeeds, the return value is a handle to the previous parent window. If the function fails, the return value is <b>NULL</b>. To get extended error information, call <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>.</para>
59+
/// </returns>
60+
/// <remarks>
61+
/// <para>An application can use the <b>SetParent</b> function to set the parent window of a pop-up, overlapped, or child window. If the window identified by the <i>hWndChild</i> parameter is visible, the system performs the appropriate redrawing and repainting. For compatibility reasons, <b>SetParent</b> does not modify the <b>WS_CHILD</b> or <b>WS_POPUP</b> window styles of the window whose parent is being changed. Therefore, if <i>hWndNewParent</i> is <b>NULL</b>, you should also clear the <b>WS_CHILD</b> bit and set the <b>WS_POPUP</b> style after calling <b>SetParent</b>. Conversely, if <i>hWndNewParent</i> is not <b>NULL</b> and the window was previously a child of the desktop, you should clear the <b>WS_POPUP</b> style and set the <b>WS_CHILD</b> style before calling <b>SetParent</b>. When you change the parent of a window, you should synchronize the UISTATE of both windows. For more information, see <a href="https://docs.microsoft.com/windows/desktop/menurc/wm-changeuistate">WM_CHANGEUISTATE</a> and <a href="https://docs.microsoft.com/windows/desktop/menurc/wm-updateuistate">WM_UPDATEUISTATE</a>. Unexpected behavior or errors may occur if <i>hWndNewParent</i> and <i>hWndChild</i> are running in different DPI awareness modes. The table below outlines this behavior: </para>
62+
/// <para>This doc was truncated.</para>
63+
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-setparent#">Read more on docs.microsoft.com</see>.</para>
64+
/// </remarks>
65+
[DllImport("USER32.dll", ExactSpelling = true, SetLastError = true)]
66+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
67+
internal static extern winmdroot.Foundation.HWND SetParent(winmdroot.Foundation.HWND hWndChild, winmdroot.Foundation.HWND hWndNewParent);
68+
69+
/// <summary>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. (Unicode)</summary>
70+
/// <param name="hWnd">
71+
/// <para>Type: <b>HWND</b> A handle to the window and, indirectly, the class to which the window belongs.</para>
72+
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-setwindowlongw#parameters">Read more on docs.microsoft.com</see>.</para>
73+
/// </param>
74+
/// <param name="nIndex">Type: <b>int</b></param>
75+
/// <param name="dwNewLong">
76+
/// <para>Type: <b>LONG</b> The replacement value.</para>
77+
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-setwindowlongw#parameters">Read more on docs.microsoft.com</see>.</para>
78+
/// </param>
79+
/// <returns>
80+
/// <para>Type: <b>LONG</b> If the function succeeds, the return value is the previous value of the specified 32-bit integer. If the function fails, the return value is zero. To get extended error information, call <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>. If the previous value of the specified 32-bit integer is zero, and the function succeeds, the return value is zero, but the function does not clear the last error information. This makes it difficult to determine success or failure. To deal with this, you should clear the last error information by calling <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-setlasterror">SetLastError</a> with 0 before calling <b>SetWindowLong</b>. Then, function failure will be indicated by a return value of zero and a <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a> result that is nonzero.</para>
81+
/// </returns>
82+
/// <remarks>
83+
/// <para>Certain window data is cached, so changes you make using <b>SetWindowLong</b> will not take effect until you call the <a href="https://docs.microsoft.com/windows/desktop/api/winuser/nf-winuser-setwindowpos">SetWindowPos</a> function. Specifically, if you change any of the frame styles, you must call <b>SetWindowPos</b> with the <b>SWP_FRAMECHANGED</b> flag for the cache to be updated properly. If you use <b>SetWindowLong</b> with the <b>GWL_WNDPROC</b> index to replace the window procedure, the window procedure must conform to the guidelines specified in the description of the <a href="https://docs.microsoft.com/previous-versions/windows/desktop/legacy/ms633573(v=vs.85)">WindowProc</a> callback function. If you use <b>SetWindowLong</b> with the <b>DWL_MSGRESULT</b> index to set the return value for a message processed by a dialog procedure, you should return <b>TRUE</b> directly afterward. Otherwise, if you call any function that results in your dialog procedure receiving a window message, the nested window message could overwrite the return value you set using <b>DWL_MSGRESULT</b>. Calling <b>SetWindowLong</b> with the <b>GWL_WNDPROC</b> index creates a subclass of the window class used to create the window. An application can subclass a system class, but should not subclass a window class created by another process. The <b>SetWindowLong</b> function creates the window subclass by changing the window procedure associated with a particular window class, causing the system to call the new window procedure instead of the previous one. An application must pass any messages not processed by the new window procedure to the previous window procedure by calling <a href="https://docs.microsoft.com/windows/desktop/api/winuser/nf-winuser-callwindowproca">CallWindowProc</a>. This allows the application to create a chain of window procedures. Reserve extra window memory by specifying a nonzero value in the <b>cbWndExtra</b> member of the <a href="https://docs.microsoft.com/windows/desktop/api/winuser/ns-winuser-wndclassexa">WNDCLASSEX</a> structure used with the <a href="https://docs.microsoft.com/windows/desktop/api/winuser/nf-winuser-registerclassexa">RegisterClassEx</a> function. You must not call <b>SetWindowLong</b> with the <b>GWL_HWNDPARENT</b> index to change the parent of a child window. Instead, use the <a href="https://docs.microsoft.com/windows/desktop/api/winuser/nf-winuser-setparent">SetParent</a> function. If the window has a class style of <b>CS_CLASSDC</b> or <b>CS_OWNDC</b>, do not set the extended window styles <b>WS_EX_COMPOSITED</b> or <b>WS_EX_LAYERED</b>. Calling <b>SetWindowLong</b> to set the style on a progressbar will reset its position.</para>
84+
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-setwindowlongw#">Read more on docs.microsoft.com</see>.</para>
85+
/// </remarks>
86+
[DllImport("USER32.dll", ExactSpelling = true, EntryPoint = "SetWindowLongW", SetLastError = true)]
87+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
88+
internal static extern int SetWindowLong(winmdroot.Foundation.HWND hWnd, winmdroot.UI.WindowsAndMessaging.WINDOW_LONG_PTR_INDEX nIndex, int dwNewLong);
89+
}
90+
91+
namespace Foundation
92+
{
93+
[DebuggerDisplay("{Value}")]
94+
[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.49-beta+91f5c15987")]
95+
internal readonly partial struct BOOL
96+
: IEquatable<BOOL>
97+
{
98+
internal readonly int Value;
99+
100+
internal BOOL(int value) => this.Value = value;
101+
102+
public static implicit operator int(BOOL value) => value.Value;
103+
104+
public static explicit operator BOOL(int value) => new BOOL(value);
105+
106+
public static bool operator ==(BOOL left, BOOL right) => left.Value == right.Value;
107+
108+
public static bool operator !=(BOOL left, BOOL right) => !(left == right);
109+
110+
public bool Equals(BOOL other) => this.Value == other.Value;
111+
112+
public override bool Equals(object obj) => obj is BOOL other && this.Equals(other);
113+
114+
public override int GetHashCode() => this.Value.GetHashCode();
115+
116+
public override string ToString() => $"0x{this.Value:x}";
117+
118+
internal BOOL(bool value) => this.Value = value ? 1 : 0;
119+
120+
public static implicit operator bool(BOOL value) => value.Value != 0;
121+
122+
public static implicit operator BOOL(bool value) => new BOOL(value);
123+
}
124+
125+
[DebuggerDisplay("{Value}")]
126+
[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.49-beta+91f5c15987")]
127+
internal readonly partial struct HANDLE
128+
: IEquatable<HANDLE>
129+
{
130+
internal readonly IntPtr Value;
131+
132+
internal HANDLE(IntPtr value) => this.Value = value;
133+
134+
internal static HANDLE Null => default;
135+
136+
internal bool IsNull => Value == default;
137+
138+
public static implicit operator IntPtr(HANDLE value) => value.Value;
139+
140+
public static explicit operator HANDLE(IntPtr value) => new HANDLE(value);
141+
142+
public static bool operator ==(HANDLE left, HANDLE right) => left.Value == right.Value;
143+
144+
public static bool operator !=(HANDLE left, HANDLE right) => !(left == right);
145+
146+
public bool Equals(HANDLE other) => this.Value == other.Value;
147+
148+
public override bool Equals(object obj) => obj is HANDLE other && this.Equals(other);
149+
150+
public override int GetHashCode() => this.Value.GetHashCode();
151+
152+
public override string ToString() => $"0x{this.Value:x}";
153+
}
154+
155+
[DebuggerDisplay("{Value}")]
156+
[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.49-beta+91f5c15987")]
157+
internal readonly partial struct HWND
158+
: IEquatable<HWND>
159+
{
160+
internal readonly IntPtr Value;
161+
162+
internal HWND(IntPtr value) => this.Value = value;
163+
164+
internal static HWND Null => default;
165+
166+
internal bool IsNull => Value == default;
167+
168+
public static implicit operator IntPtr(HWND value) => value.Value;
169+
170+
public static explicit operator HWND(IntPtr value) => new HWND(value);
171+
172+
public static bool operator ==(HWND left, HWND right) => left.Value == right.Value;
173+
174+
public static bool operator !=(HWND left, HWND right) => !(left == right);
175+
176+
public bool Equals(HWND other) => this.Value == other.Value;
177+
178+
public override bool Equals(object obj) => obj is HWND other && this.Equals(other);
179+
180+
public override int GetHashCode() => this.Value.GetHashCode();
181+
182+
public override string ToString() => $"0x{this.Value:x}";
183+
184+
public static implicit operator HANDLE(HWND value) => new HANDLE(value.Value);
185+
}
186+
}
187+
188+
namespace UI.WindowsAndMessaging
189+
{
190+
[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.49-beta+91f5c15987")]
191+
internal enum WINDOW_LONG_PTR_INDEX
192+
{
193+
GWL_EXSTYLE = -20,
194+
GWLP_HINSTANCE = -6,
195+
GWLP_HWNDPARENT = -8,
196+
GWLP_ID = -12,
197+
GWL_STYLE = -16,
198+
GWLP_USERDATA = -21,
199+
GWLP_WNDPROC = -4,
200+
GWL_HINSTANCE = -6,
201+
GWL_ID = -12,
202+
GWL_USERDATA = -21,
203+
GWL_WNDPROC = -4,
204+
GWL_HWNDPARENT = -8,
205+
}
206+
207+
[Flags]
208+
[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.49-beta+91f5c15987")]
209+
internal enum WINDOW_STYLE : uint
210+
{
211+
WS_OVERLAPPED = 0x00000000,
212+
WS_POPUP = 0x80000000,
213+
WS_CHILD = 0x40000000,
214+
WS_MINIMIZE = 0x20000000,
215+
WS_VISIBLE = 0x10000000,
216+
WS_DISABLED = 0x08000000,
217+
WS_CLIPSIBLINGS = 0x04000000,
218+
WS_CLIPCHILDREN = 0x02000000,
219+
WS_MAXIMIZE = 0x01000000,
220+
WS_CAPTION = 0x00C00000,
221+
WS_BORDER = 0x00800000,
222+
WS_DLGFRAME = 0x00400000,
223+
WS_VSCROLL = 0x00200000,
224+
WS_HSCROLL = 0x00100000,
225+
WS_SYSMENU = 0x00080000,
226+
WS_THICKFRAME = 0x00040000,
227+
WS_GROUP = 0x00020000,
228+
WS_TABSTOP = 0x00010000,
229+
WS_MINIMIZEBOX = 0x00020000,
230+
WS_MAXIMIZEBOX = 0x00010000,
231+
WS_TILED = 0x00000000,
232+
WS_ICONIC = 0x20000000,
233+
WS_SIZEBOX = 0x00040000,
234+
WS_TILEDWINDOW = 0x00CF0000,
235+
WS_OVERLAPPEDWINDOW = 0x00CF0000,
236+
WS_POPUPWINDOW = 0x80880000,
237+
WS_CHILDWINDOW = 0x40000000,
238+
WS_ACTIVECAPTION = 0x00000001,
239+
}
240+
}
241+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://aka.ms/CsWin32.schema.json",
3+
"emitSingleFile": true
4+
}

Source/Contrib/TrackViewer/NativeMethods.txt renamed to Source/Contrib/TrackViewer/NativeMethods__.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// source code generator, telling that what native functions to generate.
33
// Check the result in the project/Dependencies/Analyzers/Microsoft.Windows.CsWin32
44
// in the Visual Studio Solution Explorer.
5+
//
6+
// Name this file back to NativeMethods.txt to re-enable automatic code generation.
7+
// Disabled because when active, the file exists only virtually in Visual Studio,
8+
// thus impossible to include into the git repository.
59

610
SetParent
711
SetWindowLong

0 commit comments

Comments
 (0)