Esempio n. 1
0
        public static bool IsSquareWindowEdge(IntPtr Handle)
        {
            bool isMaximized = IsWindowMazimized(Handle);

            if (isMaximized)
            {
                return(true);
            }

            //Toolwindow = Gimp toolbox
            //Zune, Steam seem to have both Group and Tabstop
            int ExStyle = Windowing.GetWindowLong(Handle, Windowing.GWL_EXSTYLE);
            int Style   = Windowing.GetWindowLong(Handle, Windowing.GWL_STYLE);

            bool toolwin    = (ExStyle & Windowing.WS_EX_TOOLWINDOW) != 0;
            bool windowedge = (ExStyle & Windowing.WS_EX_WINDOWEDGE) != 0;
            bool popup      = (Style & Windowing.WS_POPUP) != 0;
            bool uix        = GetClassName(Handle) == "UIX Render Window";

            if (((toolwin || popup) && !windowedge) || uix)
            {
                return(true);
            }
            else
            {
                return(false);
            }

            //((Unmanaged.GetWindowLong(Handle, Unmanaged.GWL_STYLE) & Unmanaged.WS_GROUP) != 0 && (Unmanaged.GetWindowLong(Handle, Unmanaged.GWL_STYLE) & Unmanaged.WS_TABSTOP) != 0);
        }
Esempio n. 2
0
        public static DockStyle GetTaskbarEdge()
        {
            IntPtr taskBarWnd = Windowing.FindWindow("Shell_TrayWnd", null);

            Windowing.APPBARDATA abd = new Windowing.APPBARDATA();
            abd.hWnd = taskBarWnd;
            Windowing.SHAppBarMessage(Windowing.ABM_GETTASKBARPOS, ref abd);

            if (abd.rc.Top == abd.rc.Left && abd.rc.Bottom > abd.rc.Right)
            {
                return(DockStyle.Left);
            }
            else if (abd.rc.Top == abd.rc.Left && abd.rc.Bottom < abd.rc.Right)
            {
                return(DockStyle.Top);
            }
            else if (abd.rc.Top > abd.rc.Left)
            {
                return(DockStyle.Bottom);
            }
            else
            {
                return(DockStyle.Right);
            }
        }
Esempio n. 3
0
        public static bool isDialogWindow(IntPtr Handle)
        {
            return((Windowing.GetWindowLong(Handle, Windowing.GWL_EXSTYLE) & Windowing.WS_EX_DLGMODALFRAME) != 0);
            //||

            //    //Also check for dialog frame (but since that will also be true if mystery stype is true, check that that isn't there)
            //    ((Windowing.GetWindowLong(Handle, Windowing.GWL_STYLE) & Windowing.WS_DLGFRAME) != 0 &&
            //    !((Windowing.GetWindowLong(Handle, Windowing.GWL_STYLE) & 0xC000) != 0));
        }
Esempio n. 4
0
        public static Rectangle GetWindowRectangle(IntPtr Handle)
        {
            Windowing.RECT area = new Windowing.RECT();
            Windowing.GetWindowRect(Handle, out area);

            //if (isDialogWindow(Handle))
            //{
            //    area.Left -= 5;
            //    area.Right += 5;
            //    area.Top -= 5;
            //    area.Bottom += 5;
            //}

            return(new Rectangle(area.Left, area.Top, area.Width, area.Height));
        }
Esempio n. 5
0
        public static bool IsTargetProcessDPIAware(IntPtr h)
        {
            try
            {
                int pid;
                Windowing.GetWindowThreadProcessId(new HandleRef(null, h), out pid);
                string appCompatFlags = (string)Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers").GetValue(Process.GetProcessById(pid).MainModule.FileName, string.Empty);

                return(appCompatFlags.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Contains("HIGHDPIAWARE"));
            }
            catch (Exception e)
            {
                //literally do not care
                return(false);
            }
        }
Esempio n. 6
0
        public static bool IsWindowMazimized(IntPtr Handle)
        {
            Windowing.WINDOWPLACEMENT placement = new Windowing.WINDOWPLACEMENT();
            placement.length = Marshal.SizeOf(placement);
            Windowing.GetWindowPlacement(Handle, out placement);

            return(placement.showCmd == 3);

            //Rectangle WorkingAreaRect = Screen.FromHandle(Handle).WorkingArea;
            //Rectangle WindowRect = GetWindowRectangle(Handle);

            //return WindowRect.Equals(WorkingAreaRect);

            ////unreliable, for example, with Zune
            ////return (Unmanaged.GetWindowLong(Handle, Unmanaged.GWL_STYLE) & Unmanaged.WS_MAXIMIZE) != 0;
        }
Esempio n. 7
0
        public static string GetWindowText(IntPtr Handle, bool sanitized)
        {
            string WindowText = null;

            StringBuilder sb = new StringBuilder(255);

            if (Windowing.GetWindowText(Handle, sb, sb.Capacity) > 0)
            {
                WindowText = sb.ToString();

                if (sanitized)
                {
                    foreach (char c in Path.GetInvalidFileNameChars())
                    {
                        WindowText = WindowText.Replace(c, '-');
                    }
                }

                return(WindowText);
            }
            else
            {
                //Win32Exception Win32Ex = new Win32Exception(Marshal.GetLastWin32Error());
                //if (!(Win32Ex.NativeErrorCode == 0 || Win32Ex.NativeErrorCode == 1400))
                //    throw Win32Ex;
            }

            if (string.IsNullOrEmpty(WindowText))
            {
                int pid = 0;
                Windowing.GetWindowThreadProcessId(new HandleRef(null, Handle), out pid);
                try
                {
                    WindowText = Process.GetProcessById(pid).ProcessName;
                }
                catch
                {
                    //don't care
                    WindowText = "(screenshot)";
                }
            }

            return(WindowText);
        }
Esempio n. 8
0
        public static Rectangle SafeDPIShrink(this Rectangle original, IntPtr h)
        {
            bool isTargetDPIAware = IsTargetProcessDPIAware(h);
            bool isSelfDPIAware   = Windowing.IsProcessDPIAware();

            if (isSelfDPIAware && isTargetDPIAware)
            {
                return(original);
            }
            else
            {
                var ScaleFactor = GetDPIScaleFactor();
                var ScaledRect  = new Rectangle((int)(original.X / ScaleFactor), (int)(original.Y / ScaleFactor), (int)(original.Width / ScaleFactor), (int)(original.Height / ScaleFactor));

                Trace.WriteLine(string.Format("DPI adjusted '{0}' -> '{1}'", original, ScaledRect), string.Format("Helper.SafeDPIShrink [{0}]", System.Threading.Thread.CurrentThread.Name));

                return(ScaledRect);
            }
        }
Esempio n. 9
0
 public static bool isShiftKeyDown()
 {
     return(Convert.ToBoolean(Windowing.GetKeyState(Keys.LShiftKey) & Windowing.KEY_PRESSED) || Convert.ToBoolean(Windowing.GetKeyState(Keys.RShiftKey) & Windowing.KEY_PRESSED));
 }
Esempio n. 10
0
 public static void ShowBehind(Form frm, IntPtr targetWindow)
 {
     Windowing.ShowWindow(frm.Handle, Windowing.SW_SHOWNOACTIVATE);
     Windowing.SetWindowPos(frm.Handle.ToInt32(), Windowing.HWND_TOPMOST, frm.Left, frm.Top, frm.Width, frm.Height, 0);//Windowing.SWP_NOACTIVATE);
 }
Esempio n. 11
0
 public static bool HasNonClientBorder(IntPtr Handle)
 {
     return((Windowing.GetWindowLong(Handle, Windowing.GWL_STYLE) & Windowing.WS_BORDER) != 0);
 }
 protected static Screenshot FromBitmapRect(Bitmap MouseTargetScreenshot, Windowing.RECT MouseTargetWindowRect)
 {
     return new Screenshot()
     {
         BaseScreenshotImage = MouseTargetScreenshot,
         TargetRect = MouseTargetWindowRect,
         CaptureRect = MouseTargetWindowRect
     };
 }
Esempio n. 13
0
 public static extern int DwmGetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, out Windowing.RECT pvAttribute, uint cbAttribute);