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

            /// <summary>
            /// Активация окна
            /// </summary>
            static public void SwitchToCurrentInstance()
            {
                IntPtr hWnd = mainhWnd;

                sendMsg(hWnd, IntPtr.Zero, WinApi.SW_RESTORE);

                if (hWnd != IntPtr.Zero)
                {
                    // Restore window if minimised. Do not restore if already in
                    // normal or maximised window state, since we don't want to
                    // change the current state of the window.
                    if (WinApi.IsIconic(hWnd) != 0)
                    {
                        WinApi.ShowWindow(hWnd, WinApi.SW_RESTORE);
                    }
                    else
                    {
                        ;
                    }
                    // Set foreground window.
                    WinApi.SetForegroundWindow(hWnd);
                }
            }