Ejemplo n.º 1
0
        public static ObservableCollection <AppsModel> GetHandles()
        {
            var collection = new List <string>();

            ObservableCollection <AppsModel> namesOut = new ObservableCollection <AppsModel>();

            user32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
            {
                StringBuilder strbTitle = new StringBuilder(255);
                int           nLength   = user32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
                string        strTitle  = strbTitle.ToString();

                if (user32.IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false)
                {
                    collection.Add(strTitle);
                }
                return(true);
            };

            if (user32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero))
            {
                foreach (var item in collection)
                {
                    if (item != "Program Manager" && item != "Пуск")
                    {
                        AppsModel temp = new AppsModel();
                        temp.AppsDescription      = item;
                        temp.AppsWorkingCondition = "Работает";
                        namesOut.Add(temp);
                    }
                }
            }
            return(namesOut);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var collection = new List <string>();
            var Kader      = new user32.RECT();
            var Kader3     = new user32.RECT();

            cQuote = Convert.ToChar(34);
            System.Console.WriteLine("*******************************************************************************");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("* Child v0.0.1                                                                *");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("* Lists child windows of desktop windows.                                     *");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("* use: Child sClass sTitle                                                    *");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("* sClass      Classname                                                       *");
            System.Console.WriteLine("* sTitle      Window Title                                                    *");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("* Copyright (c) 2014  Geert-Jan Uijtdewilligen                                *");
            System.Console.WriteLine("* This is free open source software that comes with no warranty, and you are  *");
            System.Console.WriteLine("* welcome to redistribute it under the terms of the GNU General Public License*");
            System.Console.WriteLine("* as published by the Free Software Foundation https://www.gnu.org/licenses/  *");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("*******************************************************************************");
            if (args.Length != 2)
            {
                System.Console.WriteLine("Please enter arguments: classname, window title.");
            }
            else
            {
                sClass = args[0];
                sTitle = args[1];
                user32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
                {
                    StringBuilder strbTitle = new StringBuilder(255);
                    int           nLength   = user32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
                    string        strTitle  = strbTitle.ToString();
                    StringBuilder strbClass = new StringBuilder(255);
                    int           cLength   = user32.GetClassName(hWnd, strbClass, strbClass.Capacity + 1);
                    string        strClass  = strbClass.ToString();
                    if (strClass == sClass && string.IsNullOrEmpty(strClass) == false && strTitle == sTitle)
                    {
                        //bool retval = user32.SetForegroundWindow(hWnd);           // Bring window on foreground
                        bool retval2 = user32.GetWindowRect(hWnd, out Kader);
                        collection.Add(" ");
                        collection.Add("Title                     : " + strTitle);
                        collection.Add("Class                     : " + strClass);
                        collection.Add("Handle                    : " + hWnd.ToString());
                        collection.Add("Return                    : " + retval2.ToString());
                        collection.Add("Window Rectangle Top      : " + Kader.Top.ToString());
                        collection.Add("Window Rectangle Bottom   : " + Kader.Bottom.ToString());
                        collection.Add("Window Rectangle Left     : " + Kader.Left.ToString());
                        collection.Add("Window Rectangle Right    : " + Kader.Right.ToString());

                        int    iCnt = 1;
                        string sCnt = "000" + iCnt.ToString();

                        IntPtr        hWndChild1 = user32.FindWindowEx(hWnd, IntPtr.Zero, null, IntPtr.Zero);
                        bool          retval3    = user32.GetWindowRect(hWndChild1, out Kader3);
                        StringBuilder strbTitle1 = new StringBuilder(255);
                        int           nLength1   = user32.GetWindowText(hWndChild1, strbTitle1, strbTitle1.Capacity + 1);
                        string        strTitle1  = strbTitle1.ToString();
                        StringBuilder strbClass1 = new StringBuilder(255);
                        int           cLength1   = user32.GetClassName(hWndChild1, strbClass1, strbClass1.Capacity + 1);
                        string        strClass1  = strbClass1.ToString();
                        collection.Add("                            ");
                        collection.Add("Child " + sCnt.Substring((sCnt.Length) - 3, 3) + " Title           : " + strTitle1);
                        collection.Add("Class                     : " + strClass1);
                        collection.Add("Handle                    : " + hWndChild1.ToString());
                        collection.Add("Return                    : " + retval3.ToString());
                        collection.Add("Client Rectangle Top      : " + Kader3.Top.ToString());
                        collection.Add("Client Rectangle Bottom   : " + Kader3.Bottom.ToString());
                        collection.Add("Client Rectangle Left     : " + Kader3.Left.ToString());
                        collection.Add("Client Rectangle Right    : " + Kader3.Right.ToString());

                        while (!(hWndChild1 == IntPtr.Zero))
                        {
                            iCnt++;
                            sCnt       = "000" + iCnt.ToString();
                            hWndChild1 = user32.FindWindowEx(hWnd, hWndChild1, null, IntPtr.Zero);
                            retval3    = user32.GetWindowRect(hWndChild1, out Kader3);
                            strbTitle1 = new StringBuilder(255);
                            nLength1   = user32.GetWindowText(hWndChild1, strbTitle1, strbTitle1.Capacity + 1);
                            strTitle1  = strbTitle1.ToString();
                            strbClass1 = new StringBuilder(255);
                            cLength1   = user32.GetClassName(hWndChild1, strbClass1, strbClass1.Capacity + 1);
                            strClass1  = strbClass1.ToString();
                            if (retval3)
                            {
                                collection.Add("                            ");
                                collection.Add("Child " + sCnt.Substring((sCnt.Length) - 3, 3) + " Title           : " + strTitle1);
                                collection.Add("Class                     : " + strClass1);
                                collection.Add("Handle                    : " + hWndChild1.ToString());
                                collection.Add("Return                    : " + retval3.ToString());
                                collection.Add("Client Rectangle Top      : " + Kader3.Top.ToString());
                                collection.Add("Client Rectangle Bottom   : " + Kader3.Bottom.ToString());
                                collection.Add("Client Rectangle Left     : " + Kader3.Left.ToString());
                                collection.Add("Client Rectangle Right    : " + Kader3.Right.ToString());
                            }
                        }
                    }
                    return(true);
                };
                if (user32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero))
                {
                    foreach (var item in collection)
                    {
                        Console.WriteLine(item);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            eShowOption = user32.ShowWindowCommands.Restore;
            System.Console.WriteLine("*******************************************************************************");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("* Show v0.0.1                                                                 *");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("* Show a window by classname                                                  *");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("* use: show [sWinClass] --sShowOption(default:--restore)                      *");
            System.Console.WriteLine("* if no class string is given, list all window classes.                       *");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("* sShowOption can be:                                                         *");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("*      hide, shownormal, showminimized, showmaximized, maximize,              *");
            System.Console.WriteLine("*      shownormalnoactivate, show, minimize, showminnoactivate,               *");
            System.Console.WriteLine("*      shownoactivate, restore, showdefault, forceminimized.                  *");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("* Copyright (c) 2014  Geert-Jan Uijtdewilligen                                *");
            System.Console.WriteLine("* This is free open source software that comes with no warranty, and you are  *");
            System.Console.WriteLine("* welcome to redistribute it under the terms of the GNU General Public License*");
            System.Console.WriteLine("* as published by the Free Software Foundation https://www.gnu.org/licenses/  *");
            System.Console.WriteLine("*                                                                             *");
            System.Console.WriteLine("*******************************************************************************");
            if (args.Length == 1)
            {
                sWinClass = args[0];
            }
            if (args.Length == 2)
            {
                sWinClass   = args[0];
                sShowOption = args[1];
                String[] aOption = { "--hide", "--shownormal", "--showminimized", "--showmaximized", "--maximize", "--shownormalnoactivate", "--show", "--minimize", "--showminnoactivate", "--shownoactivate", "--restore", "--showdefault", "--forceminimized" };
                user32.ShowWindowCommands[] aeOption = { user32.ShowWindowCommands.Hide, user32.ShowWindowCommands.ShowNormal, user32.ShowWindowCommands.ShowMinimized, user32.ShowWindowCommands.ShowMaximized, user32.ShowWindowCommands.Maximize, user32.ShowWindowCommands.ShowNormalNoActivate, user32.ShowWindowCommands.Show, user32.ShowWindowCommands.Minimize, user32.ShowWindowCommands.ShowMinNoActivate, user32.ShowWindowCommands.ShowNoActivate, user32.ShowWindowCommands.Restore, user32.ShowWindowCommands.ShowDefault, user32.ShowWindowCommands.ForceMinimized };
                for (int i = 0; i < 13; i++)
                {
                    if (sShowOption == aOption[i])
                    {
                        eShowOption = aeOption[i];
                    }
                }
            }

            var collection = new List <string>();

            user32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
            {
                StringBuilder strbTitle = new StringBuilder(255);
                int           nLength   = user32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
                string        strTitle  = strbTitle.ToString();
                StringBuilder strbClass = new StringBuilder(255);
                int           cLength   = user32.GetClassName(hWnd, strbClass, strbClass.Capacity + 1);
                string        strClass  = strbClass.ToString();
                if (string.IsNullOrEmpty(strClass) == false && string.IsNullOrEmpty(strTitle) == false && strClass.Contains("IME") == false)
                {
                    if (args.Length == 0)
                    {
                        collection.Add("Title: " + strTitle);
                        collection.Add("Class: " + strClass);
                    }
                    if (sWinClass != null)
                    {
                        if (strClass.Contains(sWinClass))
                        {
                            bool retval3 = user32.ShowWindow(hWnd, eShowOption);
                            collection.Add("Returnvalue               : " + retval3.ToString());
                        }
                    }
                }

                return(true);
            };
            if (user32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero))
            {
                foreach (var item in collection)
                {
                    Console.WriteLine(item);
                }
            }
            /*Console.Read();*/
        }