Example #1
0
        public GradientRect(int left, int top, int width, int height, Colorref startColor, Colorref endColor, GradientRectDirection style)
        {
            fRect = new RECT(left, top, width, height);

            fVertices = new TRIVERTEX[2];
            fGradientRect = new GRADIENT_RECT[1];

            fGradientRect[0] = new GRADIENT_RECT();

            SetVertices(left, top, width, height);

            // Set Colors for left/top
            fVertices[0].Red = startColor.Red16;
            fVertices[0].Green = startColor.Green16;
            fVertices[0].Blue = startColor.Blue16;
            fVertices[0].Alpha = 0x0000;

            // Set Colors for right/bottom
            fVertices[1].Red = endColor.Red16;
            fVertices[1].Green = endColor.Green16;
            fVertices[1].Blue = endColor.Blue16;
            fVertices[1].Alpha = 0x0000;

            fGradientRect[0].UpperLeft = 0;
            fGradientRect[0].LowerRight = 1;

            fGradientDirection = style;
        }
Example #2
0
 /// <summary>
 /// 根据窗口标题获取窗口的大小和位置(当多个标题相同的窗体存在时,默认获取上一个活动的窗体)
 /// </summary>
 /// <param name="WindowTitle">窗口标题(字符串不能有任何差别)</param>
 /// <returns>窗口的大小和位置(System.Drawing.Rectangle)</returns>
 public static System.Drawing.Rectangle FindWindow(string WindowTitle)
 {
     RECT rect = new RECT();
     string lpClassName = null;
     GetWindowRect(FindWindow(lpClassName, WindowTitle), ref rect);
     return new System.Drawing.Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);
 }
Example #3
0
        public static RECT GetWindowRectangle(IntPtr windowHandle)
        {
            RECT ret = new RECT();
            GetWindowRect(windowHandle, out ret);

            return ret;
        }
Example #4
0
        public static Bitmap Capture(RECT rect)
        {
            int width = rect.Right - rect.Left;
            int height = rect.Bottom - rect.Top;
            try
            {
                var bitmap = new Bitmap(width, height);
                Graphics g = Graphics.FromImage(bitmap);
                g.CopyFromScreen(new Point(rect.Left, rect.Top), new Point(0, 0),
                    new Size(width, height));

                IntPtr dc = g.GetHdc();
                g.ReleaseHdc(dc);

                //            bitmap.Save(Path + "\\" + GenerateFileName() + ".png", ImageFormat.Png);
                //Console.WriteLine("Captured");

                //g.Clear(Color.Transparent);
                return bitmap;
            }
            catch (Exception)
            {
                return null;
            }
        }
Example #5
0
        public static void RemoveBorder(IntPtr hwnd)
        {
            const int SWP_FRAMECHANGED = 0x0020;
            const int GWL_STYLE = -16;
            const int GWL_EXSTYLE = -20;
            const int WS_SYSMENU = 524288;
            const int WS_THICKFRAME = 262144;
            const int WS_MINIMIZE = 536870912;
            const int WS_MAXIMIZE = 16777216;
            const int WS_BORDER = 8388608;
            const int WS_DLGFRAME = 4194304;
            const int WS_CAPTION = WS_BORDER | WS_DLGFRAME;
            const int WS_EX_DLGMODALFRAME = 1;
            const int WS_EX_CLIENTEDGE = 512;
            const int WS_EX_STATICEDGE = 131072;

            var style = GetWindowLong(hwnd, GWL_STYLE) & ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
            SetWindowLong(hwnd, GWL_STYLE, style);

            var exst = GetWindowLong(hwnd, GWL_EXSTYLE) & ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
            SetWindowLong(hwnd, GWL_EXSTYLE, exst);

            var rect = new RECT();
            var ok = GetWindowRect(hwnd, out rect)
                  && SetWindowPos(hwnd, 0, rect.X, rect.Y, rect.Width, rect.Height, SWP_FRAMECHANGED);
            if (!ok)
                throw new Exception("Error, can't remove border apparently.");
        }
        private void SyncWindowSize(bool log)
        {
            try
            {
                RECT rect = new RECT();
                NativeWindowMethods.GetWindowRect(_windowHandle, ref rect);

                var width = rect.Right - rect.Left;
                var height = rect.Bottom - rect.Top;

                if (log)
                {
                    _logger.Info("SyncWindowSize Top={0} Left={1} Width={2} Height={3}", rect.Top, rect.Left, width, height);
                }

                _form.InvokeIfRequired(() =>
                {
                    if (_form.WindowState == FormWindowState.Normal)
                    {
                        _form.Top = rect.Top;
                        _form.Left = rect.Left;
                        _form.Width = rect.Right - rect.Left;
                        _form.Height = rect.Bottom - rect.Top;
                    }
                });
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error syncing window positions", ex);
            }
        }
Example #7
0
 public Rectangle GetBandRect(int bandIndex)
 {
     RECT rect = new RECT();
     //int index = GetBandActualIndex(bandIndex);
     WindowsAPI.SendMessage(Handle, (int)RebarMessages.RB_GETRECT, bandIndex, ref rect);
     return new Rectangle(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
 }
 public static void MoveWindow(int left, int top)
 {
     var handle = GetConsoleWindow();
     RECT rect = new RECT();
     GetWindowRect(handle, ref rect);
     MoveWindow(handle, left, top, rect.right - rect.left, rect.bottom - rect.top, true);
 }
Example #9
0
		private Dictionary<string, int> GetWindowSize(string processName)
		{
			IntPtr handle = IntPtr.Zero;
			foreach (Process process in Process.GetProcesses())
			{


				if (process.MainWindowTitle.IndexOf(processName) >= 0)
				{
					handle = process.MainWindowHandle;
				}
			}
			if (handle == IntPtr.Zero)
				throw new WindowNotFoundException();

			RECT rect = new RECT(); POINT point = new POINT();
			GetClientRect(handle, out rect);
			ClientToScreen(handle, out point);
			var result = new Dictionary<string, int>();
			result.Add("width", (int)(rect.right - rect.left));
			result.Add("height", (int)(rect.bottom - rect.top));
			result.Add("x", (int)point.x);
			result.Add("y", (int)point.y);
			return result;
		}
Example #10
0
        public static void GetImage(object obj, Image destination, Color backgroundColor)
        {
            using (Graphics graphics = Graphics.FromImage(destination))
            {
                IntPtr deviceContextHandle = IntPtr.Zero;
                RECT rectangle = new RECT();

                rectangle.Right = destination.Width;
                rectangle.Bottom = destination.Height;

                graphics.Clear(backgroundColor);

                try
                {
                    deviceContextHandle = graphics.GetHdc();

                    IViewObject viewObject = obj as IViewObject;
                    viewObject.Draw(1, -1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, deviceContextHandle, ref rectangle, IntPtr.Zero, IntPtr.Zero, 0);
                }
                finally
                {
                    if (deviceContextHandle != IntPtr.Zero)
                    {
                        graphics.ReleaseHdc(deviceContextHandle);
                    }
                }
            }
        }
Example #11
0
 public InstructorSpace(RECT aFrame)
     : base("Auditorium", aFrame)
 {
     // And one larger one
     fScetchSurface = new SketchWindow(200, 0, 600, 600);
     fScetchSurface.Show();
 }
        public int DrawGlyphWithColors(IntPtr hdc, RECT[] pRect, int iMarkerType,
            IVsTextMarkerColorSet pMarkerColors, uint dwGlyphDrawFlags, int iLineHeight)
        {
            RECT rect = pRect[0];
            int rectWidth = rect.right - rect.left;
            int lineWidth = 8;// 2 + rectWidth / 20;

            uint clrFore;
            uint clrBack;
            ErrorHandler.ThrowOnFailure(pMarkerColors.GetMarkerColors(JiraLinkMarginMarkerType.Id, out clrFore, out clrBack));

            int drawColorref = (int)clrFore;
            Color color = Color.FromArgb(
                drawColorref & 0x0000FF,
                (drawColorref & 0x00FF00) >> 8,
                (drawColorref & 0xFF0000) >> 16
                );

            using (Graphics graphics = Graphics.FromHdc(hdc))
            using (SolidBrush brush = new SolidBrush(color))
            {
                graphics.FillRectangle(brush, rect.left + (rectWidth - lineWidth) / 2, rect.top, lineWidth, rect.bottom - rect.top);
            }

            return VSConstants.S_OK;
        }
Example #13
0
    public static void Main(System.String[] argv)
    {
        RPlus root;
        RECT rec, s_rec;
        MBR[] obj = new MBR[6];
        int i;

        // Case 6: Randomly generate 5 objects.
        int fillfactor = 3;
        root = new RPlus(fillfactor);
        rec = new RECT(16, 51, 39, 59);
        obj[1] = new MBR(rec, 1);
        rec = new RECT(53, 12, 65, 24);
        obj[2] = new MBR(rec, 2);
        rec = new RECT(4, 46, 11, 64);
        obj[3] = new MBR(rec, 3);
        rec = new RECT(15, 6, 61, 75);
        obj[4] = new MBR(rec, 4);
        rec = new RECT(51, 2, 70, 79);
        obj[5] = new MBR(rec, 5);
        root.insert(obj[1]);
        root.insert(obj[2]);
        root.insert(obj[3]);
        root.insert(obj[4]);
        root.insert(obj[5]);
        //                root.pack();
        root.print();
    }
Example #14
0
        public static Rectangle GetWindowRect(IntPtr hWnd)
        {
            RECT rect = new RECT();
            GetWindowRect(hWnd, ref rect);

            return new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);
        }
Example #15
0
        private static void TmrCursor_Tick(object sender, EventArgs e)
        {
            try {
                Process[] processes = Process.GetProcesses();

                foreach (var p in processes)
                {
                    if (p.ProcessName == "devenv" || p.ProcessName == "notepad") {
                        Point pos = Cursor.Position;
                        IntPtr handle = p.MainWindowHandle;
                        var rectangle = new RECT();

                        if (!GetWindowRect(handle, ref rectangle)) continue;
                        var rnd = new Random();
                        Cursor.Position = new Point(rnd.Next(0, rectangle.Width), rnd.Next(0, rectangle.Height));

                        mouse_event(MouseeventfLeftdown | MouseeventfLeftup, Cursor.Position.X, Cursor.Position.Y, 0, 0);
                        Cursor.Position = pos;
                    }
                }
            }
            catch {
                // ignored
            }
        }
 /// <summary> Win32 </summary>
 public RECT(RECT rcSrc)
 {
     left = rcSrc.left;
     top = rcSrc.top;
     right = rcSrc.right;
     bottom = rcSrc.bottom;
 }
Example #17
0
        public static Image CaptureWindow(IntPtr handle)
        {

            IntPtr hdcSrc = User32.GetWindowDC(handle);

            RECT windowRect = new RECT();
            User32.GetWindowRect(handle, ref windowRect);

            int width = windowRect.right - windowRect.left;
            int height = windowRect.bottom - windowRect.top;

            IntPtr hdcDest = Gdi32.CreateCompatibleDC(hdcSrc);
            IntPtr hBitmap = Gdi32.CreateCompatibleBitmap(hdcSrc, width, height);

            IntPtr hOld = Gdi32.SelectObject(hdcDest, hBitmap);
            Gdi32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, SRCCOPY);
            Gdi32.SelectObject(hdcDest, hOld);
            Gdi32.DeleteDC(hdcDest);
            User32.ReleaseDC(handle, hdcSrc);

            Image image = Image.FromHbitmap(hBitmap);
            Gdi32.DeleteObject(hBitmap);

            return image;
        }
Example #18
0
 public Split_info()
 {
     mbr = null;
     newnode = null;
     xcut = - 1;
     ycut = - 1;
 }
Example #19
0
 public Pencil(uint colorref)
 {
     fColor = colorref;
     //fPen = new Pen(Guid.NewGuid(), colorref, PenStyle.Solid, PenType.Cosmetic, PenJoinStyle.Round, PenEndCap.Round, 1);
     fPen = new CosmeticPen(PenStyle.Solid, fColor, Guid.NewGuid());
     fDrawingBounds = RECT.Empty;
 }
Example #20
0
        public static Bitmap PrintWindow(IntPtr hwnd)
        {
            RECT rc = new RECT();
            User32.GetWindowRect(hwnd, ref rc);

            Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
            Graphics gfxBmp = Graphics.FromImage(bmp);
            IntPtr hdcBitmap = gfxBmp.GetHdc();
            bool succeeded = User32.PrintWindow(hwnd, hdcBitmap, 0);
            gfxBmp.ReleaseHdc(hdcBitmap);
            if (!succeeded)
            {
                gfxBmp.FillRectangle(new SolidBrush(Color.Gray), new Rectangle(Point.Empty, bmp.Size));
            }
            IntPtr hRgn = Gdi32.CreateRectRgn(0, 0, 0, 0);
            User32.GetWindowRgn(hwnd, hRgn);
            Region region = Region.FromHrgn(hRgn);
            if (!region.IsEmpty(gfxBmp))
            {
                gfxBmp.ExcludeClip(region);
                gfxBmp.Clear(Color.Transparent);
            }
            gfxBmp.Dispose();
            return bmp;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="hWnd">被覆盖控件句柄。</param>
        internal void CheckBounds(IntPtr hWnd)
        {
            RECT controlRect = new RECT();
            RECT maskRect = new RECT();

            NativeMethods.GetWindowRect(base.Handle, ref maskRect);
            NativeMethods.GetWindowRect(hWnd, ref controlRect);

            uint uFlag =
                SWP.SWP_NOACTIVATE |
                SWP.SWP_NOOWNERZORDER |
                SWP.SWP_NOZORDER;

            if (!NativeMethods.EqualRect(ref controlRect, ref maskRect))
            {
                Point point = new Point(controlRect.Left, controlRect.Top);
                IntPtr hParent = NativeMethods.GetParent(base.Handle);
                NativeMethods.ScreenToClient(hParent, ref point);

                NativeMethods.SetWindowPos(
                    base.Handle,
                    IntPtr.Zero,
                    point.X,
                    point.Y,
                    controlRect.Right - controlRect.Left,
                    controlRect.Bottom - controlRect.Top,
                    uFlag);
            }
        }
Example #22
0
        /// <summary>
        /// Снятие скриншота окна
        /// </summary>
        /// <returns>Скрин или null в случае неудачи</returns>
        public Bitmap CaptureScreen()
        {
            if (Handle == IntPtr.Zero) return null;
            RECT windowRect = new RECT();
            GetWindowRect(Handle, ref windowRect);
            var Left = windowRect.left + config.xOffset;
            var Top = windowRect.top + config.yOffset;

            int h = windowRect.right - Left;
            int w = windowRect.bottom - Top;

            if (h > config.maxHeight) h = config.maxHeight;
            if (w > config.maxWidth) w = config.maxWidth;

            Bitmap BMP = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            System.Drawing.Graphics GFX = System.Drawing.Graphics.FromImage(BMP);
            IntPtr del = GFX.GetHdc();
            IntPtr dc2 = GetWindowDC(Handle);
             //CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt
            BitBlt(del, 0, 0, BMP.Width, BMP.Height, dc2, config.xOffset, config.yOffset, (int)(CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt));
            GFX.ReleaseHdc(del);
            ReleaseDC(Handle, dc2);

            return BMP;
        }
Example #23
0
        public GradientRect(int left, int top, int width, int height, uint startColor, uint endColor, GradientRectDirection style)
        {
            fRect = new RECT(left, top, width, height);

            fVertices = new TRIVERTEX[2];
            fGradientRect = new GRADIENT_RECT[1];

            fGradientRect[0] = new GRADIENT_RECT();

            SetVertices(left, top, width, height);

            // Set Colors for left/top
            fVertices[0].Red = (ushort)(RGBColor.R(startColor) << 8);
            fVertices[0].Green = (ushort)(RGBColor.G(startColor) << 8);
            fVertices[0].Blue = (ushort)(RGBColor.B(startColor) << 8);
            fVertices[0].Alpha = 0x0000;

            // Set Colors for right/bottom
            fVertices[1].Red = (ushort)(RGBColor.R(endColor) << 8);
            fVertices[1].Green = (ushort)(RGBColor.G(endColor) << 8);
            fVertices[1].Blue = (ushort)(RGBColor.B(endColor) << 8);
            fVertices[1].Alpha = 0x0000;

            fGradientRect[0].UpperLeft = 0;
            fGradientRect[0].LowerRight = 1;

            fGradientDirection = style;
        }
Example #24
0
 protected UIWindow(string title, RECT frame)
 {
     fTitle = title;
     fFrame = frame;
     fBounds = new RECT(0, 0, frame.Width, frame.Height);
     fSurfaceID = MetaSpace.CreateSurface(title, frame, new OnSurfaceCreatedEventHandler(OnSurfaceCreated));
 }
Example #25
0
        public static UISurface CreateSurface(string title, RECT frame, Guid uniqueID)
        {
            UISurface newSurface = new UISurface(title, frame, uniqueID);
            newSurface.ClearToColor(RGBColor.LtGray);

            return newSurface;
        }
        public virtual void OnCreateSurface(string title, RECT frame, Guid uniqueID)
        {
            if (null != OnCreateSurfaceEvent)
                OnCreateSurfaceEvent(title, frame, uniqueID);

            OnSurfaceCreated(uniqueID);
        }
Example #27
0
 // Check if this MBR overlaps with R.
 internal virtual int check_overlap(RECT R)
 {
     if ((R.high[0] <= this.mbr.low[0]) || (R.low[0] >= this.mbr.high[0]) || (R.high[1] <= this.mbr.low[1]) || (R.low[1] >= this.mbr.high[1]))
     {
         return 0;
     }
     return 1;
 }
Example #28
0
 public MBR(RECT w)
 {
     this.mbr = w;
     cutxl = - 1;
     cutyl = - 1;
     cutxh = - 1;
     cutyh = - 1;
 }
 /// <summary>
 ///  Initialize the standard font rectangle.
 /// </summary>
 static TerrariumTextSurfaceManager()
 {
     StandardFontRect = new RECT();
     StandardFontRect.Top = 0;
     StandardFontRect.Left = 0;
     StandardFontRect.Bottom = 15;
     StandardFontRect.Right = 100;
 }
Example #30
0
        public static RECT getRect(IntPtr awin)
        {
            RECT rc = new RECT();

            GetWindowRect(awin, ref rc);

            return rc;
        }
Example #31
0
 static extern IntPtr MonitorFromRect(ref RECT lprc, MonitorOptions dwFlags);
Example #32
0
 public static extern bool ClipCursor(ref RECT rcClip);
Example #33
0
 static extern bool GetWindowRect(int hWnd, ref RECT lpRect);
 public static extern int GetClientRect(IntPtr hwnd, ref RECT lpRect);
Example #35
0
 public static extern int FillRect(IntPtr hDC, [In] ref RECT lprc, IntPtr hbr);
Example #36
0
 internal static extern void AdjustWindowRectEx(ref RECT rect, int dwStyle, bool hasMenu, int dwExSytle);
Example #37
0
 static extern bool GetWindowRect(HandleRef hWnd, out RECT lpRect);
Example #38
0
            public static RECT FromIntPtr(IntPtr ptr)
            {
                RECT rect = (RECT)Marshal.PtrToStructure(ptr, typeof(RECT));

                return(rect);
            }
Example #39
0
 public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect);
Example #40
0
 private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
    private static void SetFormattingRect(this TextBoxBase textbox, Rectangle rect)
    {
        var rc = new RECT(rect);

        SendMessageRefRect(textbox.Handle, EmSetrect, 0, ref rc);
    }
Example #42
0
 public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, [In, Out] ref RECT rect, [MarshalAs(UnmanagedType.U4)] int cPoints);
        public static int MapInputRectsToOutputRect(PixelShaderEffect * @this, RECT *inputRects, RECT *inputOpaqueSubRects, uint inputRectCount, RECT *outputRect, RECT *outputOpaqueSubRect)
        {
            @this = (PixelShaderEffect *)&((void **)@this)[-1];

            if (inputRectCount != @this->inputCount)
            {
                return(E.E_INVALIDARG);
            }

            if (@this->d2D1TransformMapperHandle.Target is D2D1TransformMapper d2D1TransformMapper)
            {
                Span <Rectangle> inputs       = stackalloc Rectangle[8].Slice(0, (int)inputRectCount);
                Span <Rectangle> opaqueInputs = stackalloc Rectangle[8].Slice(0, (int)inputRectCount);

                for (int i = 0; i < (int)inputRectCount; i++)
                {
                    inputs[i]       = inputRects[i].ToRectangle();
                    opaqueInputs[i] = inputOpaqueSubRects[i].ToRectangle();
                }

                ReadOnlySpan <byte> buffer = new(@this->constantBuffer, @this->constantBufferSize);

                Rectangle output;
                Rectangle opaqueOutput;

                // Handle exceptions, as mentioned above
                try
                {
                    d2D1TransformMapper.MapInputsToOutput(buffer, inputs, opaqueInputs, out output, out opaqueOutput);
                }
                catch (Exception e)
                {
                    return(e.HResult);
                }

                *outputRect          = output.ToRECT();
                *outputOpaqueSubRect = opaqueOutput.ToRECT();
            }
            else if (inputRectCount == 0)
            {
                // If there are no inputs, make the output rectangle infinite. This is useful
                // to make output-only effects work fine by default, without needing a custom
                // transform. In this case, the target area will be the output node anyway.
                outputRect->MakeD2D1Infinite();

                *outputOpaqueSubRect = default;
            }
            else
            {
                // If at least one input is present and no custom mapper is available, apply the default
                // mapping. In this case, the output rect should be the union of the input rects for all
                // the simple shader inputs, or infinite if there are no simple inputs. The input rects
                // for complex inputs, if present, are not needed in this scenario, so they're ignored.
                RECT unionOfSimpleRects        = default;
                bool isUnionOfSimpleRectsEmpty = true;

                for (uint i = 0; i < inputRectCount; i++)
                {
                    if (@this->inputTypes[i] == D2D1PixelShaderInputType.Simple)
                    {
                        if (isUnionOfSimpleRectsEmpty)
                        {
                            unionOfSimpleRects        = inputRects[i];
                            isUnionOfSimpleRectsEmpty = false;
                        }
                        else
                        {
                            unionOfSimpleRects = unionOfSimpleRects.Union(inputRects[i]);
                        }
                    }
                }

                if (isUnionOfSimpleRectsEmpty)
                {
                    outputRect->MakeD2D1Infinite();
                }
                else
                {
                    *outputRect = unionOfSimpleRects;
                }

                *outputOpaqueSubRect = default;
            }

            return(S.S_OK);
        }
Example #44
0
 public static extern bool ClipCursor(ref RECT lpRect);
Example #45
0
 public static extern bool InflateRect(ref RECT lprc, int dx, int dy);
 public static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out RECT pvAttribute, int cbAttribute);
Example #47
0
 public static extern bool InvalidateRect(IntPtr hWnd, ref RECT rect, bool erase);
 public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
Example #49
0
 public static extern bool DrawFocusRect(IntPtr hWnd, ref RECT rect);
Example #50
0
        public int Print(int charFrom, int charTo, PrintPageEventArgs e)
        {
            CHARRANGE cHARRANGE = new CHARRANGE();

            FORMATRANGE fORMATRANGE = new FORMATRANGE();

            RECT rECT = new RECT(), rECT1 = new RECT();

            cHARRANGE.cpMin = charFrom;

            cHARRANGE.cpMax = charTo;

            Rectangle marginBounds = e.MarginBounds;

            rECT1.Top = checked ((int)Math.Round((double)marginBounds.Top * 14.4));

            marginBounds = e.MarginBounds;

            rECT1.Bottom = checked ((int)Math.Round((double)marginBounds.Bottom * 14.4));

            marginBounds = e.MarginBounds;

            rECT1.Left = checked ((int)Math.Round((double)marginBounds.Left * 14.4));

            marginBounds = e.MarginBounds;

            rECT1.Right = checked ((int)Math.Round((double)marginBounds.Right * 14.4));

            marginBounds = e.PageBounds;

            rECT.Top = checked ((int)Math.Round((double)marginBounds.Top * 14.4));

            marginBounds = e.PageBounds;

            rECT.Bottom = checked ((int)Math.Round((double)marginBounds.Bottom * 14.4));

            marginBounds = e.PageBounds;

            rECT.Left = checked ((int)Math.Round((double)marginBounds.Left * 14.4));

            marginBounds = e.PageBounds;

            rECT.Right = checked ((int)Math.Round((double)marginBounds.Right * 14.4));

            IntPtr hdc             = e.Graphics.GetHdc();

            fORMATRANGE.chrg = cHARRANGE;

            fORMATRANGE.hdc = hdc;

            fORMATRANGE.hdcTarget = hdc;

            fORMATRANGE.rc = rECT1;

            fORMATRANGE.rcPage = rECT;

            IntPtr zero = IntPtr.Zero, intPtr = IntPtr.Zero;

            intPtr = new IntPtr(1);

            IntPtr zero1 = IntPtr.Zero;

            zero1 = Marshal.AllocCoTaskMem(Marshal.SizeOf <FORMATRANGE>(fORMATRANGE));

            Marshal.StructureToPtr <FORMATRANGE>(fORMATRANGE, zero1, false);

            zero = SendMessage(Handle, 1081, intPtr, zero1);

            Marshal.FreeCoTaskMem(zero1);

            e.Graphics.ReleaseHdc(hdc);

            return(zero.ToInt32());
        }
Example #51
0
 public static extern IntPtr MonitorFromRect(ref RECT rect, int flags);
 public static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
Example #53
0
 public static extern bool GetClipCursor(out RECT rcClip);
 public static extern bool PtInRect([In] ref RECT lprc, Point pt);
 public extern static int OffsetRect(ref RECT lpRect, int x, int y);
 public static extern IntPtr SendMessage(
     IntPtr hWnd, int Msg, int wParam, ref RECT lParam);
Example #57
0
        public void WndActivate(object sender, CbtEventArgs e)
        {
            IntPtr hMsgBox = e.wParam;

            // try to find a howner for this message box
            if (hOwner == IntPtr.Zero)
            {
                hOwner = USER32.GetActiveWindow();
            }

            // get the MessageBox window rect
            RECT rectDlg = new RECT();

            USER32.GetWindowRect(hMsgBox, ref rectDlg);

            // get the owner window rect
            RECT rectForm = new RECT();

            USER32.GetWindowRect(hOwner, ref rectForm);

            // get the biggest screen area
            Rectangle rectScreen = API.TrueScreenRect;

            // if no parent window, center on the primary screen
            if (rectForm.right == rectForm.left)
            {
                rectForm.right = rectForm.left = Screen.PrimaryScreen.WorkingArea.Width / 2;
            }
            if (rectForm.bottom == rectForm.top)
            {
                rectForm.bottom = rectForm.top = Screen.PrimaryScreen.WorkingArea.Height / 2;
            }

            // center on parent
            int dx = ((rectDlg.left + rectDlg.right) - (rectForm.left + rectForm.right)) / 2;
            int dy = ((rectDlg.top + rectDlg.bottom) - (rectForm.top + rectForm.bottom)) / 2;

            rect = new Rectangle(
                rectDlg.left - dx,
                rectDlg.top - dy,
                rectDlg.right - rectDlg.left,
                rectDlg.bottom - rectDlg.top);

            // place in the screen
            if (rect.Right > rectScreen.Right)
            {
                rect.Offset(rectScreen.Right - rect.Right, 0);
            }
            if (rect.Bottom > rectScreen.Bottom)
            {
                rect.Offset(0, rectScreen.Bottom - rect.Bottom);
            }
            if (rect.Left < rectScreen.Left)
            {
                rect.Offset(rectScreen.Left - rect.Left, 0);
            }
            if (rect.Top < rectScreen.Top)
            {
                rect.Offset(0, rectScreen.Top - rect.Top);
            }

            if (e.IsDialog)
            {
                // do the job when the WM_INITDIALOG message returns
                wndProcRetHook             = new WndProcRetHook(hMsgBox);
                wndProcRetHook.WndProcRet += new WndProcRetHook.WndProcEventHandler(WndProcRet);
                wndProcRetHook.Install();
            }
            else
            {
                USER32.MoveWindow(hMsgBox, rect.Left, rect.Top, rect.Width, rect.Height, 1);
            }

            // uninstall this hook
            WindowsHook wndHook = (WindowsHook)sender;

            Debug.Assert(cbtHook == wndHook);
            cbtHook.Uninstall();
            cbtHook = null;
        }
Example #58
0
 public static extern bool GetClientRect(IntPtr hWnd, ref RECT lpRect);
 public bool Equals(RECT r)
 {
     return(r.Left == Left && r.Top == Top && r.Right == Right && r.Bottom == Bottom);
 }
 private static extern int SendMessageRefRect(IntPtr hWnd, uint msg, int wParam, ref RECT rect);