using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace deleteSysMenu
{
/// <summary>
/// Summary description for Test.
/// </summary>
public class Test : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
[DllImport("user32.dll",EntryPoint="GetSystemMenu")]
extern static System.IntPtr GetSystemMenu(System.IntPtr hWnd , System.IntPtr bRevert);
[DllImport("user32.dll",EntryPoint="RemoveMenu")]
extern static int RemoveMenu (IntPtr hMenu, int nPos, int flags);
static int MF_BYPOSITION = 0x400;
static int MF_REMOVE = 0x1000;
public Test()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
Text = "不让拖动的标题栏";
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
MinimizeBox = false;
}
private const int WM_NCHITTEST = 0x84;
private const int HTCAPTION = 0x2;
private const int HTCLIENT = 0x1;
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
//method 1禁止标题栏拖动
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if(m.Msg == WM_NCHITTEST && m.Result == (IntPtr)HTCAPTION)
{
m.Result = (IntPtr) HTCLIENT;
}
}
//method 2去掉系统菜单
private const int WS_SYSMENU = 0x00080000;
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style = cp.Style & ~WS_SYSMENU;
return cp;
}
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Test
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Test";
this.Text = "Test";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Test());
}
}
}