|
@@ -1,5 +1,9 @@
|
|
|
-using System.Windows;
|
|
|
+using System;
|
|
|
+using System.Windows;
|
|
|
+using System.Windows.Controls;
|
|
|
+using System.Windows.Forms;
|
|
|
using System.Windows.Input;
|
|
|
+using System.Windows.Interop;
|
|
|
|
|
|
namespace TouchVideo
|
|
|
{
|
|
@@ -8,6 +12,15 @@ namespace TouchVideo
|
|
|
/// </summary>
|
|
|
public partial class MainWindow : Window
|
|
|
{
|
|
|
+ private void Window_Initialized(object sender, System.EventArgs e)
|
|
|
+ {
|
|
|
+ if (!Properties.Settings.Default.key.Equals("123456"))
|
|
|
+ {
|
|
|
+ new LockWindow().Show();
|
|
|
+ Close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public MainWindow()
|
|
|
{
|
|
|
InitializeComponent();
|
|
@@ -15,16 +28,207 @@ namespace TouchVideo
|
|
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if (!Properties.Settings.Default.key.Equals("123456"))
|
|
|
+ // 监听 Windows 消息,获取窗口句柄一定要写在窗口 loaded 事件里,才能获取到窗口句柄,否则为空
|
|
|
+ HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource; // 窗口过程
|
|
|
+ if (hwndSource != null)
|
|
|
{
|
|
|
- new LockWindow().Show();
|
|
|
- Close();
|
|
|
+ hwndSource.AddHook(new HwndSourceHook(Key_Down)); // 挂钩
|
|
|
}
|
|
|
+
|
|
|
+ // 绑定视频文件
|
|
|
+ // 交互式控制
|
|
|
+ mediaElement.LoadedBehavior = MediaState.Manual;
|
|
|
+ // 添加元素加载完成事件 -- 自动开始播放
|
|
|
+ mediaElement.Loaded += new RoutedEventHandler(media_Loaded);
|
|
|
+ // 添加媒体播放结束事件 -- 重新播放
|
|
|
+ mediaElement.MediaEnded += new RoutedEventHandler(media_MediaEnded);
|
|
|
+ // 添加元素卸载完成事件 -- 停止播放
|
|
|
+ mediaElement.Unloaded += new RoutedEventHandler(media_Unloaded);
|
|
|
}
|
|
|
|
|
|
- private void fullScreen_Click(object sender, RoutedEventArgs e)
|
|
|
+ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
|
+ {
|
|
|
+ MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("确定退出程序吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
|
|
|
+ if (messageBoxResult == MessageBoxResult.Cancel)
|
|
|
+ {
|
|
|
+ e.Cancel = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ System.Windows.Application.Current.Shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
|
|
|
+ {
|
|
|
+ if (e.Key == System.Windows.Input.Key.Escape)
|
|
|
+ {
|
|
|
+ toolBar.Visibility = Visibility.Visible;
|
|
|
+ Thickness thickness = new Thickness();
|
|
|
+ thickness.Top = 30;
|
|
|
+ mediaElement.Margin = thickness;
|
|
|
+ this.WindowState = WindowState.Normal;
|
|
|
+ this.WindowStyle = WindowStyle.SingleBorderWindow;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Window_Activated(object sender, EventArgs e)
|
|
|
{
|
|
|
+ HotKey.RegisterHotKey(((HwndSource)PresentationSource.FromVisual(mainWindow)).Handle, 100, HotKey.KeyModifiers.None, Keys.W);
|
|
|
+ HotKey.RegisterHotKey(new WindowInteropHelper(this).Handle, 101, HotKey.KeyModifiers.None, Keys.A);
|
|
|
+ HotKey.RegisterHotKey(new WindowInteropHelper(this).Handle, 102, HotKey.KeyModifiers.None, Keys.S);
|
|
|
+ HotKey.RegisterHotKey(new WindowInteropHelper(this).Handle, 103, HotKey.KeyModifiers.None, Keys.D);
|
|
|
+ HotKey.RegisterHotKey(new WindowInteropHelper(this).Handle, 104, HotKey.KeyModifiers.None, Keys.F);
|
|
|
+ HotKey.RegisterHotKey(new WindowInteropHelper(this).Handle, 105, HotKey.KeyModifiers.None, Keys.G);
|
|
|
+ HotKey.RegisterHotKey(new WindowInteropHelper(this).Handle, 106, HotKey.KeyModifiers.None, Keys.Up);
|
|
|
+ HotKey.RegisterHotKey(new WindowInteropHelper(this).Handle, 107, HotKey.KeyModifiers.None, Keys.Down);
|
|
|
+ HotKey.RegisterHotKey(new WindowInteropHelper(this).Handle, 108, HotKey.KeyModifiers.None, Keys.Left);
|
|
|
+ HotKey.RegisterHotKey(new WindowInteropHelper(this).Handle, 109, HotKey.KeyModifiers.None, Keys.Right);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Window_Closed(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ HotKey.UnregisterHotKey(new WindowInteropHelper(this).Handle, 100);
|
|
|
+ HotKey.UnregisterHotKey(new WindowInteropHelper(this).Handle, 101);
|
|
|
+ HotKey.UnregisterHotKey(new WindowInteropHelper(this).Handle, 102);
|
|
|
+ HotKey.UnregisterHotKey(new WindowInteropHelper(this).Handle, 103);
|
|
|
+ HotKey.UnregisterHotKey(new WindowInteropHelper(this).Handle, 104);
|
|
|
+ HotKey.UnregisterHotKey(new WindowInteropHelper(this).Handle, 105);
|
|
|
+ HotKey.UnregisterHotKey(new WindowInteropHelper(this).Handle, 106);
|
|
|
+ HotKey.UnregisterHotKey(new WindowInteropHelper(this).Handle, 107);
|
|
|
+ HotKey.UnregisterHotKey(new WindowInteropHelper(this).Handle, 108);
|
|
|
+ HotKey.UnregisterHotKey(new WindowInteropHelper(this).Handle, 109);
|
|
|
+ }
|
|
|
|
|
|
+ protected IntPtr Key_Down(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
|
|
+ {
|
|
|
+ const int WM_HOTKEY = 0x0312;
|
|
|
+ // 按快捷键
|
|
|
+ switch (msg)
|
|
|
+ {
|
|
|
+ case WM_HOTKEY:
|
|
|
+ string videoPath;
|
|
|
+ switch (wParam.ToInt32())
|
|
|
+ {
|
|
|
+ case 100:
|
|
|
+ videoPath = Properties.Settings.Default.video_1;
|
|
|
+ if (videoPath != "")
|
|
|
+ {
|
|
|
+ mediaElement.Source = new Uri(videoPath);
|
|
|
+ mediaElement.Play();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 101:
|
|
|
+ videoPath = Properties.Settings.Default.video_2;
|
|
|
+ if (videoPath != "")
|
|
|
+ {
|
|
|
+ mediaElement.Source = new Uri(videoPath);
|
|
|
+ mediaElement.Play();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 102:
|
|
|
+ videoPath = Properties.Settings.Default.video_3;
|
|
|
+ if (videoPath != "")
|
|
|
+ {
|
|
|
+ mediaElement.Source = new Uri(videoPath);
|
|
|
+ mediaElement.Play();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 103:
|
|
|
+ videoPath = Properties.Settings.Default.video_4;
|
|
|
+ if (videoPath != "")
|
|
|
+ {
|
|
|
+ mediaElement.Source = new Uri(videoPath);
|
|
|
+ mediaElement.Play();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 104:
|
|
|
+ videoPath = Properties.Settings.Default.video_5;
|
|
|
+ if (videoPath != "")
|
|
|
+ {
|
|
|
+ mediaElement.Source = new Uri(videoPath);
|
|
|
+ mediaElement.Play();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 105:
|
|
|
+ videoPath = Properties.Settings.Default.video_6;
|
|
|
+ if (videoPath != "")
|
|
|
+ {
|
|
|
+ mediaElement.Source = new Uri(videoPath);
|
|
|
+ mediaElement.Play();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 106:
|
|
|
+ videoPath = Properties.Settings.Default.video_7;
|
|
|
+ if (videoPath != "")
|
|
|
+ {
|
|
|
+ mediaElement.Source = new Uri(videoPath);
|
|
|
+ mediaElement.Play();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 107:
|
|
|
+ videoPath = Properties.Settings.Default.video_8;
|
|
|
+ if (videoPath != "")
|
|
|
+ {
|
|
|
+ mediaElement.Source = new Uri(videoPath);
|
|
|
+ mediaElement.Play();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 108:
|
|
|
+ videoPath = Properties.Settings.Default.video_9;
|
|
|
+ if (videoPath != "")
|
|
|
+ {
|
|
|
+ mediaElement.Source = new Uri(videoPath);
|
|
|
+ mediaElement.Play();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 109:
|
|
|
+ videoPath = Properties.Settings.Default.video_10;
|
|
|
+ if (videoPath != "")
|
|
|
+ {
|
|
|
+ mediaElement.Source = new Uri(videoPath);
|
|
|
+ mediaElement.Play();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return IntPtr.Zero;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void media_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ (sender as MediaElement).Play();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void media_MediaEnded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (Properties.Settings.Default.loopPlay)
|
|
|
+ {
|
|
|
+ // MediaElement 需要先停止播放才能再开始播放,否则会停在最后一帧不动
|
|
|
+ (sender as MediaElement).Stop();
|
|
|
+ (sender as MediaElement).Play();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ (sender as MediaElement).Stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void media_Unloaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ (sender as MediaElement).Stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fullScreen_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ toolBar.Visibility = Visibility.Hidden;
|
|
|
+ Thickness thickness = new Thickness();
|
|
|
+ thickness.Top = 0;
|
|
|
+ mediaElement.Margin = thickness;
|
|
|
+ this.Topmost = false;
|
|
|
+ this.WindowStyle = WindowStyle.None;
|
|
|
+ this.WindowState = WindowState.Maximized;
|
|
|
}
|
|
|
|
|
|
private void settings_Click(object sender, RoutedEventArgs e)
|
|
@@ -39,7 +243,7 @@ namespace TouchVideo
|
|
|
|
|
|
private void contentControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
|
{
|
|
|
-
|
|
|
+ fullScreen_Click(null, null);
|
|
|
}
|
|
|
}
|
|
|
}
|