Skip to content

Commit baa87d7

Browse files
committed
?
1 parent 7842f85 commit baa87d7

File tree

2 files changed

+71
-31
lines changed

2 files changed

+71
-31
lines changed

IconPopup.xaml.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
using System;
22
using System.Linq;
3+
using System.Runtime.InteropServices;
4+
using System.Threading;
5+
using System.Threading.Tasks;
36
using System.Timers;
47
using System.Windows;
8+
using System.Windows.Automation;
9+
using System.Windows.Forms;
510
using System.Windows.Input;
11+
using Application = System.Windows.Application;
12+
using Clipboard = System.Windows.Clipboard;
13+
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
14+
using Timer = System.Timers.Timer;
615

716
namespace CopyPlusPlus
817
{
@@ -21,6 +30,7 @@ public partial class IconPopup
2130

2231
private double _opacity = 1;
2332

33+
public IntPtr mouseLocation;
2434
public string CopiedText;
2535

2636
public IconPopup()
@@ -41,9 +51,35 @@ public IconPopup()
4151
Stay();
4252
}
4353

44-
private void OnLeftMouseDown(object sender, MouseButtonEventArgs e)
54+
[DllImport("user32.dll")]
55+
public static extern int SetForegroundWindow(IntPtr hwnd);
56+
57+
[DllImport("user32.dll")]
58+
private static extern IntPtr WindowFromPoint(Point point);
59+
60+
private async void OnLeftMouseDown(object sender, MouseButtonEventArgs e)
4561
{
46-
_mainWindow.ProcessText(CopiedText);
62+
Point a = PointToScreen(Mouse.GetPosition(this));
63+
Hide();
64+
await Task.Delay(10);
65+
66+
var b = WindowFromPoint(a);
67+
68+
//var a = WindowFromPoint();
69+
SetForegroundWindow(b);
70+
71+
//AutomationElement element = AutomationElement.FromHandle(WindowFromPoint(mouseLocation));
72+
//if (element != null)
73+
//{
74+
// element.SetFocus();
75+
//}
76+
77+
await Task.Delay(10);
78+
79+
SendKeys.SendWait("^c");
80+
await Task.Delay(666);
81+
//Thread.Sleep(1111);
82+
_mainWindow.ProcessText(Clipboard.GetText());
4783
}
4884

4985
private static void Stay()

MainWindow.xaml.cs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq;
88
using System.Net;
99
using System.Reflection;
10+
using System.Runtime.InteropServices;
1011
using System.Security.Cryptography;
1112
using System.Text;
1213
using System.Text.RegularExpressions;
@@ -134,42 +135,45 @@ private static void OnMouseWheel(object sender, MouseEventArgs e)
134135
.LastOrDefault(window => window is IconPopup)?.Close();
135136
}
136137

137-
private async void OnMouseDragFinished(object sender, MouseEventArgs e)
138+
private void OnMouseDragFinished(object sender, MouseEventArgs e)
138139
{
139140
if (!GlobalSwitch) return;
140141

141142
if (SwitchSelectText.IsOn == false) return;
142143

143-
var clipboardBefore = Clipboard.GetText();
144-
//var clipboardBefore = Clipboard.GetData(DataFormats.Rtf);
144+
//var clipboardBefore = Clipboard.GetText();
145+
////var clipboardBefore = Clipboard.GetData(DataFormats.Rtf);
145146

146-
Clipboard.Clear();
147-
await Task.Delay(20);
147+
//Clipboard.Clear();
148+
////await Task.Delay(11);
149+
//Thread.Sleep(11);
148150

149-
SendKeys.SendWait("^c");
150-
await Task.Delay(500);
151+
//SendKeys.SendWait("^c");
152+
////await Task.Delay(666);
153+
//Thread.Sleep(1111);
151154

152-
if (Clipboard.ContainsText())
153-
try
154-
{
155-
var transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
156-
var mouse = transform.Transform(new Point(e.X, e.Y));
157-
var iconPopup = new IconPopup
158-
{
159-
Left = mouse.X + IconPopupX,
160-
Top = mouse.Y + IconPopupY,
161-
ShowActivated = false,
162-
Focusable = false,
163-
CopiedText = Clipboard.GetText()
164-
};
165-
iconPopup.Show();
166-
}
167-
catch
155+
//if (Clipboard.ContainsText())
156+
157+
try
158+
{
159+
var transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
160+
var mouse = transform.Transform(new Point(e.X, e.Y));
161+
var iconPopup = new IconPopup
168162
{
169-
// ignored
170-
}
163+
Left = mouse.X + IconPopupX,
164+
Top = mouse.Y + IconPopupY,
165+
ShowActivated = false,
166+
Focusable = false,
167+
//CopiedText = Clipboard.GetText()
168+
};
169+
iconPopup.Show();
170+
}
171+
catch
172+
{
173+
// ignored
174+
}
171175

172-
Clipboard.SetDataObject(clipboardBefore, true);
176+
//Clipboard.SetDataObject(clipboardBefore, true);
173177
}
174178

175179
public void ProcessText(string text)
@@ -592,9 +596,9 @@ public void CheckUpdate()
592596
var notifyUpdate = new
593597
NotifyUpdate("打扰一下,您已经使用这个软件版本很久啦!\n\n或许已经有新版本了,欢迎前去公众号获取最新版。✨",
594598
"知道啦", "别再提示")
595-
{
596-
Owner = this
597-
};
599+
{
600+
Owner = this
601+
};
598602
notifyUpdate.Show();
599603
}
600604

0 commit comments

Comments
 (0)