Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public static bool IsAltTabWindow(IntPtr hwnd)
        {
            const uint WS_EX_TOOLWINDOW = 0x00000080;
            const uint DWMWA_CLOAKED    = 14;

            if (!WinApiManager.IsWindowVisible(hwnd))
            {
                return(false);
            }

            string title = GetWindowTitle(hwnd);

            if (title == null || title == "Menu" || title == "GestureWindow" || title == "BlockingWindow" || title == "AppList")
            {
                return(false);
            }

            WinApiManager.WINDOWINFO winInfo = new WinApiManager.WINDOWINFO(true);
            WinApiManager.GetWindowInfo(hwnd, ref winInfo);
            if ((winInfo.dwExStyle & WS_EX_TOOLWINDOW) != 0)
            {
                return(false);
            }

            uint CloakedVal;

            WinApiManager.DwmGetWindowAttribute(hwnd, DWMWA_CLOAKED, out CloakedVal, sizeof(uint));
            return(CloakedVal == 0);
        }
Exemplo n.º 3
0
 public static void ShowWindow(IntPtr hwnd)
 {
     if (hwnd != IntPtr.Zero)
     {
         Console.WriteLine("Show Window: " + GetWindowTitle(hwnd));
         WinApiManager.ShowWindow(hwnd, WinApiManager.SW_SHOW);
     }
 }
Exemplo n.º 4
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);
     }
 }
Exemplo n.º 5
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);
     }
 }
Exemplo n.º 6
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);
     }
 }
Exemplo n.º 7
0
        private static int GetWindowZOrder(IntPtr hWnd)
        {
            var zOrder = -1;

            while ((hWnd = WinApiManager.GetWindow(hWnd, 2)) != IntPtr.Zero)
            {
                zOrder++;
            }
            return(zOrder);
        }
Exemplo n.º 8
0
        public static String GetWindowTitle(IntPtr hWnd)
        {
            StringBuilder Buff = new StringBuilder(256);

            if (WinApiManager.GetWindowText(hWnd, Buff, 256) > 0)
            {
                return(Buff.ToString());
            }
            return(null);
        }
Exemplo n.º 9
0
 public static void MoveWindow(IntPtr hwnd, int xOffset, int yOffset)
 {
     if (hwnd != IntPtr.Zero)
     {
         WinApiManager.RECT rect = new WinApiManager.RECT();
         WinApiManager.GetWindowRect(hwnd, out rect);
         int width  = Math.Abs(rect.Right - rect.Left);
         int height = Math.Abs(rect.Bottom - rect.Top);
         int x      = Math.Max(0 - width / 2, Math.Min((int)WindowsHandler.GetScreenWidth() + width / 2, rect.Left + xOffset));
         int y      = Math.Max(0, Math.Min((int)WindowsHandler.GetScreenHeight(), rect.Top + yOffset));
         WinApiManager.SetWindowPos(hwnd, IntPtr.Zero, x, y, 0, 0, WinApiManager.SWP_NOSIZE | WinApiManager.SWP_NOACTIVATE | WinApiManager.SWP_NOZORDER | WinApiManager.SWP_SHOWWINDOW);
     }
 }
Exemplo n.º 10
0
        private static IntPtr GetLastVisibleActivePopUpOfWindow(IntPtr window)
        {
            IntPtr lastPopUp = WinApiManager.GetLastActivePopup(window);

            if (WinApiManager.IsWindowVisible(lastPopUp))
            {
                return(lastPopUp);
            }
            else if (lastPopUp == window)
            {
                return(IntPtr.Zero);
            }
            else
            {
                return(GetLastVisibleActivePopUpOfWindow(lastPopUp));
            }
        }
Exemplo n.º 11
0
 public static void ScaleWindow(IntPtr hwnd, double xRatio, double yRatio)
 {
     if (hwnd != IntPtr.Zero)
     {
         WinApiManager.RECT rect = new WinApiManager.RECT();
         WinApiManager.GetWindowRect(hwnd, out rect);
         int width   = Math.Abs(rect.Right - rect.Left);
         int height  = Math.Abs(rect.Bottom - rect.Top);
         int x       = rect.Left;
         int y       = rect.Top;
         int cx      = x + width / 2;
         int cy      = y + height / 2;
         int nWidth  = (int)((double)width * xRatio);
         int nHeight = (int)((double)height * yRatio);
         int nx      = cx - nWidth / 2;
         int ny      = cy - nHeight / 2;
         WinApiManager.SetWindowPos(hwnd, IntPtr.Zero, x, y, nWidth, nHeight, WinApiManager.SWP_NOACTIVATE | WinApiManager.SWP_NOZORDER | WinApiManager.SWP_SHOWWINDOW);
     }
 }
Exemplo n.º 12
0
        public static List <IntPtr> EnumerateWindow()
        {
            List <IntPtr> windows = new List <IntPtr>();

            WinApiManager.EnumWindows(delegate(IntPtr hwnd, int param)
            {
                if (!IsAltTabWindow(hwnd))
                {
                    return(true);
                }
                windows.Add(hwnd);
                return(true);
            }, 0);


            //Console.WriteLine(windows.Count);
            //foreach (IntPtr hWnd in windows)
            //{
            //    Console.WriteLine(GetWindowTitle(hWnd));
            //}
            return(windows);
        }
Exemplo n.º 13
0
 public static IntPtr GetWindowHandle(Window window)
 {
     return(WinApiManager.FindWindowByCaption(IntPtr.Zero, window.Title));
 }
Exemplo n.º 14
0
 public static IntPtr GetHandleFromTitle(string title)
 {
     return(WinApiManager.FindWindow("", title));
 }