/// <summary> /// поиск дескриптора по процессу /// </summary> /// <returns>дескриптор окна</returns> static public IntPtr mainhwd() { Process process = Process.GetCurrentProcess(); Process[] proc = Process.GetProcesses(); Process[] processes = Process.GetProcessesByName(process.ProcessName); foreach (Process _process in processes) { // Get the first instance that is not this instance, has the // same process name and was started from the same file name // and location. Also check that the process has a valid // window handle in this session to filter out other user's // processes. if (_process.Id != process.Id && _process.MainModule.FileName == process.MainModule.FileName && _process.Handle != IntPtr.Zero) { m_hndl = _process.MainWindowHandle; if (m_hndl == IntPtr.Zero) { Enum(_process.Id); } WinApi.GetWindowTextLength(m_hndl); break; } } return(m_hndl); }
/// <summary> /// выборка всех запущенных приложений /// </summary> /// <param name="id">ид процесса приложения</param> /// <returns>дескриптор окна</returns> static private IntPtr enumID(int id) { IntPtr hwnd = IntPtr.Zero; bool flg = true; WinApi.EnumWindows((hWnd, lParam) => { if (WinApi.IsWindowVisible(hWnd) && (WinApi.GetWindowTextLength(hWnd) != 0)) { if (WinApi.IsIconic(hWnd) != 0 && WinApi.GetPlacement(hWnd).showCmd == WinApi.ShowWindowCommands.Minimized && flg) { hwnd = findCurProc(id, hWnd, out flg); } else { ; } } return(true); }, IntPtr.Zero); return(hwnd); }
/// <summary> /// Получение заголовка окна /// </summary> /// <param name="hWnd">дескриптор приложения</param> /// <returns></returns> private static string GetWindowText(IntPtr hWnd) { int len = WinApi.GetWindowTextLength(hWnd) + 1; StringBuilder sb = new StringBuilder(len); len = WinApi.GetWindowText(hWnd, sb, len); return(sb.ToString(0, len)); }
/// <summary> /// выборка всех запущенных приложений /// </summary> /// <param name="id">ид процесса приложения</param> private static void Enum(int id) { WinApi.EnumWindows((hWnd, lParam) => { if (WinApi.IsWindowVisible(hWnd) && (WinApi.GetWindowTextLength(hWnd) != 0)) { if (WinApi.IsIconic(hWnd) != 0 && WinApi.GetPlacement(hWnd).showCmd.ToString() == "Minimized") { FindCurProc(id, hWnd); } else { ; } } return(true); }, IntPtr.Zero); }