不能移动和改变大小的窗口,C#实现

// saucer(思归)的方案: 用API去掉系统菜单的“移动”菜单项

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class Test : Form
{
const int MF_BYPOSITION = 0x0400;
const int MF_REMOVE = 0x1000;

[DllImport("user32.dll",EntryPoint="GetSystemMenu")]
extern static IntPtr GetSystemMenu(IntPtr hWnd, IntPtr bRevert);

[DllImport("user32.dll",EntryPoint="RemoveMenu")]
extern static int RemoveMenu(IntPtr hMenu, int nPos, int flags);

Test()
{
Text = "不能移动和改变大小的窗口";
FormBorderStyle = FormBorderStyle.FixedSingle;
MaximizeBox = false;
MinimizeBox = false;
RemoveMenu(GetSystemMenu(Handle,IntPtr.Zero),1,MF_BYPOSITION &brvbarMF_REMOVE);
}

static void Main()
{
Application.Run(new Test());
}
}

Published At
Categories with Web编程
Tagged with
comments powered by Disqus