Buenas amigos de AMSSpecialist a petición de un usuario he creado esta DLL usando user32.dll con la cual podréis mostrar o ocultar los botones de las ventanas, Botones: Minimizar, Maximizar, Cerrar. Espero que os guste la idea y os funcione correctamente!!
using System;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
namespace WindowButtons
{
internal static class WindowButtonsClass
{
#region USER32.DLL & OTHER FUNCTIONS
[DllImport("user32.dll")]
public static extern int GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")]
public static extern bool DeleteMenu(int hMenu, int uPosition, int uFlags);
[DllImport("user32.dll")]
internal extern static int SetWindowLong(IntPtr hwnd, int index, int value);
[DllImport("user32.dll")]
internal extern static int GetWindowLong(IntPtr hwnd, int index);
public static int HideResultBoolToNum(bool val)
{
int resval;
if (val == true)
{
resval = 1;
}
else
{
resval = 0;
}
return resval;
}
public static int ShowResultBoolToNum(bool val)
{
int resval;
if (val == false)
{
resval = 1;
}
else
{
resval = 0;
}
return resval;
}
public static int HideResultVal(int val)
{
int valRes;
if (val == 349110272)
{
valRes = 1;
}
else
{
valRes = 0;
}
return valRes;
}
public static int ShowResultVal(int val)
{
int valRes;
if (val == 349044736 || val == 348979200)
{
valRes = 1;
}
else
{
valRes = 0;
}
return valRes;
}
#endregion USER32.DLL & OTHER FUNCTIONS
[DllExport("ShowMinimize", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int ShowMinimize(IntPtr Handle)
{
long value = GetWindowLong(Handle, -16);
int rest = SetWindowLong(Handle, -16, (int)(value | 0x00020000L));
return ShowResultVal(rest);
}
[DllExport("ShowMaximize", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int ShowMaximize(IntPtr Handle)
{
long value = GetWindowLong(Handle, -16);
int rest = SetWindowLong(Handle, -16, (int)(value | 0x00010000L));
return ShowResultVal(rest);
}
[DllExport("ShowClose", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int ShowClose(IntPtr Handle)
{
int s_SystemMenuHandle = GetSystemMenu(Handle, true);
bool BooleanRes = DeleteMenu(s_SystemMenuHandle, 6, 1024);
return ShowResultBoolToNum(BooleanRes);
}
[DllExport("HideMinimize", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int HideMinimize(IntPtr Handle)
{
long value = GetWindowLong(Handle, -16);
int rest = SetWindowLong(Handle, -16, (int)(value & ~0x00020000L));
return HideResultVal(rest);
}
[DllExport("HideMaximize", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int HideMaximize(IntPtr Handle)
{
long value = GetWindowLong(Handle, -16);
int rest = SetWindowLong(Handle, -16, (int)(value & ~0x00010000L));
return HideResultVal(rest);
}
[DllExport("HideClose", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static int HideClose(IntPtr Handle)
{
int s_SystemMenuHandle = GetSystemMenu(Handle, false);
bool BooleanRes = DeleteMenu(s_SystemMenuHandle, 6, 1024);
return HideResultBoolToNum(BooleanRes);
}
}
}