protected override void OnHandleCreated(EventArgs args) { base.OnHandleCreated(args); string itemText = "Natural Size"; IntPtr sysMenuHandle = UnsafeNativeMethods.GetSystemMenu(Handle, false); NativeMethods.MenuItemInfo info = new NativeMethods.MenuItemInfo(); info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(NativeMethods.MenuItemInfo)); info.fMask = NativeMethods.MIIM_STRING | NativeMethods.MIIM_STATE | NativeMethods.MIIM_ID | NativeMethods.MIIM_DATA; info.fType = NativeMethods.MFT_STRING; info.fState = NativeMethods.MFS_DEFAULT; info.dwItemData = NativeMethods.SC_NATURALSIZE; info.wID = NativeMethods.SC_NATURALSIZE; info.dwTypeData = itemText; info.cch = itemText.Length; info.hSubMenu = IntPtr.Zero; info.hbmpChecked = IntPtr.Zero; info.hbmpUnchecked = IntPtr.Zero; UnsafeNativeMethods.InsertMenuItem(sysMenuHandle, 5, true, ref info); UnsafeNativeMethods.DrawMenuBar(Handle); UpdateNaturalSizeMenuItem(); }
public static extern bool InsertMenuItem(IntPtr hMenu, int uItem, bool fByPosition, ref NativeMethods.MenuItemInfo lpmii);