Beispiel #1
0
        public MainForm()
        {
            InitializeComponent();

            try
            {
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                Application.ThreadException += Application_ThreadException;
                Msg.SupportURL = "https://github.com/stax76/mpv.net#support";
                Instance       = this;
                WPF.WPF.Init();
                System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
                Hwnd        = Handle;
                MinimumSize = new Size(FontHeight * 16, FontHeight * 9);
                Text       += " " + Application.ProductVersion;

                object recent = RegHelp.GetObject(App.RegPath, "Recent");

                if (recent is string[] r)
                {
                    RecentFiles = new List <string>(r);
                }
                else
                {
                    RecentFiles = new List <string>();
                }

                var dummy = mp.Conf;
                App.ProcessCommandLineEarly();
                if (mp.Screen == -1)
                {
                    mp.Screen = Array.IndexOf(Screen.AllScreens, Screen.PrimaryScreen);
                }
                SetScreen(mp.Screen);
                ChangeFullscreen(mp.Fullscreen);
            }
            catch (Exception ex)
            {
                Msg.ShowException(ex);
            }
        }
Beispiel #2
0
        public MainForm()
        {
            InitializeComponent();

            try
            {
                Instance = this;
                Hwnd     = Handle;
                mp.Init();

                mp.Shutdown         += Shutdown;
                mp.VideoSizeChanged += VideoSizeChanged;
                mp.FileLoaded       += FileLoaded;
                mp.Idle             += Idle;
                mp.Seek             += () => UpdateProgressBar();

                mp.observe_property_bool("pause", PropChangePause);
                mp.observe_property_bool("fullscreen", PropChangeFullscreen);
                mp.observe_property_bool("ontop", PropChangeOnTop);
                mp.observe_property_bool("border", PropChangeBorder);
                mp.observe_property_string("sid", PropChangeSid);
                mp.observe_property_string("aid", PropChangeAid);
                mp.observe_property_string("vid", PropChangeVid);
                mp.observe_property_int("edition", PropChangeEdition);

                if (mp.GPUAPI != "vulkan")
                {
                    mp.ProcessCommandLine(false);
                }

                AppDomain.CurrentDomain.UnhandledException += (sender, e) => Msg.ShowError(e.ExceptionObject.ToString());
                Application.ThreadException += (sender, e) => Msg.ShowException(e.Exception);
                Msg.SupportURL = "https://github.com/stax76/mpv.net#support";
                Text           = "mpv.net " + Application.ProductVersion;
                TaskbarButtonCreatedMessage = Native.RegisterWindowMessage("TaskbarButtonCreated");

                object recent = RegHelp.GetObject(App.RegPath, "Recent");

                if (recent is string[] r)
                {
                    RecentFiles = new List <string>(r);
                }
                else
                {
                    RecentFiles = new List <string>();
                }

                ContextMenu          = new ContextMenuStripEx(components);
                ContextMenu.Opened  += ContextMenu_Opened;
                ContextMenu.Opening += ContextMenu_Opening;

                if (mp.Screen == -1)
                {
                    mp.Screen = Array.IndexOf(Screen.AllScreens, Screen.PrimaryScreen);
                }
                int      targetIndex = mp.Screen;
                Screen[] screens     = Screen.AllScreens;
                if (targetIndex < 0)
                {
                    targetIndex = 0;
                }
                if (targetIndex > screens.Length - 1)
                {
                    targetIndex = screens.Length - 1;
                }
                Screen    screen = screens[Array.IndexOf(screens, screens[targetIndex])];
                Rectangle target = screen.Bounds;
                Left = target.X + (target.Width - Width) / 2;
                Top  = target.Y + (target.Height - Height) / 2;

                int posX = RegHelp.GetInt(App.RegPath, "PosX");
                int posY = RegHelp.GetInt(App.RegPath, "PosY");

                if (posX != 0 && posY != 0 && App.RememberPosition)
                {
                    Left = posX - Width / 2;
                    Top  = posY - Height / 2;
                }

                if (App.Maximized)
                {
                    WindowState = FormWindowState.Maximized;
                }
            }
            catch (Exception ex)
            {
                Msg.ShowException(ex);
            }
        }
Beispiel #3
0
        protected override void WndProc(ref Message m)
        {
            //Debug.WriteLine(m);

            switch (m.Msg)
            {
            case 0x0201:     // WM_LBUTTONDOWN
            case 0x0202:     // WM_LBUTTONUP
            case 0x0100:     // WM_KEYDOWN
            case 0x0101:     // WM_KEYUP
            case 0x0104:     // WM_SYSKEYDOWN
            case 0x0105:     // WM_SYSKEYUP
            case 0x020A:     // WM_MOUSEWHEEL
                if (mp.WindowHandle != IntPtr.Zero)
                {
                    Native.SendMessage(mp.WindowHandle, m.Msg, m.WParam, m.LParam);
                }
                break;

            case 0x0200:     // WM_MOUSEMOVE
                Point pos = PointToClient(Cursor.Position);
                mp.command_string($"mouse {pos.X} {pos.Y}");
                if (CursorHelp.IsPosDifferent(LastCursorPosChanged))
                {
                    CursorHelp.Show();
                }
                break;

            case 0x319:     // WM_APPCOMMAND
                if (mp.WindowHandle != IntPtr.Zero)
                {
                    Native.PostMessage(mp.WindowHandle, m.Msg, m.WParam, m.LParam);
                }
                break;

            case 0x203:     // Native.WM.LBUTTONDBLCLK
                if (!IsMouseInOSC())
                {
                    mp.command_string("cycle fullscreen");
                }
                break;

            case 0x02E0:     // WM_DPICHANGED
                if (IgnoreDpiChanged)
                {
                    break;
                }
                var r2 = Marshal.PtrToStructure <Native.RECT>(m.LParam);
                Native.SetWindowPos(Handle, IntPtr.Zero, r2.Left, r2.Top, r2.Width, r2.Height, 0);
                break;

            case 0x0214:     // WM_SIZING
                var rc = Marshal.PtrToStructure <Native.RECT>(m.LParam);
                var r  = rc;
                NativeHelp.SubtractWindowBorders(Handle, ref r);
                int   c_w = r.Right - r.Left, c_h = r.Bottom - r.Top;
                float aspect    = mp.VideoSize.Width / (float)mp.VideoSize.Height;
                int   d_w       = Convert.ToInt32(c_h * aspect - c_w);
                int   d_h       = Convert.ToInt32(c_w / aspect - c_h);
                int[] d_corners = { d_w, d_h, -d_w, -d_h };
                int[] corners   = { rc.Left, rc.Top, rc.Right, rc.Bottom };
                int   corner    = NativeHelp.GetResizeBorder(m.WParam.ToInt32());

                if (corner >= 0)
                {
                    corners[corner] -= d_corners[corner];
                }

                Marshal.StructureToPtr <Native.RECT>(new Native.RECT(corners[0], corners[1], corners[2], corners[3]), m.LParam, false);
                m.Result = new IntPtr(1);
                return;
            }

            if (m.Msg == SingleProcess.Message)
            {
                object filesObject = RegHelp.GetObject(App.RegPath, "ShellFiles");

                if (filesObject is string[] files)
                {
                    switch (RegHelp.GetString(App.RegPath, "ProcessInstanceMode"))
                    {
                    case "single":
                        mp.Load(files, true, Control.ModifierKeys.HasFlag(Keys.Control));
                        break;

                    case "queue":
                        foreach (string file in files)
                        {
                            mp.commandv("loadfile", file, "append");
                        }
                        break;
                    }
                }

                RegHelp.RemoveValue(App.RegPath, "ShellFiles");
                Activate();
                return;
            }

            base.WndProc(ref m);
        }
Beispiel #4
0
        public MainForm()
        {
            InitializeComponent();

            try
            {
                Instance = this;
                Hwnd     = Handle;
                mp.Init();
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                Application.ThreadException += Application_ThreadException;
                Msg.SupportURL = "https://github.com/stax76/mpv.net#support";
                WPF.WPF.Init();
                System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
                Text += " " + Application.ProductVersion;

                object recent = RegHelp.GetObject(App.RegPath, "Recent");

                if (recent is string[] r)
                {
                    RecentFiles = new List <string>(r);
                }
                else
                {
                    RecentFiles = new List <string>();
                }

                var   wpfColor = WPF.WPF.ThemeColor;
                Color color    = Color.FromArgb(wpfColor.A, wpfColor.R, wpfColor.G, wpfColor.B);
                ToolStripRendererEx.InitColors(color, App.IsDarkMode);

                ContextMenu          = new ContextMenuStripEx(components);
                ContextMenu.Opened  += ContextMenu_Opened;
                ContextMenu.Opening += ContextMenu_Opening;

                App.ProcessCommandLineEarly();

                if (mp.Screen == -1)
                {
                    mp.Screen = Array.IndexOf(Screen.AllScreens, Screen.PrimaryScreen);
                }
                int      targetIndex = mp.Screen;
                Screen[] screens     = Screen.AllScreens;
                if (targetIndex < 0)
                {
                    targetIndex = 0;
                }
                if (targetIndex > screens.Length - 1)
                {
                    targetIndex = screens.Length - 1;
                }
                Screen    screen = screens[Array.IndexOf(screens, screens[targetIndex])];
                Rectangle target = screen.Bounds;
                Left = target.X + (target.Width - Width) / 2;
                Top  = target.Y + (target.Height - Height) / 2;

                int posX = RegHelp.GetInt(App.RegPath, "PosX");
                int posY = RegHelp.GetInt(App.RegPath, "PosY");

                if (posX != 0 && posY != 0 && App.RememberPosition)
                {
                    Left = posX - Width / 2;
                    Top  = posY - Height / 2;
                }

                mp.Shutdown         += Shutdown;
                mp.VideoSizeChanged += VideoSizeChanged;
                mp.FileLoaded       += FileLoaded;
                mp.Idle             += Idle;
                mp.VideoSizeAutoResetEvent.WaitOne(1500);
                if (Height < FontHeight * 4)
                {
                    SetFormPosAndSize();
                }
                mp.observe_property_bool("fullscreen", PropChangeFullscreen);
                mp.observe_property_bool("ontop", PropChangeOnTop);
                mp.observe_property_bool("border", PropChangeBorder);
                mp.observe_property_string("sid", PropChangeSid);
                mp.observe_property_string("aid", PropChangeAid);
                mp.observe_property_string("vid", PropChangeVid);
                mp.observe_property_int("edition", PropChangeEdition);
            }
            catch (Exception ex)
            {
                Msg.ShowException(ex);
            }
        }