C#如何使用API函数
展开全部
下面是一个简单的例子,调用API实现了禁用关闭按钮的功能
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace winFormTest
{
public partial class Form2 : Form
{
[DllImport("USER32.DLL")]
public static extern int GetSystemMenu(int hwnd, int bRevert);
[DllImport("USER32.DLL")]
public static extern int RemoveMenu(int hMenu, int nPosition, int wFlags);
const int MF_REMOVE = 0x1000;
const int SC_RESTORE = 0xF120; //还原
const int SC_MOVE = 0xF010; //移动
const int SC_SIZE = 0xF000; //大小
const int SC_MINIMIZE = 0xF020; //最小化
const int SC_MAXIMIZE = 0xF030; //最大化
const int SC_CLOSE = 0xF060; //关闭
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
int hMenu;
hMenu = GetSystemMenu(this.Handle.ToInt32(), 0);
RemoveMenu(hMenu, SC_CLOSE, MF_REMOVE);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace winFormTest
{
public partial class Form2 : Form
{
[DllImport("USER32.DLL")]
public static extern int GetSystemMenu(int hwnd, int bRevert);
[DllImport("USER32.DLL")]
public static extern int RemoveMenu(int hMenu, int nPosition, int wFlags);
const int MF_REMOVE = 0x1000;
const int SC_RESTORE = 0xF120; //还原
const int SC_MOVE = 0xF010; //移动
const int SC_SIZE = 0xF000; //大小
const int SC_MINIMIZE = 0xF020; //最小化
const int SC_MAXIMIZE = 0xF030; //最大化
const int SC_CLOSE = 0xF060; //关闭
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
int hMenu;
hMenu = GetSystemMenu(this.Handle.ToInt32(), 0);
RemoveMenu(hMenu, SC_CLOSE, MF_REMOVE);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询