Esempio n. 1
0
        public static bool enumWndProc(int hwnd, int lparam)
        {
            StringBuilder sb = new StringBuilder(1024);

            Win32Functions.GetWindowText(hwnd, sb, sb.Capacity);


            if (Win32Functions.IsWindowVisible(hwnd) && sb.ToString().Length > 0)
            {
                Bitmap icon = null;

                int result = 0;

                IntPtr hIcon = (IntPtr)0;

                Win32Functions.SendMessageTimeout(hwnd, 0x007f, 1, 0, 0x0002, 1000, out result);
                hIcon = new IntPtr(result);

                if (hIcon == IntPtr.Zero)
                {
                    Win32Functions.SendMessageTimeout(hwnd, 0x007f, 0, 0, 0x0002, 1000, out result);
                    hIcon = new IntPtr(result);
                }

                if (hIcon == IntPtr.Zero)
                {
                    hIcon = (IntPtr)Win32Functions.GetClassLong((IntPtr)hwnd, (-14));
                }

                if (hIcon == IntPtr.Zero)
                {
                    hIcon = (IntPtr)Win32Functions.GetClassLong((IntPtr)hwnd, (-34));
                }

                if (hIcon == IntPtr.Zero)
                {
                    Win32Functions.SendMessageTimeout(hwnd, 0x0037,
                                                      0,
                                                      0,
                                                      0x0002,
                                                      1000, out result);
                    hIcon = new IntPtr(result);
                }

                if ((int)hIcon > 1)
                {
                    try
                    {
                        icon = Bitmap.FromHicon(hIcon);
                    }
                    catch { }
                }
                else
                {
                    //use a default icon..
                }
                func.Invoke(new ApplicationWindows(sb.ToString(), hwnd, icon));
            }

            return(true);
        }