private static void GetWindowInfo(IntPtr hWnd, bool isInFocus = false) { // http://www.codeproject.com/Articles/1698/MS-Spy-style-Window-Finder if (hWnd != IntPtr.Zero && WinApi.IsWindow(hWnd) && hWnd != hWndFoundWindow) { WindowSelectorEventArgs e = new WindowSelectorEventArgs(); //Программа int pId; var threadId = WinApi.GetWindowThreadProcessId(hWnd, out pId); using (var p = Process.GetProcessById(pId)) e.ProgramName = p.MainModule.ModuleName; if (isInFocus) { e.HGetForegroundWindow = (int)hWnd; var h = Misc.GetFocusedHandle(threadId, e); if (h != IntPtr.Zero) { hWnd = h; } if (hWnd == hWndFoundWindow) { return; } } //Класс var temp = new StringBuilder(256); WinApi.GetClassName(hWnd, temp, temp.Capacity); e.ClassName = temp.ToString(); temp.Clear(); //Заголовок temp.Capacity = 256; WinApi.GetWindowText(hWnd, temp, temp.Capacity); e.WindowCaption = temp.ToString(); temp.Clear(); //Дескриптор e.HWindow = (int)hWnd; e.HParent = (int)WinApi.GetParent(hWnd); //Очищаем RefreshWindow(hWndFoundWindow); //Рисуем прямоугольник HighlightFoundWindow(hWnd); hWndFoundWindow = hWnd; if (UiUpdate != null) { UiUpdate.Invoke(null, e); } } }
protected virtual void OnUiUpdate(string message, bool isError, bool append, EventArgs e) { UiUpdate?.Invoke(this, message, isError, append, e); }
private void DeviceNotifcation(object sender, string message, bool isCritical, EventArgs e) { UiUpdate?.Invoke(sender, message, isCritical, true, e); }