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); } } }
public static void RunSwitcher(object o) { var swo = (SwitcherOptions)o; if ((swo & SwitcherOptions.SetLauot) != 0) { Thread.Sleep(50); } int pId; string pName; var hMainWnd = WinApi.GetForegroundWindow(); var threadId = WinApi.GetWindowThreadProcessId(hMainWnd, out pId); using (var p = Process.GetProcessById(pId)) pName = p.MainModule.ModuleName; Language layout = (Language)(short)WinApi.GetKeyboardLayout(threadId); //LOWORD var hWnd = Misc.GetFocusedHandle(threadId); if (hWnd == IntPtr.Zero) { hWnd = hMainWnd; } var cNameSb = new StringBuilder(32); WinApi.GetClassName(hWnd, cNameSb, cNameSb.Capacity); var classNames = cNameSb.ToString().Split(new char[] { ' ', '.' }, StringSplitOptions.RemoveEmptyEntries); if ((swo & SwitcherOptions.SwitchText) != 0 && (layout == Language.en_US || layout == Language.ru_RU)) { #region Filter var ma = TextReplaceMethod.OtherTextControl; switch (pName) { case "devenv.exe": ma = TextReplaceMethod.Devenv; break; } foreach (var className in classNames) { switch (className) { case "Static": case "STATIC": case "Button": case "BUTTON": case "SysListView32": case "SysTreeView32": case "ListBox": case "ScrollBar": case "ComboBox": case "COMBOBOX": case "msctls_hotkey32": case "ConsoleWindowClass": ma = TextReplaceMethod.Off; break; case "Edit": case "EDIT": ma = TextReplaceMethod.TextBox; break; case "RichEdit20W": ma = TextReplaceMethod.RichTextBox; break; case "Scintilla": //ma = TextReplaceMethod.Scintilla; //хз как починить break; } } #endregion if (ma != TextReplaceMethod.Off) { var success = Misc.SwitchText(hWnd, layout, ma); if (success && (swo & SwitcherOptions.SwitchLauotIsText) != 0) { swo |= SwitcherOptions.SwitchText; } } } if ((swo & SwitcherOptions.SwitchLauot) != 0) { #region Filter #endregion Misc.SwitchLayout(hWnd, layout); } else if ((swo & SwitcherOptions.SetLauot) != 0) { #region Filter #endregion Misc.SetLayout(hWnd, layout); } }