PostMessage() private method

private PostMessage ( IntPtr hWnd, uint Msg, int wParam, int lParam ) : bool
hWnd System.IntPtr
Msg uint
wParam int
lParam int
return bool
Exemplo n.º 1
0
 /// <summary>
 /// Send a message to all other processes to ask them to disable any
 /// WinCompose hooks they may have installed.
 /// </summary>
 public void BroadcastDisableEvent()
 {
     NativeMethods.PostMessage(HWND.BROADCAST, WM_WINCOMPOSE.DISABLE,
                               Process.GetCurrentProcess().Id, 0);
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // Some commandline flags just trigger a message broadcast
            foreach (var arg in args)
            {
                if (m_command_flags.TryGetValue(arg, out var cmd))
                {
                    NativeMethods.PostMessage(HWND.BROADCAST, WM_WINCOMPOSE.OPEN, (int)cmd, 0);
                    return;
                }
            }

            Logging.Init();
            Logger.Info($"WinCompose {Settings.Version} started, arguments: “{string.Join(" ", args)}”");

            // Do this early because of the AutoLaunch setting
            Settings.LoadConfig();

            bool from_task    = args.Contains("-fromtask");
            bool from_startup = args.Contains("-fromstartup");

            // If run from Task Scheduler or from startup but autolaunch is
            // disabled, exit early.
            if ((from_task || from_startup) && !Settings.AutoLaunch.Value)
            {
                return;
            }

            // If run from Task Scheduler but we do not want to run elevated,
            // exit early.
            if (from_task && !Settings.RunElevated.Value)
            {
                return;
            }

            // If run from Task Scheduler, we need to detach otherwise the
            // system may kill us after some time.
            if (from_task)
            {
                Process.Start(Application.ResourceAssembly.Location, "-detached");
                return;
            }

            // If run from the start menu but we want to run elevated and there
            // is a task scheduler entry, give it priority.
            if (from_startup && Settings.RunElevated.Value)
            {
                var ret = TaskScheduler.HasTask("WinCompose");
                if (ret)
                {
                    return;
                }
                Logger.Warn($"Scheduled task not found: {ret.Message}");
            }

            // Try to install the Task Scheduler entry. The best time for this is
            // just after installation, when the installer launches us with elevated
            // privileges.
            if (!from_task && Settings.AutoLaunch.Value)
            {
                var ret = TaskScheduler.InstallTask("WinCompose", $"\"{Utils.ExecutableName}\" -fromtask",
                                                    elevated: true, author: "Sam Hocevar");
                if (!ret)
                {
                    Logger.Warn($"Could not install scheduled task: {ret.Message}");
                }
            }

            Settings.LoadSequences();
            Metadata.LoadDB();
            KeyboardHook.Init();
            Updater.Init();

            Settings.StartWatchConfigFile();

            try
            {
                var app = new Application();
                app.Run();
            }
            finally
            {
                Settings.StopWatchConfigFile();
                Updater.Fini();
                KeyboardHook.Fini();
                Settings.SaveConfig();
                Metadata.SaveDB();
                Updater.Fini();
                Logger.Info("Program shut down");
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // Some commandline flags just trigger a message broadcast
            var command_flags = new Dictionary <string, MenuCommand>()
            {
                { "-sequences", MenuCommand.ShowSequences },
                { "-settings", MenuCommand.ShowOptions },
            };

            foreach (var arg in args)
            {
                if (command_flags.TryGetValue(arg, out var cmd))
                {
                    NativeMethods.PostMessage(HWND.BROADCAST, WM_WINCOMPOSE.OPEN, (int)cmd, 0);
                    return;
                }
            }

            // Do this early because of the AutoLaunch setting
            Settings.LoadConfig();

            bool from_task    = args.Contains("-fromtask");
            bool from_startup = args.Contains("-fromstartup");

            // If run from the task scheduler or from startup but autolaunch is
            // disabled, exit early.
            if ((from_task || from_startup) && !Settings.AutoLaunch.Value)
            {
                return;
            }


            // If run from Task Scheduler, we need to detach otherwise the
            // system may kill us after some time.
            if (from_task)
            {
                Process.Start(Application.ResourceAssembly.Location);
                return;
            }

            // If run from the start menu but there is a task scheduler entry,
            // give it priority.
            if (from_startup && SchTasks.HasTask())
            {
                return;
            }

            SchTasks.InstallTask();

            Settings.LoadSequences();
            Metadata.LoadDB();
            KeyboardHook.Init();
            Updater.Init();

            Settings.StartWatchConfigFile();

            try
            {
                var app = new Application();
                app.Run();
            }
            finally
            {
                Settings.StopWatchConfigFile();
                Updater.Fini();
                KeyboardHook.Fini();
                Settings.SaveConfig();
                Metadata.SaveDB();
                Updater.Fini();
            }
        }
Exemplo n.º 4
0
 static void Main()
 {
     NativeMethods.PostMessage(HWND.BROADCAST, WM_WINCOMPOSE.SEQUENCES, 0, 0);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Send a message to all other processes to ask them to disable any
 /// WinCompose hooks they may have installed.
 /// </summary>
 public void TriggerDisableEvent()
 {
     NativeMethods.PostMessage((IntPtr)0xffff, WM_WINCOMPOSE_DISABLE,
                               Process.GetCurrentProcess().Id, 0);
 }