private void CustomizeMenu(bool updateMenuChecked) { // Reset current system menu SystemMenu.ResetSystemMenu(this); // Add custom menuitems to system menu systemMenu = SystemMenu.FromForm(this); //systemMenu.AppendSeparator(); if (updateMenuChecked) { systemMenu.InsertMenu(0, ItemFlags.mfChecked, UpdateCheckMenuId, "Automatic Update Check Enabled"); timerUpdateCheck.Enabled = true; } else { systemMenu.InsertMenu(0, ItemFlags.mfUnchecked, UpdateCheckMenuId, "Automatic Update Check Enabled"); } RegistryKey rk = Registry.CurrentUser.CreateSubKey(@"Software\SystemRestoreExplorer"); if (rk != null) { rk.SetValue("AutomaticUpdateCheckEnabled", updateCheckEnabled, RegistryValueKind.DWord); } systemMenu.InsertMenu(0, AboutMenuId, "About"); systemMenu.InsertSeparator(2); }
// Retrieves a new object from a Form object public static SystemMenu FromForm(Form form) { SystemMenu systemMenu = new SystemMenu(); systemMenu.hSystemMenu = apiGetSystemMenu(form.Handle, 0); if (systemMenu.hSystemMenu == IntPtr.Zero) { // Throw an exception on failure throw new NoSystemMenuException(); } return(systemMenu); }