Пример #1
0
        public WinInfoItemCollection GetSysWinTitles()
        {
            _SysWinTitles.Clear();

            //user32.EnumWindowsProc ewp = new user32.EnumWindowsProc(ADA_EnumWindowsProc);
            //user32.EnumWindows(ewp, 0);
            Process[] localAll = Process.GetProcesses();
            foreach (Process localProcess in localAll)
            {
                if (!string.IsNullOrEmpty(localProcess.MainWindowTitle))
                {
                    WinInfoItem winInfo = new WinInfoItem();
                    winInfo.Title = localProcess.MainWindowTitle;

                    winInfo.HWnd = localProcess.MainWindowHandle;
                    try
                    {
                        Icon icon = Icon.ExtractAssociatedIcon(localProcess.MainModule.FileName);
                        if (icon != null)
                        {
                            winInfo.Icon = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle, new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions());
                        }
                    }
                    catch (Exception e)
                    {
                        //MessageBox.Show(localProcess.MainWindowTitle + " e:" + e.ToString());
                    }

                    _SysWinTitles.Add(winInfo);
                }
            }

            return _SysWinTitles;
        }
Пример #2
0
        public WinInfoItemCollection GetSysWinTitles()
        {
            _SysWinTitles.Clear();

            //user32.EnumWindowsProc ewp = new user32.EnumWindowsProc(ADA_EnumWindowsProc);
            //user32.EnumWindows(ewp, 0);
            Process[] localAll = Process.GetProcesses();
            foreach (Process localProcess in localAll)
            {
                if (!string.IsNullOrEmpty(localProcess.MainWindowTitle))
                {
                    WinInfoItem winInfo = new WinInfoItem();
                    winInfo.Title = localProcess.MainWindowTitle;

                    winInfo.HWnd = localProcess.MainWindowHandle;
                    try
                    {
                        Icon icon = Icon.ExtractAssociatedIcon(localProcess.MainModule.FileName);
                        if (icon != null)
                        {
                            winInfo.Icon = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle, new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions());
                        }
                    }
                    catch (Exception e)
                    {
                        //MessageBox.Show(localProcess.MainWindowTitle + " e:" + e.ToString());
                    }

                    _SysWinTitles.Add(winInfo);
                }
            }

            return(_SysWinTitles);
        }