[DllImport("USER32.DLL")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, UInt32 bRevert);
private const UInt32 SC_CLOSE = 0x0000F060;
private const UInt32 MF_BYCOMMAND = 0x00000000;
public Form1()
{
InitializeComponent();
IntPtr hMenu = GetSystemMenu(this.Handle, 0);
RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
}
private static extern IntPtr GetSystemMenu(IntPtr hWnd, UInt32 bRevert);
[DllImport("USER32.DLL")]
private static extern UInt32 RemoveMenu(IntPtr hMenu, UInt32 nPosition, UInt32 wFlags);
private static extern UInt32 RemoveMenu(IntPtr hMenu, UInt32 nPosition, UInt32 wFlags);
private const UInt32 SC_CLOSE = 0x0000F060;
private const UInt32 MF_BYCOMMAND = 0x00000000;
public Form1()
{
InitializeComponent();
IntPtr hMenu = GetSystemMenu(this.Handle, 0);
RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
}
本文介绍了一种使用 C# 在 Windows Forms 应用中禁用窗口关闭按钮的方法。通过调用 USER32.DLL 中的 GetSystemMenu 和 RemoveMenu 函数实现。此技巧对于需要控制应用程序退出流程的开发者非常有用。
601

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



