Ejemplo n.º 1
0
        private bool SendPlainImage(BitmapImage img)
        {
            bool isok = false;

            DispatcherEx.xInvoke(() =>
            {
                HwndInfo hwndInfo = this.GetActivedEditorHwnd();
                if (hwndInfo.Handle > 0)
                {
                    this.FocusEditor(true);
                    WinApi.Editor.MoveCaretToEnding(hwndInfo);
                    var dict = ClipboardEx.Backup();
                    Clipboard.Clear();
                    Clipboard.SetImage(img);
                    string text = this.GetPlainTextUnCached();
                    WinApi.PressCtrlV();
                    DateTime now = DateTime.Now;
                    while ((DateTime.Now - now).TotalSeconds < 2.0)
                    {
                        string newText = this.GetPlainTextUnCached();
                        if (newText != text)
                        {
                            isok = true;
                        }
                        DispatcherEx.DoEvents();
                    }
                    Util.WriteTimeElapsed(now, "等待时间");
                    ClipboardEx.Restore(dict);
                    return;
                }
            });
            return(isok);
        }