资源简介

通过windows API禁用、启用窗体的关闭按钮,防止不小心点击X号或右键关闭按钮而关闭程序

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace TestFormClose
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        const int SC_CLOSE = 0xF060;

        [DllImport(“User32.dll “ EntryPoint = “FindWindow“)]
        private static extern IntPtr FindWindow(string lpClassName string lpWindowName);
        [DllImport(“user32.dll“)]
        static extern IntPtr GetSystemMenu(IntPtr hwnd bool bRevert);
        [DllImport(“user32.dll “ EntryPoint = “RemoveMenu“)]
        extern static int RemoveMenu(IntPtr hMenu int nPos int flags);
        [DllImport(“user32.dll“)]
        private static extern bool InsertMenu(IntPtr hMenu Int32 wPosition Int32 wFlags Int32 wIDNewItem string lpNewItem);

        private void button1_Click(object sender EventArgs e)
        {
            IntPtr hwnd_win;
            hwnd_win = FindWindow(null textBox1.Text);
            IntPtr CLOSE_MENU = GetSystemMenu(hwnd_win false);
            RemoveMenu(CLOSE_MENU SC_CLOSE 0x0);
        }

        private void button2_Click(object sender EventArgs e)
        {
            IntPtr hwnd_win = FindWindow(null textBox1.Text);
            IntPtr CLOSE_MENU = GetSystemMenu(hwnd_win true);
            InsertMenu(CLOSE_MENU SC_CLOSE 0x0 0 ““);
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     338370  2013-06-07 08:55  TestFormClose\11.bmp

     文件     404022  2013-06-07 08:56  TestFormClose\22.bmp

     文件       9728  2013-06-07 08:53  TestFormClose\bin\Debug\TestFormClose.exe

     文件      22016  2013-06-07 08:53  TestFormClose\bin\Debug\TestFormClose.pdb

     文件      11608  2013-06-07 08:56  TestFormClose\bin\Debug\TestFormClose.vshost.exe

     文件        490  2010-03-17 22:39  TestFormClose\bin\Debug\TestFormClose.vshost.exe.manifest

     文件       1571  2013-06-07 08:52  TestFormClose\Form1.cs

     文件       4508  2013-06-07 08:50  TestFormClose\Form1.Designer.cs

     文件       5817  2013-06-07 08:50  TestFormClose\Form1.resx

     文件       6104  2013-06-07 08:57  TestFormClose\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        470  2013-06-07 08:52  TestFormClose\obj\x86\Debug\GenerateResource-ResGen.read.1.tlog

     文件        746  2013-06-07 08:52  TestFormClose\obj\x86\Debug\GenerateResource-ResGen.write.1.tlog

     文件        927  2013-06-07 08:56  TestFormClose\obj\x86\Debug\TestFormClose.csproj.FileListAbsolute.txt

     文件       9728  2013-06-07 08:53  TestFormClose\obj\x86\Debug\TestFormClose.exe

     文件        180  2013-06-07 08:52  TestFormClose\obj\x86\Debug\TestFormClose.Form1.resources

     文件      22016  2013-06-07 08:53  TestFormClose\obj\x86\Debug\TestFormClose.pdb

     文件        180  2013-06-07 08:52  TestFormClose\obj\x86\Debug\TestFormClose.Properties.Resources.resources

     文件        494  2013-06-07 08:46  TestFormClose\Program.cs

     文件       1382  2013-06-07 08:46  TestFormClose\Properties\AssemblyInfo.cs

     文件       2874  2013-06-07 08:46  TestFormClose\Properties\Resources.Designer.cs

     文件       5612  2013-06-07 08:46  TestFormClose\Properties\Resources.resx

     文件       1096  2013-06-07 08:46  TestFormClose\Properties\Settings.Designer.cs

     文件        249  2013-06-07 08:46  TestFormClose\Properties\Settings.settings

     文件       3578  2013-06-07 08:52  TestFormClose\TestFormClose.csproj

     目录          0  2013-06-07 08:46  TestFormClose\obj\x86\Debug\TempPE

     目录          0  2013-06-07 08:53  TestFormClose\obj\x86\Debug

     目录          0  2013-06-07 08:53  TestFormClose\bin\Debug

     目录          0  2013-06-07 08:46  TestFormClose\obj\x86

     目录          0  2013-06-07 08:46  TestFormClose\bin

     目录          0  2013-06-07 08:46  TestFormClose\obj

............此处省略5个文件信息

评论

共有 条评论