-
Notifications
You must be signed in to change notification settings - Fork 0
/
SystemMenu.cs
45 lines (36 loc) · 1.54 KB
/
SystemMenu.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public static class SystemMenu
{
[DllImport("user32.dll", EntryPoint = "GetSystemMenu", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
static extern IntPtr GetSystemMenu(IntPtr WindowHandle, int bReset);
[DllImport("user32.dll", SetLastError = true)]
static extern int EnableMenuItem(IntPtr menu, int ideEnableItem, int enable);
public static void DisableCloseButton(Form form)
{
//0xF060 = scClose
//mfGrayed = 0x00000001
//mfByCommand = 0x00000000
IntPtr SystemMenu = GetSystemMenu(form.Handle, 0);
EnableMenuItem(SystemMenu, 0xF060, 1);
//NOTE: don't make this a critical failure if it doesn't work.
/*
int PreviousState = EnableMenuItem(SystemMenu, 0xF060, 1);
if (PreviousState == -1)
throw new Exception("The close menu does not exist");*/
}
public static void EnableCloseButton(Form form)
{
//0xF060 = scClose
//mfString = 0x00000000
//mfByCommand = 0x00000000
IntPtr SystemMenu = GetSystemMenu(form.Handle, 0);
EnableMenuItem(SystemMenu, 0xF060, 0);
//NOTE: don't make this a critical failure if it doesn't work.
/*
int PreviousState = EnableMenuItem(SystemMenu, 0xF060, 0);
if (PreviousState == -1)
throw new Exception("The close menu does not exist");*/
}
}