Пример #1
0
 private static extern int EnumPropsA(IntPtr hWnd, PROPENUMPROCA lpEnumFunc);
Пример #2
0
        public static List <WindowInfo> GetRunApplicationInfo(Form form)
        {
            List <WindowInfo> appList = new List <WindowInfo>();

            myPropeNumProca = new PROPENUMPROCA(myPropeNumProcaReport);
            try
            {
                int handle = (int)form.Handle;
                //   int handle = (int)GetDesktopWindow();
                int    hwCurr;
                IntPtr hwChild;
                hwCurr = GetWindow(handle, GW_HWNDFIRST);
                // hwCurr = GetWindow(handle, 5);
                while (hwCurr > 0)
                {
                    //| WS_BORDER
                    int  isTask     = (WS_VISIBLE);
                    int  lngStyle   = GetWindowLongA(hwCurr, GWL_STYLE);
                    bool taskWindow = ((lngStyle & isTask) == isTask);
                    if (taskWindow)
                    {
                        int           length = GetWindowTextLength(new IntPtr(hwCurr));
                        StringBuilder sb     = new StringBuilder(256);
                        GetWindowText(hwCurr, sb, sb.Capacity);
                        string strTitle = sb.ToString();
                        if (!string.IsNullOrEmpty(strTitle))
                        {
                            WindowInfo wnd = new WindowInfo();
                            wnd.hWnd         = new IntPtr(hwCurr);
                            wnd.szWindowName = strTitle;                        //窗口title名称
                            sb.Clear();
                            GetClassNameW(new IntPtr(hwCurr), sb, sb.Capacity); //类名
                            wnd.cls = sb.ToString();
                            sb.Clear();
                            GetWindowTextW(new IntPtr(hwCurr), sb, sb.Capacity);
                            wnd.app = sb.ToString();
                            int PID;
                            GetWindowThreadProcessId(new IntPtr(hwCurr), out PID);
                            wnd.PID = PID.ToString();
                            sb.Clear();
                            GetWindowModuleFileNameA(new IntPtr(hwCurr), sb, sb.Capacity);
                            wnd.AppPath = sb.ToString();
                            sb.Clear();
                            // GetClassInfoExW(new IntPtr(hwCurr), sb, sb.Capacity);获取不到值
                            // wnd.marks = sb.ToString();
                            // GetPropA(new IntPtr(hwCurr), sb);
                            // wnd.marks = sb.ToString();
                            //枚举属性
                            // EnumPropsA(new IntPtr(hwCurr), myPropeNumProca);

                            TITLEBARINFO pti = new TITLEBARINFO();
                            pti.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(pti);
                            bool result = GetTitleBarInfo(new IntPtr(hwCurr), ref pti);
                            // wnd.marks = pti.rgstate.FirstOrDefault()..ToString();
                            appList.Add(wnd);
                        }
                    }
                    hwCurr = GetWindow(hwCurr, GW_HWNDNEXT);
                }
                return(appList);
            }
            catch (Exception ex)
            {
                throw;
            }
        }