Exemple #1
0
        /// <summary>
        /// Given a Window object, creates a new ListviewItem and
        /// adds it to lstApps. This correctly sets the Image stuff
        /// to get the App icon right.
        /// </summary>
        /// <param name="w"></param>
        private void AddWindowToListview(Window w)
        {
            lstApps.LargeImageList.Images.Add(w.HWnd, w.BigIcon);

            lstApps.SmallImageList.Images.Add(w.HWnd, w.BigIcon);
            ListViewItem item = new ListViewItem(w.Title, w.HWnd);
            item.Name = w.HWnd;

            lstApps.Items.Add(item);
        }
Exemple #2
0
        /// <summary>
        /// Function to use with a delegate
        /// This function receive a window handle and a pointer to lparam that can be anything
        /// 
        /// For us we use this function to find active application associate with a visible and accessible 
        /// window.  Window can have to kind of style if create with CreateWindowEx
        /// 
        /// dwStyle and dwStyleEx.
        /// 
        /// Whate we need  : 
        /// 
        /// - Visible window : WS_VISIBLE  OR 
        /// 
        /// This properties forces a window to be on top and not to be in the task bar. 
        /// So this only property doesn't guarantee that the window will be really visble or drawn on the desktop
        /// 
        /// Properties that can make it wrong are :
        /// 
        /// WS_EX_TOOLWINDOW : this property makes the window not appearing in the task bar and tasks manager. 
        /// This kind of window is used as a floating bar. So its small, doesn't have an icon and can have 
        /// a system menu but ITS NOT AN APPLICATION            
        /// 
        /// next, 
        /// 
        /// we dont want child window. 
        /// 
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        private static bool EnumDesktopWindows_cb(int hwnd, IntPtr lParam)
        {
            List<Window> list = (List<Window>)GCHandle.FromIntPtr(lParam).Target;

            int style = GetWindowLongPtr(hwnd, GWL_STYLE);
            int styleEx = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
            if (((styleEx & WS_EX_TOOLWINDOW) == 0) && ((style & WS_VISIBLE) != 0) && ((style & WS_CHILD) == 0))
            {
                try
                {
                    Window w = new Window(hwnd);
                    list.Add(w);
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                }
            }
            return true;
        }