public bool Nav(string text, ChatDesk chatDesk) { bool result = false; try { chatDesk.Automator.OpenWorkbench(); Util.WaitFor(() => false, 300, 300, false); HwndInfo hwndInfo = new HwndInfo(this.AddrTextBoxHwnd, "AddrTextBoxHwnd"); WinApi.ClickPointBySendMessage(hwndInfo.Handle, 30, 5); Util.WaitFor(() => false, 100, 100, false); WinApi.Editor.SetText(hwndInfo, text, true); for (int i = 0; i < 2; i++) { Util.WaitFor(() => false, 100, 100, false); WinApi.ClickHwndBySendMessage(hwndInfo.Handle, 1); WinApi.PressEnterKey(); } result = true; } catch (Exception e) { Log.Exception(e); result = false; } return(result); }
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); }
public bool SetPlainText(string txt, bool moveCaretToEnd = true, bool focusEditor = true) { if (string.IsNullOrEmpty(txt)) { return(true); } var rt = false; lock (_setPlainTextSynObj) { HwndInfo hwndInfo = this.GetActivedEditorHwnd(); if (hwndInfo.Handle > 0) { if (!WinApi.Editor.SetText(hwndInfo, txt, moveCaretToEnd)) { Log.Error("无法设置文本到编辑器"); this._desk.CheckAlive(); } else { this.LastSetPlainText = txt; this.GetPlainTextUnCached(); rt = true; this.EnsureShowEmoji(txt, hwndInfo.Handle); if (focusEditor) { this.FocusEditor(focusEditor); } } } } return(rt); }
public static DeskAutomator Create(HwndInfo hwndInfo, string seller) { DeskAutomator automator; if (QnHelper.IsGreaterV7_30_67N()) { automator = new DeskAutomatorV7_30_67N(hwndInfo, seller); } else if (QnHelper.IsGreaterV7_21_00N()) { automator = new DeskAutomatorV7_21_00N(hwndInfo, seller); } else if (QnHelper.IsGreaterV7_20_00N()) { automator = new DeskAutomatorV7_20_00N(hwndInfo, seller); } else if (QnHelper.IsGreaterV6_07_00N()) { automator = new DeskAutomatorV6_07_00N(hwndInfo, seller); } else if (QnHelper.IsGreaterV6_02_00N()) { automator = new DeskAutomatorV6_02_00N(hwndInfo, seller); } else { automator = new DeskAutomator(hwndInfo, seller); } return(automator); }
private string IsChatWnd(HwndInfo hwndInfo) { string isChatWindow = ""; string txt; if (WinApi.GetText(hwndInfo, out txt)) { isChatWindow = RegexEx.Match(txt, QnAccountFinderFactory.Finder.ChatWindowTitlePattern); } return(isChatWindow); }
private string GetSellerOfDesk(HwndInfo deskHwnd, out bool hasTitle) { string matchChatWindowTitle = ""; string title; hasTitle = WinApi.GetText(deskHwnd, out title); if (hasTitle) { matchChatWindowTitle = RegexEx.Match(title, QnAccountFinderFactory.Finder.ChatWindowTitlePattern); } return(matchChatWindowTitle); }
private string GetPlainTextInner() { string result = ""; HwndInfo hwndInfo = this.GetActivedEditorHwnd(); if (hwndInfo.Handle != 0 && !WinApi.Editor.GetText(hwndInfo, out result)) { Log.Error("无法从编辑器中获取文本!,hwnd=" + hwndInfo); this._desk.CheckAlive(); result = ""; } return(result); }
public DeskAutomator(HwndInfo deskhwnd, string seller) { this._firstControlHwnd = 0; this._singleChatEditorHwnd = 0; this._groupChatEditorHwnd = 0; this.dateTime_0 = DateTime.MinValue; this._groupChatCloseButtonHwnd = 0; this._groupChatSendButtonHwnd = 0; this._toolbarPlusHwnd = 0; this._recentContactButtonHwnd = 0; this._buyerPicHwnd = 0; this._sendMessageButtonHwnd = 0; this._closeBuyerButtonHwnd = 0; this._openWorkbenchButtonHwnd = 0; this._deskHwnd = deskhwnd; this._seller = seller; }
public bool FocusEditor(bool focusEditor) { bool isok = false; DispatcherEx.xInvoke(() => { if (focusEditor) { this._desk.BringTop(); } HwndInfo hwndInfo = this.GetActivedEditorHwnd(); if (hwndInfo.Handle > 0) { isok = WinApi.SetFocus(hwndInfo); } }); return(isok); }
private bool GetPlainTextInner(out string txt) { bool rt = false; txt = ""; try { HwndInfo hwndInfo = this.GetChatEditorHwndInfo(); if (hwndInfo.Handle != 0) { string err; if (WinApi.Editor.GetText(hwndInfo, out txt, out err, true)) { rt = true; this.HideEditorErrorTip(); } else { txt = ""; Log.Error(string.Format("无法从编辑器中获取文本!,hwnd={0},err={1}", hwndInfo.Handle, err)); if (this._desk.HasSingleOrGroupChat) { this.ShowEditorErrorTipIfNeed("无法从千牛【回复框】中读取内容。请【重启】软件。"); } else { this.HideEditorErrorTip(); } } } else { Log.Info("千牛回复框句柄为0,seller=" + this._desk.Seller); this.ShowEditorErrorTipIfNeed("无法【检测到】千牛【回复框】。请【重启】软件。"); } } catch (Exception e) { Log.Exception(e); } return(rt); }
public bool InsertRichTextToEditor(string rtf, string buyer) { var rt = false; try { HwndInfo hwndInfo = this.GetActivedEditorHwnd(); if (hwndInfo.Handle > 0) { WinApi.Editor.PasteRichText(hwndInfo, rtf); rt = true; } } catch (Exception e) { Log.Exception(e); rt = false; } return(rt); }
public DeskAutomatorV6_07_00N(HwndInfo hwndInfo, string seller) : base(hwndInfo, seller) { }
public DeskAutomatorV7_30_67N(HwndInfo hwndInfo, string seller) : base(hwndInfo, seller) { }
private ChatDesk(LoginedSeller loginedSeller, string seller) { _isBuyerRegionVisibleCacheTime = DateTime.MinValue; _foregroundChangedTime = DateTime.MaxValue; _isSingleChatcloseButtonEnableCacheTime = DateTime.MinValue; _assistWindow = null; _isGroupChatCheckTime = DateTime.MinValue; _isGroupChat = null; _isEvShowFinished = true; _isEvHideFinished = true; _preLogGroupChatNullTime = DateTime.MinValue; _logGroupChatNullCount = 0; _getVisiblePercentCacheTime = DateTime.MinValue; _getVisiblePercentCache = 0.0; _isForeground = false; _isVisible = true; _synObj = new object(); _preCheckCloseBuyerTime = DateTime.MinValue; _sameBuyerCount = 0; preUpdateRectAndWindowStateIfNeedTime = DateTime.MinValue; _preCheckForegroundWindowTime = DateTime.MinValue; _preUpdateLocationTime = DateTime.MinValue; _isEditorTextChanged = false; _isLocationChanged = false; _isAlive = true; Log.Info("Begin Create ChatDesk,seller=" + seller); Hwnd = new HwndInfo(loginedSeller.SellerHwnd, "ChatDesk"); Seller = seller; _args = new ChatDeskEventArgs { Desk = this }; Automator = ChatDeskAutomatorFactory.Create(Hwnd, Seller); chatRecordChrome = ChromeDebugerCreator.Create(this); //chatRecordChrome.EvChromeConnected += chatRecordChrome_EvChromeConnected; //chatRecordChrome.EvChromeDetached += chatRecordChrome_EvChromeDetached; //chatRecordChrome.EvRecieveNewMessage += chatRecordChrome_EvRecieveNewMessage; //chatRecordChrome.EvBuyerSwitched += Contact_EvBuyerSwitched; //_buyerReader = new TaskWindowBuyerNameReader(this); //_buyerReader.EvBuyerChanged += Contact_EvBuyerChanged; _buyerReader = new BuyerInfoWindowNameReader(this); _buyerReader.EvBuyerSwitched += Contact_EvBuyerSwitched; Editor = new DeskEditor(Automator.SingleChatEditorHwnd, this); _qnThreadId = WinApi.GetWindowThreadProcessId(loginedSeller.SellerHwnd, out _processId); EnterpriseHwnd = new HwndInfo(loginedSeller.EpHwnd, "EnterpriseRootDesk"); _winEventHooker = new WinEventHooker(_qnThreadId, loginedSeller.SellerHwnd); _winEventHooker.EvFocused += WinEventHooker_EvFocused; _winEventHooker.EvLocationChanged += WinEventHooker_EvLocationChanged; _winEventHooker.EvTextChanged += WinEventHooker_EvTextChanged; WinEventHooker.EvForegroundChanged += WinEventHooker_EvForegroundChanged; IsForeground = WinApi.IsForeground(Hwnd.Handle); IsVisible = WinApi.IsVisible(Hwnd.Handle); UpdateRectAndWindowState(); _timer = new NoReEnterTimer(Loop, 100, 0); _sugguestion = new DeskSuggestion(this); DeskSet = new HashSet <ChatDesk>(DeskSet) { this }; Log.Info("ChatDesk Created.seller=" + seller); }
void Monitor(object state) { //Find new processes that have started FindProcessesToMonitor(); // Process eventProcess = null; IntPtr eventTopLevelhWnd = IntPtr.Zero; IntPtr eventhWnd = IntPtr.Zero; string title = null; uint eventsToRaise = 0x0000; //Monitor Each Process for exit, or visible windows lock (ProcessesToMonitor) { foreach (Process process in ProcessesToMonitor) { eventProcess = process; process.Refresh(); if (process.HasExited) { ProcessesToMonitor.Remove(process); OnProcessExited(process); break; } //Monitor Visible Windows foreach (HwndInfo info in GetTopLevelVisibleWindows(process)) { eventTopLevelhWnd = info.hWnd; title = GetWindowTitle(info.hWnd); eventhWnd = eventTopLevelhWnd; //Is the Window a new window we havent seen before? if (!VisibleWindows.ContainsKey(info.hWnd)) { VisibleWindows[info.hWnd] = title; eventsToRaise |= VISIBLE_WINDOW_FOUND; break; } //has the title of the window changed? else if (VisibleWindows[info.hWnd] != title) { VisibleWindows[info.hWnd] = title; eventsToRaise |= VISIBLE_WINDOW_TITLE_CHANGED; break; } //Is the Window a new window we havent seen before? HwndInfo[] infoChilds = GetVisibleChildWindowsNotInProcess(info.hWnd, info.ProcessId); if (infoChilds.Length > 0) { HwndInfo infoChild = infoChilds[infoChilds.Length - 1]; title = GetWindowTitle(infoChild.hWnd); eventhWnd = infoChild.hWnd; if (!VisibleWindows.ContainsKey(infoChild.hWnd)) { VisibleWindows[infoChild.hWnd] = title; eventsToRaise |= VISIBLE_WINDOW_FOUND; eventProcess = Process.GetProcessById(infoChild.ProcessId); break; } } } if (eventsToRaise != 0) { break; //need to raise an event } } } if ((eventsToRaise & VISIBLE_WINDOW_FOUND) != 0) { OnVisibleWindowFound(eventTopLevelhWnd, eventhWnd, eventProcess, title); } if ((eventsToRaise & VISIBLE_WINDOW_TITLE_CHANGED) != 0) { OnVisibleWindowTitleChanged(eventTopLevelhWnd, eventhWnd, eventProcess, title); } }