Improved P/Invoke bindings for GetWindowLongPtr() and SetWindowLongPtr() functions.
This commit is contained in:
parent
7fee4f9bf3
commit
5759a0cd83
@ -325,9 +325,9 @@ namespace com.muldersoft.slunkcrypt.gui.utils.cpu
|
||||
|
||||
private static class Internal
|
||||
{
|
||||
const string DLL_NAME_X86 = "cpu-capabilities-x86.dll";
|
||||
const string DLL_NAME_X64 = "cpu-capabilities-x64.dll";
|
||||
const string DLL_KERNEL32 = "kernel32.dll";
|
||||
private const string DLL_NAME_X86 = "cpu-capabilities-x86.dll";
|
||||
private const string DLL_NAME_X64 = "cpu-capabilities-x64.dll";
|
||||
private const string DLL_KERNEL32 = "kernel32.dll";
|
||||
|
||||
/* GetCPUArchitecture() */
|
||||
[DllImport(DLL_NAME_X64, CallingConvention = CallingConvention.Cdecl)]
|
||||
@ -372,9 +372,9 @@ namespace com.muldersoft.slunkcrypt.gui.utils.cpu
|
||||
public static extern uint GetCPULibraryVersionX86();
|
||||
|
||||
/* IsWow64Process2() */
|
||||
[DllImport(DLL_KERNEL32, SetLastError = true)]
|
||||
[DllImport(DLL_KERNEL32, EntryPoint = "IsWow64Process2", ExactSpelling = true)]
|
||||
public static extern bool IsWow64Process2(IntPtr process, out ushort processMachine, out ushort nativeMachine);
|
||||
[DllImport(DLL_KERNEL32)]
|
||||
[DllImport(DLL_KERNEL32, EntryPoint = "GetCurrentProcess", ExactSpelling = true)]
|
||||
public static extern IntPtr GetCurrentProcess();
|
||||
}
|
||||
|
||||
|
@ -160,6 +160,8 @@ namespace com.muldersoft.slunkcrypt.gui.utils
|
||||
|
||||
private class Native
|
||||
{
|
||||
private const string DLL_USER32 = "user32.dll";
|
||||
|
||||
[Flags]
|
||||
public enum MenuFlags : uint
|
||||
{
|
||||
@ -171,13 +173,13 @@ namespace com.muldersoft.slunkcrypt.gui.utils
|
||||
MF_SEPARATOR = 0x0800
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "GetSystemMenu", ExactSpelling = true)]
|
||||
public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "AppendMenuW", ExactSpelling = true)]
|
||||
public static extern bool AppendMenu(IntPtr hMenu, MenuFlags uFlags, UIntPtr uIDNewItem, string lpNewItem);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "ModifyMenuW", ExactSpelling = true)]
|
||||
public static extern bool ModifyMenu(IntPtr hMenu, uint uPosition, MenuFlags uFlags, UIntPtr uIDNewItem, string lpNewItem);
|
||||
}
|
||||
}
|
||||
|
@ -35,14 +35,14 @@ namespace com.muldersoft.slunkcrypt.gui.utils
|
||||
if (!ReferenceEquals(window, null))
|
||||
{
|
||||
const int GWL_STYLE = -16;
|
||||
const uint WS_MAXIMIZEBOX = 0x10000;
|
||||
const ulong WS_MAXIMIZEBOX = 0x10000;
|
||||
try
|
||||
{
|
||||
WindowInteropHelper interopHelper = new WindowInteropHelper(window);
|
||||
uint value = NativeMethods.GetWindowLong(interopHelper.Handle, GWL_STYLE);
|
||||
if ((value & WS_MAXIMIZEBOX) != 0U)
|
||||
ulong value = NativeMethods.GetWindowLongPtr(interopHelper.Handle, GWL_STYLE);
|
||||
if (value != 0UL)
|
||||
{
|
||||
NativeMethods.SetWindowLong(interopHelper.Handle, GWL_STYLE, value & (~WS_MAXIMIZEBOX));
|
||||
NativeMethods.SetWindowLongPtr(interopHelper.Handle, GWL_STYLE, value & (~WS_MAXIMIZEBOX));
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
@ -51,17 +51,49 @@ namespace com.muldersoft.slunkcrypt.gui.utils
|
||||
|
||||
private static class NativeMethods
|
||||
{
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private const string DLL_USER32 = "user32.dll";
|
||||
|
||||
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "BringWindowToTop", ExactSpelling = true)]
|
||||
public static extern bool BringWindowToTop(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "SetForegroundWindow", ExactSpelling = true)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern uint GetWindowLong(IntPtr hWnd, int nIndex);
|
||||
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "GetWindowLongW", ExactSpelling = true)]
|
||||
private static extern UIntPtr GetWindowLongPtr32(IntPtr hWnd, int nIndex);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern uint SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
|
||||
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "GetWindowLongPtrW", ExactSpelling = true)]
|
||||
private static extern UIntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);
|
||||
|
||||
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "SetWindowLongW", ExactSpelling = true)]
|
||||
private static extern UIntPtr SetWindowLongPtr32(IntPtr hWnd, int nIndex, UIntPtr dwNewLong);
|
||||
|
||||
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "SetWindowLongPtrW", ExactSpelling = true)]
|
||||
private static extern UIntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, UIntPtr dwNewLong);
|
||||
|
||||
public static ulong GetWindowLongPtr(IntPtr hWnd, int nIndex)
|
||||
{
|
||||
if (IntPtr.Size >= 8)
|
||||
{
|
||||
return GetWindowLongPtr64(hWnd, nIndex).ToUInt64();
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetWindowLongPtr32(hWnd, nIndex).ToUInt64();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetWindowLongPtr(IntPtr hWnd, int nIndex, ulong dwNewLong)
|
||||
{
|
||||
if (IntPtr.Size >= 8)
|
||||
{
|
||||
SetWindowLongPtr64(hWnd, nIndex, new UIntPtr(dwNewLong));
|
||||
}
|
||||
else
|
||||
{
|
||||
SetWindowLongPtr32(hWnd, nIndex, new UIntPtr(dwNewLong));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user