散分了!如何屏蔽窗体右键的系统快捷菜单?急
窗体最小化到任务栏后,想屏蔽掉 右键快捷菜单,
防止窗体关闭,程序终止?
谢谢
分数不够,继续加
[解决办法]
一个变态的方法
想法来之前几天的一个问题,和楼主的正好相反
他想实现在无边框的窗体时也有右键菜单
private void Form1_SizeChanged(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
FormBorderStyle = FormBorderStyle.None;
else FormBorderStyle = FormBorderStyle.Sizable;
}
[解决办法]
//参考如下代码将Close菜单项屏蔽
using System.Runtime.InteropServices;
[DllImport( "user32.dll ")]
public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport( "user32.dll ")]
public static extern bool EnableMenuItem(IntPtr hMenu,
uint uIDEnableItem, uint uEnable);
public const int SC_CLOSE = 61536;
public const uint MF_BYCOMMAND = 0;
public const uint MF_GRAYED = 1;
public const int WM_INITMENUPOPUP = 0x0117;
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_INITMENUPOPUP:
if ((int)m.LParam > > 16 != 0)
EnableMenuItem(m.WParam, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
break;
}
base.WndProc(ref m);
}
private void Form1_Load(object sender, EventArgs e)
{
EnableMenuItem(GetSystemMenu(Handle, false), SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
}