Example #1
0
        public static ImageSource GetAppIcon(IntPtr hwnd)
        {
            try
            {
                IntPtr hIcon = default(IntPtr);
                hIcon = WinApiManager.SendMessage(hwnd, WinApiManager.WM_GETICON, WinApiManager.ICON_SMALL2, IntPtr.Zero);

                if (hIcon == IntPtr.Zero)
                {
                    hIcon = WinApiManager.GetClassLongPtr(hwnd, -14); // GCL_HICON
                }
                if (hIcon == IntPtr.Zero)
                {
                    hIcon = WinApiManager.LoadIcon(IntPtr.Zero, (IntPtr)0x7F00);
                }

                if (hIcon != IntPtr.Zero)
                {
                    Bitmap bmp  = new Bitmap(Icon.FromHandle(hIcon).ToBitmap(), 64, 64);
                    IntPtr hbmp = bmp.GetHbitmap();
                    return(Imaging.CreateBitmapSourceFromHBitmap(hbmp, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                }
            } catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(null);
        }
Example #2
0
 public static void RestoreWindow(IntPtr hwnd)
 {
     if (hwnd != IntPtr.Zero)
     {
         Console.WriteLine("Restore Window: " + GetWindowTitle(hwnd));
         WinApiManager.SendMessage(hwnd, WinApiManager.WM_SYSCOMMAND, WinApiManager.SC_RESTORE, IntPtr.Zero);
     }
 }
Example #3
0
 public static void MaximizeWindow(IntPtr hwnd)
 {
     if (hwnd != IntPtr.Zero)
     {
         Console.WriteLine("Maximize Window: " + GetWindowTitle(hwnd));
         WinApiManager.SendMessage(hwnd, WinApiManager.WM_SYSCOMMAND, WinApiManager.SC_MAXIMIZE, IntPtr.Zero);
     }
 }
Example #4
0
 public static void CloseWindow(IntPtr hwnd)
 {
     if (hwnd != IntPtr.Zero)
     {
         Console.WriteLine("Close Window:" + GetWindowTitle(hwnd));
         WinApiManager.SendMessage(hwnd, WinApiManager.WM_CLOSE, 0, IntPtr.Zero);
     }
 }