public static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
{
if (IntPtr.Size == 4)
{
return SetWindowLongPtr32(hWnd, nIndex, dwNewLong);
}
return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
}
[DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
public static extern IntPtr SetWindowLongPtr32(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Auto)]
public static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
public static IntPtr GetWindowLong(IntPtr hWnd, int nIndex)
{
if (IntPtr.Size == 4)
{
return GetWindowLong32(hWnd, nIndex);
}
return GetWindowLongPtr64(hWnd, nIndex);
}
[DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
private static extern IntPtr GetWindowLong32(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Auto)]
private static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);
private const int GWL_STYLE = -16;
// 右上角 X 按鈕
private const int WS_SYSMENU = 0x00080000;
// 右上角 最小化、最大化 按鈕
private const int MaximizeIcon = 0x10000;
private const int MinimizeIcon = 0x20000;
---------------------------------------------------------------------------------------------------------------
IntPtr hWndRUT_Host = FindWindowByCaption(IntPtr.Zero, strRUT_Host);
#region 移除 視窗 右上角 X 按鈕
IntPtr style = GetWindowLong(hWndRUT_Host, GWL_STYLE);
long tempStyle = (long)style.ToInt32() & ~WS_SYSMENU;
SetWindowLong(hWndRUT_Host, GWL_STYLE, new IntPtr(tempStyle));
textBox1.Text += "移除 視窗 右上角 X 按鈕" + Environment.NewLine;
#endregion
沒有留言:
張貼留言