diff --git a/service/ClipService.cs b/service/ClipService.cs
index 5e139f9..2d43894 100644
--- a/service/ClipService.cs
+++ b/service/ClipService.cs
@@ -80,8 +80,8 @@ public string SaveImage(BitmapSource bs)
///
///
public void SetValueToClipboard(ClipModel result)
- {
-
+ {
+
if (result.Type == WECHAT_TYPE)
{
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(result.ClipValue));
@@ -98,11 +98,11 @@ public void SetValueToClipboard(ClipModel result)
bool isExplorer = false;
Process[] ps = Process.GetProcesses();
- WinAPIHelper.GetWindowThreadProcessId(WinAPIHelper.GetForegroundWindow(), out int pid);
-
+ WinAPIHelper.GetWindowThreadProcessId(WinAPIHelper.GetForegroundWindow(), out int pid);
+
foreach (Process p in ps)
- {
-
+ {
+
if (p.Id == pid && p.ProcessName.ToLower() == "explorer")
{
isExplorer = true;
@@ -111,8 +111,8 @@ public void SetValueToClipboard(ClipModel result)
}
//如果是桌面或者资源管理器则直接粘贴为文件
if (isExplorer)
- {
-
+ {
+
string[] tmp = Path.GetFullPath(result.ClipValue).Split(',');
IDataObject data = new DataObject(DataFormats.FileDrop, tmp);
@@ -176,12 +176,14 @@ public void SetValueToClipboard(ClipModel result)
catch { return; }
}
else
- {
-
- IDataObject data = new DataObject(DataFormats.Text, result.ClipValue);
-
- Clipboard.SetDataObject(data, true);
- //System.Windows.Forms.Clipboard.SetDataObject(data, true);
+ {
+
+ IDataObject data = new DataObject(DataFormats.Text, result.ClipValue);
+
+ // Clipboard.SetDataObject(data, true);
+
+ //当有其他进程占用剪切板时,WPF的Clipboard会有BUG,winform的没有,所以暂时用winform的
+ System.Windows.Forms.Clipboard.SetDataObject(data, true);
}
diff --git a/util/WinAPIHelper.cs b/util/WinAPIHelper.cs
index 7adff27..b2f9d5c 100644
--- a/util/WinAPIHelper.cs
+++ b/util/WinAPIHelper.cs
@@ -91,6 +91,9 @@ public static extern IntPtr GetWindow(
int wCmd
);
+
+
+
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
diff --git a/view/MainWindow.xaml.cs b/view/MainWindow.xaml.cs
index a685fbc..3f0fedc 100644
--- a/view/MainWindow.xaml.cs
+++ b/view/MainWindow.xaml.cs
@@ -681,14 +681,24 @@ public void PasteValue(string clipStr)
/// /// 是否需要延时,单条需要,批量不需要
private void SetValueToClip(ClipModel result)
{
-
+
+
try
{
- clipService.SetValueToClipboard(result);
+ clipService.SetValueToClipboard(result);
+
}
- catch { }
- Thread.Sleep(50);
-
+ catch (Exception e){
+ //Console.WriteLine(e.StackTrace);
+ //IntPtr hwnd = WinAPIHelper.GetOpenClipboardWindow();
+ //StringBuilder sb = new StringBuilder(501);
+ //WinAPIHelper.GetWindowText(hwnd, sb, 500);
+ //Console.WriteLine("==");
+ //Console.WriteLine(sb.ToString());
+ //Console.WriteLine("==");
+ }
+ Thread.Sleep(50);
+
//WinAPIHelper.keybd_event((byte)KeyInterop.VirtualKeyFromKey(Key.LeftCtrl),0,0,0);//按下
//WinAPIHelper.keybd_event((byte)KeyInterop.VirtualKeyFromKey(Key.V),0,0,0);//按下
//WinAPIHelper.keybd_event((byte)KeyInterop.VirtualKeyFromKey(Key.V),0,2,0);//弹起
@@ -698,7 +708,8 @@ private void SetValueToClip(ClipModel result)
KeyboardKit.Keyboard.Press(Key.V);
KeyboardKit.Keyboard.Release(Key.LeftCtrl);
- KeyboardKit.Keyboard.Release(Key.V);
+ KeyboardKit.Keyboard.Release(Key.V);
+
}