示例#1
0
        static void Main()
        {
            try
            {
                string assemblyLocation = System.Reflection.Assembly.GetEntryAssembly().Location;
                FirstRun = false;

                int runningInstances = System.Diagnostics.Process.GetProcessesByName(
                    System.IO.Path.GetFileNameWithoutExtension(assemblyLocation)).Length;

                if (runningInstances > 1)
                {
                    MessageBox.Show(Strings.TouchpadPeaceInstanceFound);
                    return;
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                LoadProgramSettings();
            }
            catch (Exception)
            {
            }

            try
            {
                if (FirstRun)
                {
                    ContextMenus.OnHelp_Click(null, null);
                }

                using (TPCIcon tpcIcon = new TPCIcon())
                {
                    tpcIcon.Display();
                    AppDomain.CurrentDomain.ProcessExit += OnProcessExitRequest;
                    Application.Run();
                }
            }
            catch (Exception)
            {
            }
        }
示例#2
0
        /// <summary>
        /// Displays the icon in the system tray.
        /// </summary>
        public void Display()
        {
            TrayIcon.Icon    = Resources.TPPIcon;
            TrayIcon.Text    = string.Format(Strings.ReportTemplate, Program.ProgramSettings.FilterCount);
            TrayIcon.Visible = true;

            // Attach a context menu.
            ContextMenus = new ContextMenus(this);;
            TrayIcon.ContextMenuStrip = ContextMenus.Create();

            mouseHookProc    = new HookProc(onMouseAction);
            keyboardHookProc = new HookProc(onKeyboardAction);

            using (Process process = Process.GetCurrentProcess())
                using (ProcessModule module = process.MainModule)
                {
                    IntPtr hModule = GetModuleHandle(module.ModuleName);
                    hKeyboardHook = SetWindowsHookEx(HookType.WH_KEYBOARD_LL, keyboardHookProc, hModule, 0);
                    hMouseHook    = SetWindowsHookEx(HookType.WH_MOUSE_LL, mouseHookProc, hModule, 0);
                }

            TooltipAlwaysAnnounce(Strings.TouchpadPeaceStarted);
        }