コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: hanfeijp/Captura
        public MainWindow()
        {
            Instance = this;
            
            FFmpegService.FFmpegDownloader += () =>
            {
                if (_downloader == null)
                {
                    _downloader = new FFmpegDownloader();
                    _downloader.Closed += (Sender, Args) => _downloader = null;
                }

                _downloader.ShowAndFocus();
            };
            
            InitializeComponent();

            if (DataContext is MainViewModel vm)
            {
                vm.Init(!App.CmdOptions.NoPersist, true, !App.CmdOptions.Reset, !App.CmdOptions.NoHotkeys);

                // Register for Windows Messages
                ComponentDispatcher.ThreadPreprocessMessage += (ref MSG Message, ref bool Handled) =>
                {
                    const int wmHotkey = 786;

                    if (Message.message == wmHotkey)
                    {
                        var id = Message.wParam.ToInt32();

                        vm.HotKeyManager.ProcessHotkey(id);
                    }
                };

                Loaded += (Sender, Args) =>
                {
                    RepositionWindowIfOutside();

                    vm.HotKeyManager.ShowNotRegisteredOnStartup();

                    if (vm.AudioSource is NoAudioSource)
                    {
                        ServiceProvider.MessageProvider.ShowError(
                            "Could not find bass.dll or bassmix.dll.\nAudio Recording will not be available.", "No Audio");
                    }
                };
            }

            if (App.CmdOptions.Tray || ServiceProvider.Get<Settings>().UI.MinToTrayOnStartup)
                Hide();

            Closing += (Sender, Args) =>
            {
                if (!TryExit())
                    Args.Cancel = true;
            };
        }