private void SetPosition() { ClipUnit.POINT ptr = new ClipUnit.POINT(); ClipUnit.GetCursorPos(out ptr); this.Top = ptr.Y + 10; this.Left = ptr.X + 10; double width = SystemParameters.PrimaryScreenWidth; double height = SystemParameters.PrimaryScreenHeight; if (Top + 400 > height) { Top = height - 400; } else if (Top < 0) { Top = 0; } if (Left + 400 > width) { Left = width - 400; } else if (Left < 0) { Left = 0; } }
/// <summary> /// 激活窗口 /// </summary> public void ActiveWindow() { ClipUnit.POINT ptr = new ClipUnit.POINT(); ClipUnit.GetCursorPos(out ptr); this.Top = ptr.Y + 10; this.Left = ptr.X + 10; if (!this.IsActive) { if (this.WindowState == WindowState.Minimized) { SystemCommands.RestoreWindow(this); } dataGrid.SelectedIndex = 0; ShowActived(); Task.Factory.StartNew(() => { Thread.Sleep(20); Dispatcher.BeginInvoke(new Action(() => { GetGridFocus(); textBox.Focus(); })); }); } }
/// <summary> WPF窗口重写 </summary> protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); this.win_SourceInitialized(this, e); // HTodo :添加剪贴板监视 handle = (new System.Windows.Interop.WindowInteropHelper(this)).Handle; ClipUnit.AddClipboardFormatListener(handle); }
private void DealEnter() { ClipBoardModel model = (ClipBoardModel)dataGrid.SelectedItem; clipBoardManager.CopyToBoard(model); CreateSystemTray(); Task.Factory.StartNew(() => { Thread.Sleep(200); Dispatcher.BeginInvoke(new Action(() => { IntPtr myPtr = ClipUnit.GetForegroundWindow(); ClipUnit.keybd_event(Keys.ControlKey, 0, 0, 0); ClipUnit.keybd_event(Keys.V, 0, 0, 0); ClipUnit.keybd_event(Keys.ControlKey, 0, 2, 0); })); }); }