|
|
@ -3,6 +3,7 @@ using STranslate.ViewModel;
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Windows;
|
|
|
|
using System.Windows;
|
|
|
|
using System.Windows.Input;
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
using System.Windows.Interop;
|
|
|
|
|
|
|
|
|
|
|
|
namespace STranslate
|
|
|
|
namespace STranslate
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -11,46 +12,66 @@ namespace STranslate
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
public MainWindow()
|
|
|
|
/// 监听全局快捷键
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
protected override void OnSourceInitialized(EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HotkeysUtil.InitialHook(this);
|
|
|
|
InitializeComponent();
|
|
|
|
HotkeysUtil.Regist(HotkeyModifiers.MOD_ALT, Key.A, () =>
|
|
|
|
|
|
|
|
|
|
|
|
InitHwnd();
|
|
|
|
|
|
|
|
InitTray();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.DataContext = MainVM.Instance;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void InitHwnd()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.Show();
|
|
|
|
var helper = new WindowInteropHelper(this);
|
|
|
|
this.Activate();
|
|
|
|
helper.EnsureHandle();
|
|
|
|
this.TextBoxInput.Focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
#if false
|
|
|
|
/// <summary>
|
|
|
|
HotkeysUtil.Regist(HotkeyModifiers.MOD_ALT, Key.D, () =>
|
|
|
|
/// 初始化托盘
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private void InitTray()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//复制内容
|
|
|
|
//notifyIcon.BalloonTipText = "程序开始运行";
|
|
|
|
KeyboardUtil.Press(Key.LeftCtrl);
|
|
|
|
//notifyIcon.ShowBalloonTip(1000);
|
|
|
|
KeyboardUtil.Type(Key.C);
|
|
|
|
notifyIcon.Text = "STranslate";
|
|
|
|
KeyboardUtil.Release(Key.LeftCtrl);
|
|
|
|
notifyIcon.Icon = new System.Drawing.Icon(@"D:\CodePepo\STranslate\STranslate\Images\translate2.ico");
|
|
|
|
System.Threading.Thread.Sleep(200);
|
|
|
|
notifyIcon.Visible = true;
|
|
|
|
System.Diagnostics.Debug.Print(Clipboard.GetText());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//this.Show();
|
|
|
|
System.Windows.Forms.MenuItem inputTranslateButton = new System.Windows.Forms.MenuItem("输入翻译");
|
|
|
|
//this.Activate();
|
|
|
|
inputTranslateButton.Click += new EventHandler(InputTranslate_Click);
|
|
|
|
//this.TextBoxInput.Text = "123";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//this.TextBoxInput.Text = Clipboard.GetText();
|
|
|
|
System.Windows.Forms.MenuItem crosswordTranslateButton = new System.Windows.Forms.MenuItem("划词翻译");
|
|
|
|
//this.TextBoxInput.Focus();
|
|
|
|
crosswordTranslateButton.Click += new EventHandler(CrosswordTranslate_Click);
|
|
|
|
|
|
|
|
|
|
|
|
//KeyboardUtil.Type(Key.Enter);
|
|
|
|
System.Windows.Forms.MenuItem screenshotTranslationButton = new System.Windows.Forms.MenuItem("截图翻译");
|
|
|
|
});
|
|
|
|
screenshotTranslationButton.Click += new EventHandler(ScreenshotTranslation_Click);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
System.Windows.Forms.MenuItem openMainWinButton = new System.Windows.Forms.MenuItem("显示主窗口");
|
|
|
|
|
|
|
|
openMainWinButton.Click += new EventHandler(OpenMainWin_Click);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.Windows.Forms.MenuItem exitButton = new System.Windows.Forms.MenuItem("退出");
|
|
|
|
|
|
|
|
exitButton.Click += new EventHandler(Exit_Click);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] {
|
|
|
|
|
|
|
|
inputTranslateButton,
|
|
|
|
|
|
|
|
crosswordTranslateButton,
|
|
|
|
|
|
|
|
screenshotTranslationButton,
|
|
|
|
|
|
|
|
openMainWinButton,
|
|
|
|
|
|
|
|
exitButton
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 显示主窗口
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
private void OpenMainWin_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
this.Show();
|
|
|
|
this.TextBoxInput.Focus();
|
|
|
|
this.Activate();
|
|
|
|
this.DataContext = MainVM.Instance;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -62,9 +83,8 @@ namespace STranslate
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DragMove();
|
|
|
|
DragMove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 快捷键
|
|
|
|
/// 软件运行时快捷键
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
/// <param name="e"></param>
|
|
|
|
/// <param name="e"></param>
|
|
|
@ -77,12 +97,12 @@ namespace STranslate
|
|
|
|
MainVM.Instance.InputTxt = string.Empty;
|
|
|
|
MainVM.Instance.InputTxt = string.Empty;
|
|
|
|
MainVM.Instance.OutputTxt = string.Empty;
|
|
|
|
MainVM.Instance.OutputTxt = string.Empty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//退出 Ctrl+Q
|
|
|
|
//退出 Ctrl+Shift+Q
|
|
|
|
if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control)
|
|
|
|
if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control)
|
|
|
|
&& e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Shift)
|
|
|
|
&& e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Shift)
|
|
|
|
&& e.Key == Key.Q)
|
|
|
|
&& e.Key == Key.Q)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Application.Current.Shutdown();
|
|
|
|
Exit_Click(null, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if false
|
|
|
|
#if false
|
|
|
|
//置顶/取消置顶 Ctrl+T
|
|
|
|
//置顶/取消置顶 Ctrl+T
|
|
|
@ -119,11 +139,71 @@ namespace STranslate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 监听全局快捷键
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
protected override void OnSourceInitialized(EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
IntPtr handle = new WindowInteropHelper(this).Handle;
|
|
|
|
|
|
|
|
HotKeysUtil2.RegisterHotKey(handle);
|
|
|
|
|
|
|
|
|
|
|
|
private void NotifyIcon_Click(object sender, RoutedEventArgs e)
|
|
|
|
HwndSource source = HwndSource.FromHwnd(handle);
|
|
|
|
|
|
|
|
source.AddHook(WndProc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if false
|
|
|
|
|
|
|
|
HotkeysUtil.InitialHook(this);
|
|
|
|
|
|
|
|
HotkeysUtil.Regist(HotkeyModifiers.MOD_ALT, Key.A, () =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.Show();
|
|
|
|
this.Show();
|
|
|
|
this.Activate();
|
|
|
|
this.Activate();
|
|
|
|
|
|
|
|
this.TextBoxInput.Focus();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
HotkeysUtil.Regist(HotkeyModifiers.MOD_ALT, Key.D, () =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//复制内容
|
|
|
|
|
|
|
|
KeyboardUtil.Press(Key.LeftCtrl);
|
|
|
|
|
|
|
|
KeyboardUtil.Type(Key.C);
|
|
|
|
|
|
|
|
KeyboardUtil.Release(Key.LeftCtrl);
|
|
|
|
|
|
|
|
System.Threading.Thread.Sleep(200);
|
|
|
|
|
|
|
|
System.Diagnostics.Debug.Print(Clipboard.GetText());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//this.Show();
|
|
|
|
|
|
|
|
//this.Activate();
|
|
|
|
|
|
|
|
//this.TextBoxInput.Text = "123";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//this.TextBoxInput.Text = Clipboard.GetText();
|
|
|
|
|
|
|
|
//this.TextBoxInput.Focus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//KeyboardUtil.Type(Key.Enter);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 热键的功能
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="m"></param>
|
|
|
|
|
|
|
|
protected IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handle)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 0x0312: //这个是window消息定义的 注册的热键消息
|
|
|
|
|
|
|
|
//Console.WriteLine(wParam.ToString());
|
|
|
|
|
|
|
|
if (wParam.ToString().Equals(HotKeysUtil2.InputTranslateId + ""))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.InputTranslate_Click(null, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (wParam.ToString().Equals(HotKeysUtil2.CrosswordTranslateId + ""))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.CrosswordTranslate_Click(null, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (wParam.ToString().Equals(HotKeysUtil2.ScreenShotTranslateId + ""))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.ScreenshotTranslation_Click(null, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return IntPtr.Zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -134,8 +214,69 @@ namespace STranslate
|
|
|
|
private void Window_Deactivated(object sender, EventArgs e)
|
|
|
|
private void Window_Deactivated(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.Hide();
|
|
|
|
this.Hide();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 截图翻译
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
private void ScreenshotTranslation_Click(object sender, EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MessageBox.Show("开发中");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 划词翻译
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
private void CrosswordTranslate_Click(object sender, EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ClearTextBox();
|
|
|
|
|
|
|
|
var sentence = GetWords.Get();
|
|
|
|
|
|
|
|
this.Show();
|
|
|
|
|
|
|
|
this.Activate();
|
|
|
|
|
|
|
|
this.TextBoxInput.Text = sentence.Trim();
|
|
|
|
|
|
|
|
_ = MainVM.Instance.Translate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 输入翻译
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
private void InputTranslate_Click(object sender, EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ClearTextBox();
|
|
|
|
|
|
|
|
Show();
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
TextBoxInput.Focus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 退出程序
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
private void Exit_Click(object sender, EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
notifyIcon.Dispose();
|
|
|
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 清空输入输出框
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private void ClearTextBox()
|
|
|
|
|
|
|
|
{
|
|
|
|
MainVM.Instance.InputTxt = string.Empty;
|
|
|
|
MainVM.Instance.InputTxt = string.Empty;
|
|
|
|
MainVM.Instance.OutputTxt = string.Empty;
|
|
|
|
MainVM.Instance.OutputTxt = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 托盘图标
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|