public static string GetWindowName(IntPtr hwnd)
        {
            int           len = Win32Funcs.GetWindowTextLength(hwnd);
            StringBuilder sb  = new StringBuilder(len + 1);

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

            return(sb.ToString());
        }
Пример #2
0
        void SetupWindowCapture()
        {
            UpdateCursorInfo();

            // Get the device context
            if (isDesktop)
            {
                hdc = Win32Funcs.GetDC(IntPtr.Zero);
            }
            else
            {
                hdc = Win32Funcs.GetWindowDC(hwnd);
            }

            // Create a device context to use yourself
            hDest = Win32Funcs.CreateCompatibleDC(hdc);

            Win32Types.RECT windowRect;

            if (isDesktop)
            {
                Win32Types.MonitorInfo mi = new Win32Types.MonitorInfo();
                mi.cbSize = Marshal.SizeOf(mi);
                Win32Funcs.GetMonitorInfo(hwnd, ref mi);
                windowRect = mi.rcMonitor;
            }
            else
            {
                // Get the size of the window
                Win32Funcs.GetWindowRect(hwnd, out windowRect);
            }

            windowWidth  = windowRect.Width;
            windowHeight = windowRect.Height;

            if (onlyCaptureMouse)
            {
                windowWidth  = cursorRect.Width;
                windowHeight = cursorRect.Height;
            }

            // From http://stackoverflow.com/questions/7502588/createcompatiblebitmap-and-createdibsection-memory-dcs
            Win32Types.BitmapInfo bmi = new Win32Types.BitmapInfo();
            bmi.bmiHeader.Init();
            bmi.bmiHeader.biSize        = (uint)Marshal.SizeOf(bmi);
            bmi.bmiHeader.biWidth       = windowWidth;
            bmi.bmiHeader.biHeight      = -windowHeight; // top-down
            bmi.bmiHeader.biPlanes      = 1;
            bmi.bmiHeader.biBitCount    = 24;
            bmi.bmiHeader.biCompression = Win32Consts.BitmapCompressionMode.BI_RGB;


            IntPtr outBits;

            curRenderingBitmap = Win32Funcs.CreateDIBSection(hdc, ref bmi, (uint)Win32Consts.DIB_Color_Mode.DIB_PAL_COLORS, out outBits, IntPtr.Zero, (uint)0);
        }
Пример #3
0
        public bool LoopThroughWindows(IntPtr hWnd, IntPtr lParam)
        {
            string hwndString = IntPtrToString(hWnd);



            StringBuilder sb = new StringBuilder(10000);

            Win32Funcs.GetClassName(hWnd, sb, sb.Capacity);
            string windowTitle = sb.ToString();

            bool isAltTab = IsAltTabWindow(hWnd, windowTitle);

            if (isAltTab)
            {
                if (!tempWindowsFoundSoFar.ContainsKey(hwndString))
                {
                    thingsToAdd.Add(hWnd);
                }

                shouldKeep[hwndString] = true;
                return(true);
            }



            bool isDialog = isDialogBox(hWnd, windowTitle);

            if (isDialog)
            {
                shouldKeep[hwndString] = true;
                if (Win32Funcs.IsWindowVisible(hWnd))
                {
                    if (!tempWindowsFoundSoFar.ContainsKey(hwndString))
                    {
                        thingsToAdd.Add(hWnd);
                    }
                }

                return(true);
            }


            if (tempWindowsFoundSoFar.ContainsKey(hwndString))
            {
                thingsToRemove.Add(hWnd);
                shouldKeep[hwndString] = true;
                return(true);
            }

            return(true);
        }
Пример #4
0
        public bool IsAltTabWindow(IntPtr window, string windowTitle)
        {
            if (windowTitle == "Jump List")
            {
                return(false);
            }

            if (windowTitle == "TaskListThumbnailWnd")
            {
                return(false);
            }

            if (windowTitle == "Unity Personal (64bit) - yams.unity - Floating Windows - PC, Mac & Linux Standalone <DX11>" || windowTitle == "Multiscreens" || windowTitle == "UnityContainerWndClass")
            {
                return(true);
            }

            //if (windowTitle ==
            if (window == taskbarHandle)
            {
                return(true);
            }
            //if (window == Win32funcs.GetShellWindow())   //Desktop
            //	return false;

            //http://stackoverflow.com/questions/210504/enumerate-windows-like-alt-tab-does
            //http://blogs.msdn.com/oldnewthing/archive/2007/10/08/5351207.aspx
            //1. For each visible window, walk up its owner chain until you find the root owner.
            //2. Then walk back down the visible last active popup chain until you find a visible window.
            //3. If you're back to where you're started, (look for exceptions) then put the window in the Alt+Tab list.
            IntPtr root = Win32Funcs.GetAncestor(window, Win32Consts.GetAncestorFlags.GetRootOwner);

            if (GetLastVisibleActivePopUpOfWindow(root) == window)
            {
                Win32Types.WindowInfo wi = new Win32Types.WindowInfo(window);

                if (wi.className == "#32768" ||
                    wi.className == "Shell_TrayWnd" ||                   //Windows taskbar
                    wi.className == "DV2ControlHost" ||                  //Windows startmenu, if open
                    (wi.className == "Button" && wi.title == "Start") || //Windows startmenu-button.
                    wi.className == "MsgrIMEWindowClass" ||              //Live messenger's notifybox i think
                    wi.className == "SysShadow" ||                       //Live messenger's shadow-hack
                    wi.className.StartsWith("WMP9MediaBarFlyout"))       //WMP's "now playing" taskbar-toolbar
                {
                    return(false);
                }

                return(true);
            }
            return(false);
        }
Пример #5
0
        // Apply WinCapture/WindowShader shader to any resulting textures
        public WindowCaptureManager()
        {
            windowsHolder                 = new WindowsHolder();
            windowsHolder.OnAddWindow    += OnAddWindowFound;
            windowsHolder.OnRemoveWindow += OnRemoveWindowFound;

            windowCapturers = new Dictionary <IntPtr, WindowCapture>();

            List <Win32Types.DisplayInfo> monitorInfos = Win32Funcs.GetDisplays();

            for (int i = 0; i < monitorInfos.Count; i++)
            {
                windowCapturers[monitorInfos[i].hwnd] = new WindowCapture(monitorInfos[i].hwnd, true);
                windowCapturers[monitorInfos[i].hwnd].windowInfo.title = "desktopBitBlt" + i;
            }
        }
Пример #6
0
        private IntPtr GetLastVisibleActivePopUpOfWindow(IntPtr window)
        {
            IntPtr lastPopUp = Win32Funcs.GetLastActivePopup(window);

            if (Win32Funcs.IsWindowVisible(lastPopUp))
            {
                return(lastPopUp);
            }
            else if (lastPopUp == window)
            {
                return(IntPtr.Zero);
            }
            else
            {
                return(GetLastVisibleActivePopUpOfWindow(lastPopUp));
            }
        }
Пример #7
0
        public WindowGetterWorker()
        {
            this.windowLock       = new System.Object();
            tempWindowsFoundSoFar = new Dictionary <string, IntPtr>(100);

            thingsToAdd    = new List <IntPtr>(100);
            thingsToRemove = new List <IntPtr>(100);

            myThingsToAdd    = new List <IntPtr>(100);
            myThingsToRemove = new List <IntPtr>(100);

            shouldKeep = new Dictionary <string, bool>(100);

            taskbarHandle = Win32Funcs.FindWindow("Shell_TrayWnd", null);

            mapToString = new Dictionary <int, string>();

            lastTimeRan = Time.time;
        }
Пример #8
0
        void CleanupWindowCapture()
        {
            if (hdc != IntPtr.Zero)
            {
                Win32Funcs.ReleaseDC(hwnd, hdc);
                hdc = IntPtr.Zero;
            }

            if (hDest != IntPtr.Zero)
            {
                Win32Funcs.DeleteDC(hDest);
                hDest = IntPtr.Zero;
            }

            if (curRenderingBitmap != IntPtr.Zero)
            {
                Win32Funcs.DeleteObject(curRenderingBitmap);
                curRenderingBitmap = IntPtr.Zero;
            }
        }
Пример #9
0
        public bool isDialogBox(IntPtr hwnd, string windowTitle)
        {
            if (windowTitle == "Jump List")
            {
                return(true);
            }
            if (hwnd == taskbarHandle)
            {
                return(false);
            }

            if (windowTitle == "Program Manager")
            {
                return(false);
            }


            if (!Win32Funcs.IsWindow(hwnd))
            {
                return(false);
            }

            return(true);
        }
Пример #10
0
 public static bool GetScreenRect(out Win32Types.RECT result)
 {
     return(Win32Funcs.GetWindowRect(Win32Funcs.GetDesktopWindow(), out result));
 }
Пример #11
0
        public byte[] GetWindowBitmapUsingBitBlt(out int numBytesPerRow)
        {
            windowRect = new Win32Types.RECT();
            bool result;

            if (isDesktop)
            {
                Win32Types.MonitorInfo mi = new Win32Types.MonitorInfo();
                mi.cbSize = Marshal.SizeOf(mi);
                result    = Win32Funcs.GetMonitorInfo(hwnd, ref mi);
                if (result)
                {
                    windowRect = mi.rcMonitor;
                }
            }
            else
            {
                // Get the size of the window
                result = Win32Funcs.GetWindowRect(hwnd, out windowRect);
            }

            if (onlyCaptureMouse)
            {
                windowRect = cursorRect;
                result     = true;
            }

            if (!result)
            {
                // Failed getting rect
                numBytesPerRow = 0;

                return(null);
            }

            // If they resized the window we need to reinit the memory
            if (windowWidth != windowRect.Width || windowHeight != windowRect.Height)
            {
                CleanupWindowCapture();
                SetupWindowCapture();
                windowWidth  = windowRect.Width;
                windowHeight = windowRect.Height;
            }



            // Use the previously created device context with the bitmap
            Win32Funcs.SelectObject(hDest, curRenderingBitmap);

            if (onlyCaptureMouse)
            {
                if (isDesktop)
                {
                    Win32Funcs.BitBlt(hDest, 0, 0, cursorRect.Width, cursorRect.Height, hdc, windowRect.Left, windowRect.Top, Win32Consts.TernaryRasterOperations.SRCCOPY);
                }
                else
                {
                    Win32Funcs.BitBlt(hDest, cursorRect.Left, cursorRect.Height, cursorRect.Width, cursorRect.Height, hdc, 0, 0, Win32Consts.TernaryRasterOperations.SRCCOPY);
                }
                Win32Funcs.DrawIconEx(hDest, 1, 1, cursorHandle, cursorRect.Width, cursorRect.Height, 0, IntPtr.Zero, Win32Consts.DI_NORMAL);
            }
            else
            {
                // Copy from the screen device context to the bitmap device context
                if (isDesktop)
                {
                    Win32Funcs.BitBlt(hDest, 0, 0, windowRect.Width, windowRect.Height, hdc, windowRect.Left, windowRect.Top, Win32Consts.TernaryRasterOperations.SRCCOPY);
                }
                else
                {
                    Win32Funcs.BitBlt(hDest, 0, 0, windowRect.Width, windowRect.Height, hdc, 0, 0, Win32Consts.TernaryRasterOperations.SRCCOPY);
                }
                Win32Funcs.DrawIconEx(hDest, cursorRect.Left, cursorRect.Top, cursorHandle, cursorRect.Width, cursorRect.Height, 0, IntPtr.Zero, Win32Consts.DI_NORMAL);
            }



            Win32Types.BITMAP bitmap = new Win32Types.BITMAP();

            Win32Funcs.GetObjectBitmap(curRenderingBitmap, Marshal.SizeOf(bitmap), ref bitmap);

            numBytesPerRow = bitmap.bmWidthBytes;

            if (bitmapBytes == null || bitmapBytes.Length != bitmap.bmHeight * bitmap.bmWidthBytes)
            {
                bitmapBytes = new byte[bitmap.bmHeight * bitmap.bmWidthBytes];
            }


            if (bitmap.bmBits != IntPtr.Zero)
            {
                Marshal.Copy(bitmap.bmBits, bitmapBytes, 0, bitmapBytes.Length);
            }

            if (bitmapBytes == null || bitmapBytes.Length == 0)
            {
                return(null);
            }

            return(bitmapBytes);
        }
Пример #12
0
 public void GetRect()
 {
     Win32Funcs.GetWindowRect(hwnd, out windowRect);
 }
        public byte[] GetWindowBitmapUsingBitBlt(out int numBytesPerRow)
        {
            windowRect = new Win32Types.RECT();
            bool result;

            if (isDesktop)
            {
                Win32Types.MonitorInfo mi = new Win32Types.MonitorInfo();
                mi.cbSize = Marshal.SizeOf(mi);
                result    = Win32Funcs.GetMonitorInfo(hwnd, ref mi);
                if (result)
                {
                    windowRect = mi.rcMonitor;
                }
            }
            else
            {
                // Get the size of the window
                result = Win32Funcs.GetWindowRect(hwnd, out windowRect);
            }

            if (onlyCaptureMouse)
            {
                windowRect = cursorRect;
                result     = true;
            }

            if (!result)
            {
                // Failed getting rect
                numBytesPerRow = 0;

                return(null);
            }

            // If they resized the window we need to reinit the memory

            if (windowWidth != windowRect.Width || windowHeight != windowRect.Height)
            {
                CleanupWindowCapture();
                SetupWindowCapture();
                windowWidth  = windowRect.Width;
                windowHeight = windowRect.Height;
            }
            oldhDest = Win32Funcs.SelectObject(hDest, curRenderingBitmap);
            Win32Types.BITMAP bitmap = new Win32Types.BITMAP();
            Win32Funcs.GetObjectBitmap(curRenderingBitmap, Marshal.SizeOf(bitmap), ref bitmap);

            if (onlyCaptureMouse)
            {
                if (isDesktop)
                {
                    Win32Funcs.BitBlt(hDest, 0, 0, cursorRect.Width, cursorRect.Height, hdc, windowRect.Left, windowRect.Top, Win32Consts.TernaryRasterOperations.SRCCOPY);
                }
                else
                {
                    Win32Funcs.BitBlt(hDest, cursorRect.Left, cursorRect.Height, cursorRect.Width, cursorRect.Height, hdc, 0, 0, Win32Consts.TernaryRasterOperations.SRCCOPY);
                }
                Win32Funcs.DrawIconEx(hDest, 1, 1, cursorHandle, cursorRect.Width, cursorRect.Height, 0, IntPtr.Zero, Win32Consts.DI_NORMAL);
            }
            else
            {
                // Copy from the screen device context to the bitmap device context
                var testing = false;
                if (isDesktop)
                {
                    Win32Funcs.BitBlt(hDest, 0, 0, windowRect.Width, windowRect.Height, hdc, windowRect.Left, windowRect.Top, Win32Consts.TernaryRasterOperations.SRCCOPY);
                }
                else
                {
                    if (testing)
                    {
                        Win32Funcs.BitBlt(hDest, 0, 0, windowRect.Width, windowRect.Height, hdc, 0, 0, Win32Consts.TernaryRasterOperations.SRCCOPY);
                    }
                    else
                    {
                        if (needsGDIp)
                        {
                            Bitmap   map      = new Bitmap(windowRect.Width, windowRect.Height);
                            Graphics graphics = Graphics.FromHdc(hDest);
                            try
                            {
                                graphics.CopyFromScreen(new System.Drawing.Point(windowRect.Left, windowRect.Top), System.Drawing.Point.Empty, windowRect.Size, CopyPixelOperation.SourceCopy);
                            }
                            finally
                            {
                                map.Dispose();
                                graphics.Dispose();
                            }
                        }
                    }
                }
                Win32Funcs.DrawIconEx(hDest, cursorRect.Left, cursorRect.Top, cursorHandle, cursorRect.Width, cursorRect.Height, 0, IntPtr.Zero, Win32Consts.DI_NORMAL);
            }

            numBytesPerRow = bitmap.bmWidthBytes;

            if (bitmapBytes == null || bitmapBytes.Length != bitmap.bmHeight * bitmap.bmWidthBytes)
            {
                bitmapBytes = new byte[bitmap.bmHeight * bitmap.bmWidthBytes];
            }

            if (bitmap.bmBits != IntPtr.Zero)
            {
                Marshal.Copy(bitmap.bmBits, bitmapBytes, 0, bitmapBytes.Length);
            }

            if (bitmapBytes == null || bitmapBytes.Length == 0)
            {
                return(null);
            }
            Win32Funcs.DeleteObject(bitmap.bmBits);
            Win32Funcs.SelectObject(hDest, oldhDest);
            return(bitmapBytes);
        }
Пример #14
0
 public void AddWindows()
 {
     Win32Funcs.EnumWindows(new Win32Funcs.EnumWindowsProc(LoopThroughWindows), IntPtr.Zero);
 }
Пример #15
0
        public void UpdateWindows()
        {
            windowGetter.DoWork();
            List <IntPtr> actualThingsToAdd    = new List <IntPtr>(10);
            List <IntPtr> actualThingsToRemove = new List <IntPtr>(10);

            lock (windowGetter.windowLock)
            {
                for (int i = 0; i < windowGetter.myThingsToAdd.Count; i++)
                {
                    string curKey = IntPtrToString(windowGetter.myThingsToAdd[i]);
                    if (!(windows.ContainsKey(curKey)))
                    {
                        actualThingsToAdd.Add(windowGetter.myThingsToAdd[i]);
                    }
                }
                for (int i = 0; i < windowGetter.myThingsToRemove.Count; i++)
                {
                    string curKey = IntPtrToString(windowGetter.myThingsToRemove[i]);
                    if (windows.ContainsKey(curKey))
                    {
                        actualThingsToRemove.Add(windowGetter.myThingsToRemove[i]);
                    }
                }

                windowGetter.myThingsToAdd.Clear();
                windowGetter.myThingsToRemove.Clear();
            }
            for (int i = 0; i < actualThingsToAdd.Count; i++)
            {
                //WindowThing windowAdding = null;
                IntPtr hwnd       = actualThingsToAdd[i];
                string hwndString = IntPtrToString(hwnd);

                if (windows.ContainsKey(hwndString))
                {
                    continue;
                }

                StringBuilder sb = new StringBuilder(10000);
                Win32Funcs.GetClassName(hwnd, sb, sb.Capacity);
                string windowTitle = sb.ToString().Trim();


                if (windowGetter.IsAltTabWindow(hwnd, windowTitle))
                {
                    windowTypes[hwndString] = WindowType.Window;
                    //Win32window winWindowAdding = new Win32window(hwnd, baseManager);
                    //windowAdding = winWindowAdding;
                    //if (windowAdding.windowInfo.title == "Program Manager" && false)
                    //{
                    //temp windowAdding.windowObject.transform.position = baseManager.riftController.transform.position + baseManager.riftController.transform.forward * 50.0f;
                    //}
                    //else
                    //{
                    //    windowAdding.windowObject.transform.position = new Vector3(-100000, -100000, -100000);
                    //}



                    // Otherwise set it to default where you are looking as is done above once you focus on it


                    if (OnAddWindow != null)
                    {
                        OnAddWindow(hwnd);
                    }

                    windows[hwndString] = hwnd;

                    //bool setPosition = false;
                }
                else if (windowGetter.isDialogBox(hwnd, windowTitle))
                {
                    windowTypes[IntPtrToString(hwnd)] = WindowType.DialogBox;
                    //Win32dialogBox winDiagAdding = new Win32dialogBox(hwnd, baseManager, foregroundWindowThing);
                    //windowAdding = winDiagAdding;
                    if (OnAddDialogBox != null)
                    {
                        //OnAddDialogBox(hwnd, winDiagAdding);
                        OnAddDialogBox(hwnd);
                    }

                    windows[hwndString] = hwnd;
                }
                else
                {
                    continue;
                }
            }

            for (int i = 0; i < actualThingsToRemove.Count; i++)
            {
                IntPtr hwnd       = actualThingsToRemove[i];
                string hwndString = IntPtrToString(hwnd);


                if (windows.ContainsKey(hwndString))
                {
                    windows.Remove(hwndString);
                    if (windowTypes[hwndString] == WindowType.Window)
                    {
                        if (OnRemoveWindow != null)
                        {
                            OnRemoveWindow(hwnd);
                        }
                    }
                    else if (windowTypes[hwndString] == WindowType.DialogBox)
                    {
                        if (OnRemoveDialogBox != null)
                        {
                            OnRemoveDialogBox(hwnd);
                        }
                    }


                    /////if (windowRemoving.foregroundWindowThing != null && windowRemoving.foregroundWindowThing.hwnd == windowGetter.taskbarHandle)
                    ////{
                    //windowRemoving.numChancesLeft -= 1;
                    //if (windowRemoving.numChancesLeft == 0) {
                    //windows.Remove (hwndString);
                    //windowRemoving.Destroy ();
                    //}
                    ///// }

                    /*
                     * else
                     * {
                     *   if (windowRemoving.GetType() == typeof(Win32window))
                     *   {
                     *       if (hwnd == BaseManager.foregroundWindow)
                     *       {
                     *           //BaseManager.me.faceMouse.capturingClicks = true;
                     *       }
                     *       if (OnRemoveWindow != null)
                     *       {
                     *           OnRemoveWindow(hwnd, (Win32window)windowRemoving);
                     *       }
                     *   }
                     *   else if (windowRemoving.GetType() == typeof(Win32dialogBox))
                     *   {
                     *       if (OnRemoveDialogBox != null)
                     *       {
                     *           OnRemoveDialogBox(hwnd, (Win32dialogBox)windowRemoving);
                     *       }
                     *   }
                     *
                     *   windows.Remove(hwndString);
                     *   windowRemoving.Destroy();
                     * }
                     */
                }
            }
        }