public static void Enable(bool enabled)
 {
     if (enabled)
     {
         if (Instance == null)
         {
             Instance = new DropDownMenuScrollWheelHandler();
             Application.AddMessageFilter(Instance);
         }
     }
     else
     {
         if (Instance != null)
         {
             Application.RemoveMessageFilter(Instance);
             Instance = null;
         }
     }
 }
Exemple #2
0
        static void Main(string[] args)
        {
            try
            {
                // Remove Zone.Identifier from Alternate Data Stream
                SafeNativeMethods.DeleteFile(Application.ExecutablePath + ":Zone.Identifier");
            }
            catch { }
#if RELEASE
            try
            {
#endif
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            DropDownMenuScrollWheelHandler.Enable(true);

            var argFileIndex = ArgFileIndex(args);
            if (argFileIndex != -1)
            {
                if (new FileInfo(args[argFileIndex]).Extension.ToLower() == ".nip")
                {
                    try
                    {
                        var import       = DrsServiceLocator.ImportService;
                        var importReport = import.ImportProfiles(args[argFileIndex]);
                        GC.Collect();
                        Process current = Process.GetCurrentProcess();
                        foreach (
                            Process process in
                            Process.GetProcessesByName(current.ProcessName.Replace(".vshost", "")))
                        {
                            if (process.Id != current.Id && process.MainWindowTitle.Contains("Settings"))
                            {
                                MessageHelper mh = new MessageHelper();
                                mh.sendWindowsStringMessage((int)process.MainWindowHandle, 0, "ProfilesImported");
                            }
                        }

                        if (string.IsNullOrEmpty(importReport) && !ArgExists(args, "-silentImport") && !ArgExists(args, "-silent"))
                        {
                            frmDrvSettings.ShowImportDoneMessage(importReport);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Import Error: " + ex.Message, Application.ProductName + " Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }

            else if (ArgExists(args, "-createCSN"))
            {
                File.WriteAllText("CustomSettingNames.xml", Properties.Resources.CustomSettingNames);
            }
            else
            {
                bool createdNew = true;
                using (Mutex mutex = new Mutex(true, Application.ProductName, out createdNew))
                {
                    if (createdNew)
                    {
                        Application.Run(new frmDrvSettings(ArgExists(args, "-showOnlyCSN"), ArgExists(args, "-disableScan")));
                    }
                    else
                    {
                        Process current = Process.GetCurrentProcess();
                        foreach (
                            Process process in
                            Process.GetProcessesByName(current.ProcessName.Replace(".vshost", "")))
                        {
                            if (process.Id != current.Id && process.MainWindowTitle.Contains("Settings"))
                            {
                                MessageHelper mh = new MessageHelper();
                                mh.bringAppToFront((int)process.MainWindowHandle);
                            }
                        }
                    }
                }
            }
#if RELEASE
        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message + "\r\n\r\n" + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
#endif
        }