예제 #1
0
        private bool EnumWindowsCallback(IntPtr hWnd, IntPtr lParam)
        {
            int style   = ExternalAPI.GetWindowLong(hWnd, -16);
            int Exstyle = ExternalAPI.GetWindowLong(hWnd, -20);

            if (!ExternalAPI.IsWindowVisible(hWnd))
            {
                return(true);
            }

            // Ignore Popup windows
            if ((style & 0x80000000) != 0)
            {
                return(true);
            }

            uint          ProcessID;
            StringBuilder TempString = new StringBuilder();

            ExternalAPI.GetWindowThreadProcessId(hWnd, out ProcessID);

            IntPtr ProcessHandle = ExternalAPI.OpenProcess(0x0400, false, ProcessID);

            TempString.EnsureCapacity(1024);
            ExternalAPI.GetModuleFileNameEx(ProcessHandle, IntPtr.Zero, TempString, TempString.Capacity);

            if (TempString.ToString() == System.Reflection.Assembly.GetExecutingAssembly().Location)
            {
                return(true);
            }

            WindowData Entry;

            Entry.Handle = hWnd;
            Entry.Name   = System.IO.Path.GetFileNameWithoutExtension(TempString.ToString());

            ExternalAPI.CloseHandle(ProcessHandle);

            int size = ExternalAPI.GetWindowTextLength(hWnd);

            if (size != 0)
            {
                TempString.EnsureCapacity(size + 1);
                ExternalAPI.GetWindowText(hWnd, TempString, TempString.Capacity);

                Entry.Title = TempString.ToString();
            }
            else
            {
                Entry.Title = "";
            }

            WindowDropdown.Items.Add(Entry);

            return(true);
        }
예제 #2
0
파일: MainForm.cs 프로젝트: FoxCutter/Tools
            public bool EnumWindowsCallback(IntPtr hWnd, IntPtr lParam)
            {
                int style   = ExternalAPI.GetWindowLong(hWnd, -16);
                int Exstyle = ExternalAPI.GetWindowLong(hWnd, -20);

                if (!ExternalAPI.IsWindowVisible(hWnd))
                {
                    return(true);
                }

                // Ignore Popup windows
                if ((style & 0x80000000) != 0)
                {
                    return(true);
                }

                uint          ProcessID;
                StringBuilder TempString = new StringBuilder();

                ExternalAPI.GetWindowThreadProcessId(hWnd, out ProcessID);

                IntPtr ProcessHandle = ExternalAPI.OpenProcess(0x0400, false, ProcessID);

                TempString.EnsureCapacity(1024);
                ExternalAPI.GetModuleFileNameEx(ProcessHandle, IntPtr.Zero, TempString, TempString.Capacity);
                ExternalAPI.CloseHandle(ProcessHandle);

                string ExeName = System.IO.Path.GetFileNameWithoutExtension(TempString.ToString());

                if (Name.Equals(ExeName, StringComparison.InvariantCultureIgnoreCase))
                {
                    if (MatchTitle)
                    {
                        int size = ExternalAPI.GetWindowTextLength(hWnd);
                        if (size != 0)
                        {
                            TempString.EnsureCapacity(size + 1);
                            ExternalAPI.GetWindowText(hWnd, TempString, TempString.Capacity);

                            if (TempString.ToString() == Title)
                            {
                                Handle = hWnd;
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        Handle = hWnd;
                        return(false);
                    }
                }

                return(true);
            }