Example #1
0
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (App.IsStartedFromTerminal)
                {
                    WinAPI.AttachConsole(-1 /*ATTACH_PARENT_PROCESS*/);
                }

                if (core.ConfigFolder == "")
                {
                    return;
                }

                string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray();

                if (args.Length == 2 && args[0] == "--reg-file-assoc")
                {
                    if (args[1] == "audio")
                    {
                        FileAssociation.Register(App.AudioTypes);
                    }
                    if (args[1] == "video")
                    {
                        FileAssociation.Register(App.VideoTypes);
                    }
                    if (args[1] == "image")
                    {
                        FileAssociation.Register(App.ImageTypes);
                    }
                    if (args[1] == "unreg")
                    {
                        FileAssociation.Unregister();
                    }
                    return;
                }

                App.Init();
                Mutex mutex = new Mutex(true, "mpvnetProcessInstance", out bool isFirst);

                if ((App.ProcessInstance == "single" || App.ProcessInstance == "queue") && !isFirst)
                {
                    List <string> files = new List <string>();
                    files.Add(App.ProcessInstance);

                    foreach (string arg in args)
                    {
                        if (!arg.StartsWith("--") && (arg == "-" || arg.Contains("://") ||
                                                      arg.Contains(":\\") || arg.StartsWith("\\\\")))
                        {
                            files.Add(arg);
                        }
                        else if (arg == "--queue")
                        {
                            files[0] = "queue";
                        }
                    }

                    Process[] procs = Process.GetProcessesByName("mpvnet");

                    for (int i = 0; i < 20; i++)
                    {
                        foreach (Process proc in procs)
                        {
                            if (proc.MainWindowHandle != IntPtr.Zero)
                            {
                                WinAPI.AllowSetForegroundWindow(proc.Id);
                                var data = new WinAPI.COPYDATASTRUCT();
                                data.lpData = string.Join("\n", files.ToArray());
                                data.cbData = data.lpData.Length * 2 + 1;
                                WinAPI.SendMessage(proc.MainWindowHandle, 0x004A /*WM_COPYDATA*/, IntPtr.Zero, ref data);
                                mutex.Dispose();

                                if (App.IsStartedFromTerminal)
                                {
                                    WinAPI.FreeConsole();
                                }

                                return;
                            }
                        }

                        Thread.Sleep(50);
                    }

                    mutex.Dispose();
                    return;
                }

                Application.Run(new MainForm());

                if (App.IsStartedFromTerminal)
                {
                    WinAPI.FreeConsole();
                }

                mutex.Dispose();
            }
            catch (Exception ex)
            {
                Msg.ShowException(ex);
            }
        }
Example #2
0
        /// <summary>
        /// ウィンドウプロシージャ
        /// </summary>
        /// <param name="m">Windowsメッセージ</param>
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            switch (m.Msg)
            {
            case WinAPI.WM_COPYDATA:
                if (!ListViewInput.Visible || HotKey == null)
                {
                    break;
                }

                WinAPI.COPYDATASTRUCT cds = (WinAPI.COPYDATASTRUCT)Marshal.PtrToStructure(m.LParam, typeof(WinAPI.COPYDATASTRUCT));

                WinAPI.KeyInfo key = (WinAPI.KeyInfo)Marshal.PtrToStructure(cds.lpData, typeof(WinAPI.KeyInfo));
                uint           mod = HotKey.ModKey;

                if (key.keycode == (uint)Keys.RWin)
                {
                    key.keycode = (uint)Keys.LWin;
                }
                if (key.keycode == (uint)Keys.LShiftKey || key.keycode == (uint)Keys.RShiftKey)
                {
                    key.keycode = (uint)Keys.Shift;
                }
                if (key.keycode == (uint)Keys.LControlKey || key.keycode == (uint)Keys.RControlKey)
                {
                    key.keycode = (uint)Keys.Control;
                }
                if (key.keycode == (uint)Keys.LMenu || key.keycode == (uint)Keys.RMenu)
                {
                    key.keycode = (uint)Keys.Alt;
                }
                if (key.keycode == (uint)Keys.Return)
                {
                    key.keycode = (uint)Keys.Enter;
                }


                if (LeavedKey)
                {
                    if (key.keycode == (uint)Keys.Enter || key.keycode == (uint)Keys.Escape)
                    {
                        Keys sendKey = (Keys)key.keycode;
                        IsEntered = true;
                        ListViewInput.Textbox_SetValue(sendKey, HotKey);
                        break;
                    }
                }

                if (key.keycode == (uint)Keys.Control || key.keycode == (uint)Keys.Alt || key.keycode == (uint)Keys.Shift || key.keycode == (uint)Keys.LWin)
                {
                    // キーをすべて離したら次のキー入力で取得しなおす
                    if (key.keyflag == 1)
                    {
                        if (LeavedKey)
                        {
                            mod       = 0;
                            LeavedKey = false;
                        }
                        mod |= (uint)(Keys)Enum.ToObject(typeof(Keys), key.keycode);
                    }
                    else if (key.keyflag == 3)
                    {
                        LeavedKey = true;
                    }

                    HotKey.ModKey = mod;
                }
                else
                {
                    if (HotKey.ModKey == 0)
                    {
                        HotKey.ModKey = (uint)Keys.Control;
                    }
                    HotKey.Key = (uint)(Keys)Enum.ToObject(typeof(Keys), key.keycode);
                }

                if (HotKey.ModKey != 0 && HotKey.Key != 0)
                {
                    ListViewInput.Text = KeysToString(HotKey.ModKey, HotKey.Key);
                }

                break;

            default:
                break;
            }
        }