예제 #1
0
            /// <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);
            }
예제 #2
0
            /// <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);
            }
예제 #3
0
            /// <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));
            }
예제 #4
0
 /// <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);
 }