当前位置: 首页>>代码示例>>C#>>正文


C# NativeMethods.RECT类代码示例

本文整理汇总了C#中NativeMethods.RECT的典型用法代码示例。如果您正苦于以下问题:C# NativeMethods.RECT类的具体用法?C# NativeMethods.RECT怎么用?C# NativeMethods.RECT使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NativeMethods.RECT类属于命名空间,在下文中一共展示了NativeMethods.RECT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetNonClientSize

        public static Padding GetNonClientSize(Control control)
        {
            var memory = IntPtr.Zero;

            try
            {
                var rect = new NativeMethods.RECT
                {
                    left = 0,
                    top = 0,
                    right = control.Width,
                    bottom = control.Height
                };

                memory = Marshal.AllocHGlobal(Marshal.SizeOf(rect));

                Marshal.StructureToPtr(rect, memory, false);

                NativeMethods.SendMessage(control.Handle, NativeMethods.WM_NCCALCSIZE, IntPtr.Zero, memory);

                rect = (NativeMethods.RECT)Marshal.PtrToStructure(memory, typeof(NativeMethods.RECT));

                return new Padding(
                    rect.left,
                    rect.top,
                    control.Width - rect.right,
                    control.Height - rect.bottom
                );
            }
            finally
            {
                if (memory != IntPtr.Zero)
                    Marshal.FreeHGlobal(memory);
            }
        }
开发者ID:pvginkel,项目名称:SystemEx,代码行数:35,代码来源:ControlUtil.cs

示例2: CaptureWindow

        /// <summary>
        /// Captures a screenshot of the window associated with the handle argument.
        /// </summary>
        /// <param name="handle">Used to determine which window to provide a screenshot for.</param>
        /// <returns>Screenshot of the window corresponding to the handle argument.</returns>
        public static Image CaptureWindow(IntPtr handle)
        {
            IntPtr sourceContext = NativeMethods.GetWindowDC(handle);
            IntPtr destinationContext = NativeMethods.CreateCompatibleDC(sourceContext);

            NativeMethods.RECT windowRect = new NativeMethods.RECT();
            NativeMethods.GetWindowRect(handle, ref windowRect);
            int width = windowRect.right - windowRect.left;
            int height = windowRect.bottom - windowRect.top;

            IntPtr bitmap = NativeMethods.CreateCompatibleBitmap(sourceContext, width, height);
            IntPtr replaceContext = NativeMethods.SelectObject(destinationContext, bitmap);
            NativeMethods.BitBlt(destinationContext, 0, 0, width, height, sourceContext, 0, 0, NativeMethods.SRCCOPY);

            NativeMethods.SelectObject(destinationContext, replaceContext);

            NativeMethods.DeleteDC(destinationContext);
            NativeMethods.ReleaseDC(handle, sourceContext);

            Image img = Image.FromHbitmap(bitmap);

            NativeMethods.DeleteObject(bitmap);

            return img;
        }
开发者ID:BookSwapSteve,项目名称:Exceptionless,代码行数:30,代码来源:ImageHelper.cs

示例3: DrawText

        public void DrawText(string text, Point point, Font font, Color foreColor)
        {
            IntPtr fontHandle = font.ToHfont();
            IntPtr oldFontHandle = NativeMethods.SelectObject(this.graphicsHandle, fontHandle);

            int oldBkMode = NativeMethods.SetBkMode(this.graphicsHandle, NativeMethods.TRANSPARENT);
            int oldTextColor = NativeMethods.SetTextColor(this.graphicsHandle, Color.FromArgb(0, foreColor.R, foreColor.G, foreColor.B).ToArgb());

            Size size = this.MeassureTextInternal(text);

            NativeMethods.RECT clip = new NativeMethods.RECT();
            clip.left = point.X;
            clip.top = point.Y;
            clip.right = clip.left + size.Width;
            clip.bottom = clip.top + size.Height;

            // ExtTextOut does not show Mnemonics highlighting.
            NativeMethods.DrawText(this.graphicsHandle, text, text.Length, ref clip, NativeMethods.DT_SINGLELINE | NativeMethods.DT_LEFT);

            NativeMethods.SetTextColor(this.graphicsHandle, oldTextColor);
            NativeMethods.SetBkMode(this.graphicsHandle, oldBkMode);

            NativeMethods.SelectObject(this.graphicsHandle, oldFontHandle);
            NativeMethods.DeleteObject(fontHandle);
        }
开发者ID:NickCorn,项目名称:Writer,代码行数:25,代码来源:TextGraphics.cs

示例4: GetBestSize

        /// <summary>
        /// Measure a multiline string
        /// </summary>
        /// <param name="gr">Graphics</param>
        /// <param name="text">string to measure</param>
        /// <param name="rect">Original rect. The width will be taken as fixed.</param>
        /// <param name="textboxControl">True if you want to measure the string for a textbox control</param>
        /// <returns>A Size object with the measure of the string according with the params</returns>
        public static Size GetBestSize(Graphics gr, string text, Rectangle rect, bool textboxControl)
        {
            NativeMethods.RECT bounds = new NativeMethods.RECT(rect);
            IntPtr hdc = gr.GetHdc();
            int flags = NativeMethods.DT_CALCRECT | NativeMethods.DT_WORDBREAK;
            if (textboxControl) flags |= NativeMethods.DT_EDITCONTROL;
            NativeMethods.DrawText(hdc, text, text.Length, ref bounds, flags);
            gr.ReleaseHdc(hdc);

            return new Size(bounds.right - bounds.left, bounds.bottom - bounds.top + (textboxControl ? 6 : 0));
        }
开发者ID:netide,项目名称:netide,代码行数:19,代码来源:AdjustControls.cs

示例5: ShouldShowPopup

        public static bool ShouldShowPopup(System.Windows.Forms.Form popupForm, Screen popupScreen)
        {
            // Is the current session locked?

            if (_sessionLocked)
                return false;

            // Has the last mouse movement or keyboard action been too long ago?

            var lii = new NativeMethods.LASTINPUTINFO();

            lii.cbSize = (uint)Marshal.SizeOf(lii);

            bool fResult = NativeMethods.GetLastInputInfo(ref lii);

            if (!fResult)
                throw new Exception("GetLastInputInfo failed");

            if (NativeMethods.GetTickCount() - lii.dwTime > IdleTime)
            {
                return false;
            }

            // Only consider the foreground window when it is on the same monitor
            // as the popup is going to be displayed on.

            var hForeground = NativeMethods.GetForegroundWindow();

            var screen = Screen.FromHandle(hForeground);

            if (screen.WorkingArea != popupScreen.WorkingArea)
            {
                return true;
            }

            // Is the foreground application running in full-screen mode?

            NativeMethods.RECT rcForeground = new NativeMethods.RECT();

            NativeMethods.GetClientRect(hForeground, ref rcForeground);

            var foreground = ClientToScreen(hForeground, rcForeground);

            // If the client rect is covering the entire screen, the application is a
            // full-screen application.

            return !(
                screen.Bounds.Left >= foreground.Left &&
                screen.Bounds.Top >= foreground.Top &&
                screen.Bounds.Right <= foreground.Right &&
                screen.Bounds.Bottom <= foreground.Bottom
            );
        }
开发者ID:pvginkel,项目名称:SystemEx,代码行数:53,代码来源:PopupUtil.cs

示例6: GetBorderThickness

        public Padding GetBorderThickness()
        {
            var rect = new NativeMethods.RECT(Rectangle.Empty);

            NativeMethods.AdjustWindowRectEx(
                ref rect,
                (uint)NativeMethods.GetWindowLong(Handle, NativeMethods.GWL_STYLE),
                false,
                (uint)NativeMethods.GetWindowLong(Handle, NativeMethods.GWL_EXSTYLE)
            );

            return new Padding(
                rect.right,
                rect.bottom,
                rect.right,
                rect.bottom
            );
        }
开发者ID:pvginkel,项目名称:CustomChrome,代码行数:18,代码来源:ChromeManager.cs

示例7: GetItemRect

 /// <summary>
 /// Return the bounds of the item with the given index
 /// </summary>
 /// <param name="itemIndex"></param>
 /// <returns></returns>
 public Rectangle GetItemRect(int itemIndex) {
     const int HDM_FIRST = 0x1200;
     const int HDM_GETITEMRECT = HDM_FIRST + 7;
     NativeMethods.RECT r = new NativeMethods.RECT();
     NativeMethods.SendMessageRECT(this.Handle, HDM_GETITEMRECT, itemIndex, ref r);
     return Rectangle.FromLTRB(r.left, r.top, r.right, r.bottom);
 }
开发者ID:leesanghyun2,项目名称:mp-onlinevideos2,代码行数:12,代码来源:HeaderControl.cs

示例8: AddItems

        private void AddItems()
        {
            NativeMethods.SendMessage(Handle, NativeMethods.TB_BUTTONSTRUCTSIZE, Marshal.SizeOf(typeof(NativeMethods.TBBUTTON)), 0);

            int extendedStyle = NativeMethods.TBSTYLE_EX_HIDECLIPPEDBUTTONS | NativeMethods.TBSTYLE_EX_DOUBLEBUFFER;
            if (style == CommandBarStyle.ToolBar)
            {
                extendedStyle |= NativeMethods.TBSTYLE_EX_DRAWDDARROWS;
            }

            NativeMethods.SendMessage(Handle, NativeMethods.TB_SETEXTENDEDSTYLE, 0, extendedStyle);

            this.UpdateImageList();

            for (int i = 0; i < items.Count; i++)
            {
                NativeMethods.TBBUTTON button = new NativeMethods.TBBUTTON();
                button.idCommand = i;
                NativeMethods.SendMessage(this.Handle, NativeMethods.TB_INSERTBUTTON, i, ref button);

                NativeMethods.TBBUTTONINFO buttonInfo = this.GetButtonInfo(i);
                NativeMethods.SendMessage(this.Handle, NativeMethods.TB_SETBUTTONINFO, i, ref buttonInfo);
            }

            // Add ComboBox controls.
            this.Controls.Clear();
            for (int i = 0; i < items.Count; i++)
            {
                CommandBarComboBox comboBox = this.items[i] as CommandBarComboBox;
                if (comboBox != null)
                {
                    NativeMethods.RECT rect = new NativeMethods.RECT();
                    NativeMethods.SendMessage(this.Handle, NativeMethods.TB_GETITEMRECT, i, ref rect);

                    rect.top = rect.top + (((rect.bottom - rect.top) - comboBox.Height) / 2);

                    comboBox.ComboBox.Location = new Point(rect.left, rect.top);
                    this.Controls.Add(comboBox.ComboBox);
                }
            }

            this.UpdateSize();
        }
开发者ID:modulexcite,项目名称:Resourcer,代码行数:43,代码来源:CommandBar.cs

示例9: UpdateSize

        private void UpdateSize()
        {
            if (this.style == CommandBarStyle.Menu)
            {
                int fontHeight = Font.Height;

                using (Graphics graphics = this.CreateGraphics())
                {
                    using (TextGraphics textGraphics = new TextGraphics(graphics))
                    {
                        foreach (CommandBarItem item in items)
                        {
                            Size textSize = textGraphics.MeasureText(item.Text, this.Font);
                            if (fontHeight < textSize.Height)
                            {
                                fontHeight = textSize.Height;
                            }
                        }
                    }
                }

                NativeMethods.SendMessage(this.Handle, NativeMethods.TB_SETBUTTONSIZE, 0, (fontHeight << 16) | 0xffff);
            }

            Size size = new Size(0, 0);
            for (int i = 0; i < items.Count; i++)
            {
                NativeMethods.RECT rect = new NativeMethods.RECT();
                NativeMethods.SendMessage(Handle, NativeMethods.TB_GETRECT, i, ref rect);
                int height = rect.bottom - rect.top;
                if (height > size.Height)
                {
                    size.Height = height;
                }

                size.Width += rect.right - rect.left;

                CommandBarComboBox comboBox = items[i] as CommandBarComboBox;
                if ((comboBox != null) && (comboBox.ComboBox != null))
                {
                    if (comboBox.ComboBox.Height > size.Height)
                    {
                        size.Height = comboBox.ComboBox.Height;
                    }

                    this.UpdateComboBoxLocation(comboBox, i);
                }
            }

            this.Size = size;
        }
开发者ID:modulexcite,项目名称:Resourcer,代码行数:51,代码来源:CommandBar.cs

示例10: SetDisplayRectLocation

        private void SetDisplayRectLocation(int x, int y, bool preserveContents)
        {
            int xDelta = 0;
            int yDelta = 0;

            var client = ClientRectangle;
            var displayRectangle = _displayRect;
            int minX = Math.Min(client.Width - displayRectangle.Width, 0);
            int minY = Math.Min(client.Height - displayRectangle.Height, 0);

            if (x > 0)
                x = 0;
            if (x < minX)
                x = minX;
            if (y > 0)
                y = 0;
            if (y < minY)
                y = minY;

            if (displayRectangle.X != x)
                xDelta = x - displayRectangle.X;
            if (displayRectangle.Y != y)
                yDelta = y - displayRectangle.Y;

            _displayRect.X = x;
            _displayRect.Y = y;

            if ((xDelta != 0 || yDelta != 0) && IsHandleCreated && preserveContents)
            {
                var cr = ClientRectangle;
                var rcClip = new NativeMethods.RECT(cr);
                var rcUpdate = new NativeMethods.RECT(cr);

                NativeMethods.ScrollWindowEx(
                    new HandleRef(this, Handle), xDelta, yDelta,
                    IntPtr.Zero,
                    ref rcClip,
                    IntPtr.Zero,
                    ref rcUpdate,
                    NativeMethods.SW_INVALIDATE | NativeMethods.SW_SCROLLCHILDREN
                );
            }

            OnDisplayRectangleChanged(EventArgs.Empty);
        }
开发者ID:fffCBBG,项目名称:HackMarathon,代码行数:45,代码来源:CustomScrollControl.cs

示例11: logWindowLocationsToolStripMenuItem_Click

 private void logWindowLocationsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     foreach (IDockContent c in this.DockPanel.Documents)
     {
         ctlPuttyPanel panel = c as ctlPuttyPanel;
         if (c != null)
         {
             NativeMethods.RECT rect = new NativeMethods.RECT();
             NativeMethods.GetWindowRect(panel.AppPanel.AppWindowHandle, ref rect);
             Point p = panel.PointToScreen(new Point());
             Log.InfoFormat(
                 "[{0,-20} {1,8}] WindowLocations: panel={2}, putty={3}, x={4}, y={5}",
                 panel.Text + (panel == panel.DockPanel.ActiveDocument ? "*" : ""),
                 panel.AppPanel.AppWindowHandle,
                 panel.DisplayRectangle,
                 rect, p.X, p.Y);
         }
     }
 }
开发者ID:keramist,项目名称:superputty,代码行数:19,代码来源:frmSuperPutty.cs

示例12: GetNotifyIconRectWindows7

        /// <summary>
        /// Returns a rectangle representing the location of the specified NotifyIcon. (Windows 7+.)
        /// </summary>
        /// <param name="notifyicon">The NotifyIcon whose location should be returned.</param>
        /// <returns>The location of the specified NotifyIcon. Null if the location could not be found.</returns>
        public static Rect? GetNotifyIconRectWindows7(NotifyIcon notifyicon)
        {
            if (Compatibility.CurrentWindowsVersion != Compatibility.WindowsVersion.Windows7Plus)
                throw new PlatformNotSupportedException("This method can only be used under Windows 7 or later. Please use GetNotifyIconRectangleLegacy() if you use an earlier operating system.");

            // get notify icon id
            FieldInfo idFieldInfo = notifyicon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance);
            int iconid = (int)idFieldInfo.GetValue(notifyicon);

            // get notify icon hwnd
            IntPtr iconhandle;
            try
            {
                FieldInfo windowFieldInfo = notifyicon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance);
                System.Windows.Forms.NativeWindow nativeWindow = (System.Windows.Forms.NativeWindow)windowFieldInfo.GetValue(notifyicon);
                iconhandle = nativeWindow.Handle;
                if (iconhandle == null || iconhandle == IntPtr.Zero)
                    return null;
            } catch {
                return null;
            }

            NativeMethods.RECT rect = new NativeMethods.RECT();
            NativeMethods.NOTIFYICONIDENTIFIER nid = new NativeMethods.NOTIFYICONIDENTIFIER()
            {
                hWnd = iconhandle,
                uID = (uint)iconid
            };
            nid.cbSize = (uint)Marshal.SizeOf(nid);

            int result = NativeMethods.Shell_NotifyIconGetRect(ref nid, out rect);

            // 0 means success, 1 means the notify icon is in the fly-out - either is fine
            if (result != 0 && result != 1)
                return null;

            // convert to System.Rect and return
            return rect;
        }
开发者ID:navhaxs,项目名称:BrightnessTray,代码行数:44,代码来源:WindowPositioning.cs

示例13: DrawUpDownButton

            private void DrawUpDownButton()
            {
                bool mouseOver = false;
                bool mousePress = LeftKeyPressed();
                bool mouseInUpButton = false;

                NativeMethods.RECT rect = new NativeMethods.RECT();

                NativeMethods.GetClientRect(base.Handle, ref rect);

                Rectangle clipRect = Rectangle.FromLTRB(
                    rect.Top, rect.Left, rect.Right, rect.Bottom);

                Point cursorPoint = new Point();
                NativeMethods.GetCursorPos(ref cursorPoint);
                NativeMethods.GetWindowRect(base.Handle, ref rect);

                mouseOver = NativeMethods.PtInRect(ref rect, cursorPoint);

                cursorPoint.X -= rect.Left;
                cursorPoint.Y -= rect.Top;

                mouseInUpButton = cursorPoint.X < clipRect.Width / 2;

                using (Graphics g = Graphics.FromHwnd(base.Handle))
                {
                    UpDownButtonPaintEventArgs e =
                        new UpDownButtonPaintEventArgs(
                        g,
                        clipRect,
                        mouseOver,
                        mousePress,
                        mouseInUpButton);
                    _owner.OnPaintUpDownButton(e);
                }
            }
开发者ID:caocf,项目名称:workspace-kepler,代码行数:36,代码来源:TabControlEx.cs

示例14: WmNotifyDropDown

        /// <include file='doc\ToolBar.uex' path='docs/doc[@for="ToolBar.WmNotifyDropDown"]/*' />
        /// <devdoc>
        ///     The button clicked was a dropdown button.  If it has a menu specified,
        ///     show it now.  Otherwise, fire an onButtonDropDown event.
        /// </devdoc>
        /// <internalonly/>
        private void WmNotifyDropDown(ref Message m) {
            NativeMethods.NMTOOLBAR nmTB = (NativeMethods.NMTOOLBAR)m.GetLParam(typeof(NativeMethods.NMTOOLBAR));

            ToolBarButton tbb = (ToolBarButton)buttons[nmTB.iItem];
            if (tbb == null)
                throw new InvalidOperationException(SR.GetString(SR.ToolBarButtonNotFound));

            OnButtonDropDown(new ToolBarButtonClickEventArgs(tbb));

            Menu menu = tbb.DropDownMenu;
            if (menu != null) {
                NativeMethods.RECT rc = new NativeMethods.RECT();
                NativeMethods.TPMPARAMS tpm = new NativeMethods.TPMPARAMS();

                SendMessage(NativeMethods.TB_GETRECT, nmTB.iItem, ref rc);

                if ((menu.GetType()).IsAssignableFrom(typeof(ContextMenu))) {
                    ((ContextMenu)menu).Show(this, new Point(rc.left, rc.bottom));
                }
                else {
                    Menu main = menu.GetMainMenu();
                    if (main != null) {
                        main.ProcessInitMenuPopup(menu.Handle);
                    }

                    UnsafeNativeMethods.MapWindowPoints(new HandleRef(nmTB.hdr, nmTB.hdr.hwndFrom), NativeMethods.NullHandleRef, ref rc, 2);

                    tpm.rcExclude_left = rc.left;
                    tpm.rcExclude_top = rc.top;
                    tpm.rcExclude_right = rc.right;
                    tpm.rcExclude_bottom = rc.bottom;

                    SafeNativeMethods.TrackPopupMenuEx(
                                                  new HandleRef(menu, menu.Handle),
                                                  NativeMethods.TPM_LEFTALIGN |
                                                  NativeMethods.TPM_LEFTBUTTON |
                                                  NativeMethods.TPM_VERTICAL,
                                                  rc.left, rc.bottom,
                                                  new HandleRef(this, Handle), tpm);
                }
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:48,代码来源:ToolBar.cs

示例15: CenterToParent

        /// <include file='doc\Form.uex' path='docs/doc[@for="Form.CenterToParent"]/*' />
        /// <devdoc>
        ///     Centers the dialog to its parent.
        /// </devdoc>
        /// <internalonly/>
        protected void CenterToParent() {
            if (TopLevel) {
                Point p = new Point();
                Size s = Size;
                IntPtr ownerHandle = IntPtr.Zero;

                ownerHandle = UnsafeNativeMethods.GetWindowLong(new HandleRef(this, Handle), NativeMethods.GWL_HWNDPARENT);
                if (ownerHandle != IntPtr.Zero) {
                    Screen desktop = Screen.FromHandleInternal(ownerHandle);
                    Rectangle screenRect = desktop.WorkingArea;
                    NativeMethods.RECT ownerRect = new NativeMethods.RECT();

                    UnsafeNativeMethods.GetWindowRect(new HandleRef(null, ownerHandle), ref ownerRect);

                    p.X = (ownerRect.left + ownerRect.right - s.Width) / 2;
                    if (p.X < screenRect.X)
                        p.X = screenRect.X;
                    else if (p.X + s.Width > screenRect.X + screenRect.Width)
                        p.X = screenRect.X + screenRect.Width - s.Width;

                    p.Y = (ownerRect.top + ownerRect.bottom - s.Height) / 2;
                    if (p.Y < screenRect.Y)
                        p.Y = screenRect.Y;
                    else if (p.Y + s.Height > screenRect.Y + screenRect.Height)
                        p.Y = screenRect.Y + screenRect.Height - s.Height;

                    Location = p;
                }
                else {
                    CenterToScreen();
                }
            }
        }
开发者ID:mind0n,项目名称:hive,代码行数:38,代码来源:Form.cs


注:本文中的NativeMethods.RECT类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。