可以在InitializeComponent()后面去调用这个涵数
[DllImport("aa.dll", EntryPoint = "mytest")]
public static extern int mytest();
[DllImport("user32.dll")]
internal static extern IntPtr GetSystemMenu(IntPtr hwnd, bool bRevert);
[DllImport("user32.dll")]
internal static extern int GetMenuItemCount(IntPtr hMenu);
[DllImport("user32.dll")]
internal static extern int RemoveMenu(IntPtr hMenu, int uPosition, int uFlags);
/// <summary>
/// 窗体的关闭按钮失效
/// </summary>
protected void CloseButtonEnable()
{
// 默认窗口去除关闭按钮
const int MF_BYPOSITION = 0x00000400;
IntPtr hWindow = this.Handle;
IntPtr hMenu = GetSystemMenu(hWindow, false);
int count = GetMenuItemCount(hMenu);
RemoveMenu(hMenu, count - 1, MF_BYPOSITION);
RemoveMenu(hMenu, count - 2, MF_BYPOSITION);
}
本文介绍了一种在Windows窗体应用中通过调用user32.dll中的API函数来禁用窗体上的关闭按钮的方法。具体步骤包括获取系统菜单句柄、获取菜单项数量以及移除指定位置的菜单项。
3万+

被折叠的 条评论
为什么被折叠?



