public MainWindow() { InitializeComponent(); // this.ShowTitleBar = false; this.ShowIconOnTitleBar = true; this.ShowMinButton = true; this.ShowMaxRestoreButton = false; this.ShowCloseButton = true; this.ResizeMode = ResizeMode.CanMinimize; // this.SaveWindowPosition = true; this.LeftWindowCommandsOverlayBehavior = WindowCommandsOverlayBehavior.Never; this.RightWindowCommandsOverlayBehavior = WindowCommandsOverlayBehavior.Never; this.image1.Source = EyeHelper.ChangeBitmapToImageSource(softwatcher.Properties.Resources.drag); // this.Flyouts1.Items.Add(new LoginFlyout()); this.Flyouts1.Items.Add(new SettingsView()); this.Flyouts1.Items.Add(new SetXiaohaoFlyout()); new SoftContext(this); try { this.Topmost = bool.Parse(INIHelper.IniReadValue("BaseConfig", "Topmost", AppDomain.CurrentDomain.BaseDirectory + "\\config.ini")); } catch { } }
protected virtual IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { switch (msg) { case WM_LBUTTONUP: //鼠标左键弹起 { if (this.IsDragging) { this.IsDragging = false; this.CaptureMouse(false); handled = true; uint pid; EyeHelper.GetWindowThreadProcessId(this._hWndCurrent, out pid); if (pid > 0) { Process p = Process.GetProcessById((int)pid); if (p.ProcessName == "DragonNest") { //鼠标最后指向的句柄 SoftContext.Role = new Role((int)this._hWndCurrent); if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\resources")) { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\resources"); } SoftContext.Role.Window.Dm.SetPath(AppDomain.CurrentDomain.BaseDirectory + "\\resources"); if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\resources\\dnDict.txt")) { File.Create(AppDomain.CurrentDomain.BaseDirectory + "\\resources\\dnDict.txt"); } SoftContext.Role.Window.Dm.SetDict(0, "dnDict.txt"); } else { this.ShowMessageAsync("绑定失败", "请选择游戏窗口!"); } } } } break; case WM_MOUSEMOVE: //鼠标移动 { if (this.IsDragging) { IntPtr hWnd = EyeHelper.WindowFromPoint(System.Windows.Forms.Control.MousePosition); if (this._hWndCurrent != hWnd) { // EyeHelper.DrawRevFrame(this._hWndCurrent); // EyeHelper.DrawRevFrame(hWnd); this._hWndCurrent = hWnd; // 想显示当前句柄的位置如this.tbHwnd.Text = hWnd.ToInt32().ToString(); } handled = true; } } break; } return(IntPtr.Zero); }
/// <summary> /// 捕获或释放鼠标 /// </summary> /// <param name="captured">true捕获,false释放</param> private void CaptureMouse(bool captured) { if (captured) { var hwnd = EyeHelper.SetCapture(new WindowInteropHelper(this).Handle); this.Cursor = new Cursor(new MemoryStream(softwatcher.Properties.Resources.eye)); this.image1.Source = EyeHelper.ChangeBitmapToImageSource(softwatcher.Properties.Resources.drag2); } else { this.image1.Source = EyeHelper.ChangeBitmapToImageSource(softwatcher.Properties.Resources.drag); this.Cursor = Cursors.Arrow; var ret = EyeHelper.ReleaseCapture(); if (this._hWndCurrent != IntPtr.Zero) { // EyeHelper.DrawRevFrame(this._hWndCurrent); //还原边框 //this._hWndCurrent = IntPtr.Zero; } } }