• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# NativeMethods.RECT类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ValidateOwnerDrawRegions

             // this eliminates flicker by removing the pieces we're going to paint ourselves from 
             // the update region.  Note the UpdateRegionBox is the bounding box of the actual update region.
             // this is just here so we can quickly eliminate rectangles that arent in the update region.
             public void ValidateOwnerDrawRegions(ComboBox comboBox, Rectangle updateRegionBox) {
                 NativeMethods.RECT validRect;
                 if (comboBox != null) { return; }
                 Rectangle topOwnerDrawArea = new Rectangle(0,0,comboBox.Width, innerBorder.Top);
                 Rectangle bottomOwnerDrawArea = new Rectangle(0,innerBorder.Bottom,comboBox.Width, comboBox.Height-innerBorder.Bottom);
                 Rectangle leftOwnerDrawArea = new Rectangle(0,0,innerBorder.Left, comboBox.Height);
                 Rectangle rightOwnerDrawArea = new Rectangle(innerBorder.Right,0,comboBox.Width - innerBorder.Right,comboBox.Height);
 
                 if (topOwnerDrawArea.IntersectsWith(updateRegionBox)) {                            
                     validRect =  new NativeMethods.RECT(topOwnerDrawArea);
                     SafeNativeMethods.ValidateRect(new HandleRef(comboBox, comboBox.Handle), ref validRect);
                 }
 
                 if (bottomOwnerDrawArea.IntersectsWith(updateRegionBox)) {                            
                     validRect =  new NativeMethods.RECT(bottomOwnerDrawArea);
                     SafeNativeMethods.ValidateRect(new HandleRef(comboBox, comboBox.Handle), ref validRect);
                 }
 
                 if (leftOwnerDrawArea.IntersectsWith(updateRegionBox)) {                            
                     validRect =  new NativeMethods.RECT(leftOwnerDrawArea);
                     SafeNativeMethods.ValidateRect(new HandleRef(comboBox, comboBox.Handle), ref validRect);
                 }
 
                 if (rightOwnerDrawArea.IntersectsWith(updateRegionBox)) {                            
                     validRect =  new NativeMethods.RECT(rightOwnerDrawArea);
                     SafeNativeMethods.ValidateRect(new HandleRef(comboBox, comboBox.Handle), ref validRect);
                 }
             
             }
开发者ID:mind0n,项目名称:hive,代码行数:32,代码来源:ComboBox.cs


示例17: GetNotifyIconRectLegacy


//.........这里部分代码省略.........

                // retrieve the number of toolbar buttons (i.e. notify icons)
                int buttoncount = NativeMethods.SendMessage(natoolbarhandle, NativeMethods.TB_BUTTONCOUNT, IntPtr.Zero, IntPtr.Zero).ToInt32();

                // get notification area's process id
                uint naprocessid;
                NativeMethods.GetWindowThreadProcessId(natoolbarhandle, out naprocessid);

                // get handle to notification area's process
                IntPtr naprocesshandle = NativeMethods.OpenProcess(NativeMethods.ProcessAccessFlags.All, false, naprocessid);

                if (naprocesshandle == IntPtr.Zero)
                    return null;

                // allocate enough memory within the notification area's process to store the button info we want
                IntPtr toolbarmemoryptr = NativeMethods.VirtualAllocEx(naprocesshandle, (IntPtr)null, (uint)Marshal.SizeOf(typeof(NativeMethods.TBBUTTON)), NativeMethods.AllocationType.Commit, NativeMethods.MemoryProtection.ReadWrite);

                if (toolbarmemoryptr == IntPtr.Zero)
                    return null;

                try
                {
                    // loop through the toolbar's buttons until we find our notify icon
                    for (int j = 0; !found && j < buttoncount; j++)
                    {
                        int bytesread = -1;

                        // ask the notification area to give us information about the current button
                        NativeMethods.SendMessage(natoolbarhandle, NativeMethods.TB_GETBUTTON, new IntPtr(j), toolbarmemoryptr);

                        // retrieve that information from the notification area's process
                        NativeMethods.TBBUTTON buttoninfo = new NativeMethods.TBBUTTON();
                        NativeMethods.ReadProcessMemory(naprocesshandle, toolbarmemoryptr, out buttoninfo, Marshal.SizeOf(buttoninfo), out bytesread);

                        if (bytesread != Marshal.SizeOf(buttoninfo))
                            return null;

                        if (buttoninfo.dwData == IntPtr.Zero)
                            return null;

                        // the dwData field contains a pointer to information about the notify icon:
                        // the handle of the notify icon (an 4/8 bytes) and the id of the notify icon (4 bytes)
                        IntPtr niinfopointer = buttoninfo.dwData;

                        // read the notify icon handle
                        IntPtr nihandlenew;
                        NativeMethods.ReadProcessMemory(naprocesshandle, niinfopointer, out nihandlenew, Marshal.SizeOf(typeof(IntPtr)), out bytesread);

                        if (bytesread != Marshal.SizeOf(typeof(IntPtr)))
                            return null;

                        // read the notify icon id
                        uint niidnew;
                        NativeMethods.ReadProcessMemory(naprocesshandle, niinfopointer + Marshal.SizeOf(typeof(IntPtr)), out niidnew, Marshal.SizeOf(typeof(uint)), out bytesread);

                        if (bytesread != Marshal.SizeOf(typeof(uint)))
                            return null;

                        // if we've found a match
                        if (nihandlenew == nihandle && niidnew == niid)
                        {
                            // check if the button is hidden: if it is, return the rectangle of the 'show hidden icons' button
                            if ((byte)(buttoninfo.fsState & NativeMethods.TBSTATE_HIDDEN) != 0)
                            {
                                nirect = GetNotifyAreaButtonRectangle();
                            }
                            else
                            {
                                NativeMethods.RECT result = new NativeMethods.RECT();

                                // get the relative rectangle of the toolbar button (notify icon)
                                NativeMethods.SendMessage(natoolbarhandle, NativeMethods.TB_GETITEMRECT, new IntPtr(j), toolbarmemoryptr);

                                NativeMethods.ReadProcessMemory(naprocesshandle, toolbarmemoryptr, out result, Marshal.SizeOf(result), out bytesread);

                                if (bytesread != Marshal.SizeOf(result))
                                    return null;

                                // find where the rectangle lies in relation to the screen
                                NativeMethods.MapWindowPoints(natoolbarhandle, (IntPtr)null, ref result, 2);

                                nirect = result;
                            }

                            found = true;
                        }
                    }
                }
                finally
                {
                    // free memory within process
                    NativeMethods.VirtualFreeEx(naprocesshandle, toolbarmemoryptr, 0, NativeMethods.FreeType.Release);

                    // close handle to process
                    NativeMethods.CloseHandle(naprocesshandle);
                }
            }

            return nirect;
        }
开发者ID:navhaxs,项目名称:BrightnessTray,代码行数:101,代码来源:WindowPositioning.cs


示例18: DrawTabPages

        private void DrawTabPages(Graphics g)
        {
            Rectangle tabRect;
            Point cusorPoint = PointToClient(MousePosition);
            bool hover;
            bool selected;
            bool hasSetClip = false;
            bool alignHorizontal =
                (Alignment == TabAlignment.Top || 
                Alignment == TabAlignment.Bottom);
            System.Drawing.Drawing2D.LinearGradientMode mode = alignHorizontal ?
                System.Drawing.Drawing2D.LinearGradientMode.Vertical : System.Drawing.Drawing2D.LinearGradientMode.Horizontal;

            if (alignHorizontal)
            {
                IntPtr upDownButtonHandle = UpDownButtonHandle;
                bool hasUpDown = upDownButtonHandle != IntPtr.Zero;
                if (hasUpDown)
                {
                    if (NativeMethods.IsWindowVisible(upDownButtonHandle))
                    {
                        NativeMethods.RECT upDownButtonRect = new NativeMethods.RECT();
                        NativeMethods.GetWindowRect(
                            upDownButtonHandle, ref upDownButtonRect);
                        Rectangle upDownRect = Rectangle.FromLTRB(
                            upDownButtonRect.Left,
                            upDownButtonRect.Top,
                            upDownButtonRect.Right,
                            upDownButtonRect.Bottom);
                        upDownRect = RectangleToClient(upDownRect);

                        switch (Alignment)
                        {
                            case TabAlignment.Top:
                                upDownRect.Y = 0;
                                break;
                            case TabAlignment.Bottom:
                                upDownRect.Y = 
                                    ClientRectangle.Height - DisplayRectangle.Height;
                                break;
                        }
                        upDownRect.Height = ClientRectangle.Height;
                        g.SetClip(upDownRect, CombineMode.Exclude);
                        hasSetClip = true;
                    }
                }
            }

            for(int index = 0; index <base.TabCount; index ++)
            {
                TabPage page = TabPages[index];

                tabRect = GetTabRect(index);
                hover = tabRect.Contains(cusorPoint);
                selected = SelectedIndex == index;

                Color baseColor = _baseColor;
                Color borderColor = _borderColor;

                if (selected)
                {
                    baseColor = GetColor(_baseColor, 0, -45, -30, -14);
                }
                else if (hover)
                {
                    baseColor = GetColor(_baseColor, 0, 35, 24, 9);
                }

                RenderTabBackgroundInternal(
                    g,
                    tabRect,
                    baseColor,
                    borderColor,
                    .45F,
                    mode);

                bool hasImage = DrawTabImage(g, page, tabRect);

                DrawtabText(g, page, tabRect, hasImage);
            }
            if (hasSetClip)
            {
                g.ResetClip();
            }
        }
开发者ID:caocf,项目名称:workspace-kepler,代码行数:85,代码来源:TabControlEx.cs


示例19: GetWindowSize

 /// <summary>
 /// Returns a Rect containing the bounds of the specified window's area (i.e. area excluding border).
 /// </summary>
 /// <param name="hWnd">Handle of the window.</param>
 /// <returns>Rect containing window bounds.</returns>
 public static Rect GetWindowSize(IntPtr hWnd)
 {
     NativeMethods.RECT result = new NativeMethods.RECT();
     if (NativeMethods.GetWindowRect(hWnd, out result))
         return result;
     else
         throw new Exception(String.Format("Could not find window bounds for specified window (handle {0:X})", hWnd));
 }
开发者ID:navhaxs,项目名称:BrightnessTray,代码行数:13,代码来源:WindowPositioning.cs


示例20: DrawBorder

        private void DrawBorder(Graphics g)
        {
            if (SelectedIndex != -1)
            {
                Rectangle tabRect = GetTabRect(SelectedIndex);
                Rectangle clipRect = ClientRectangle;
                Point[] points = new Point[6];

                IntPtr upDownButtonHandle = UpDownButtonHandle;
                bool hasUpDown = upDownButtonHandle != IntPtr.Zero;
                if (hasUpDown)
                {
                    if (NativeMethods.IsWindowVisible(upDownButtonHandle))
                    {
                        NativeMethods.RECT upDownButtonRect = new NativeMethods.RECT();
                        NativeMethods.GetWindowRect(
                            upDownButtonHandle,
                            ref upDownButtonRect);
                        Rectangle upDownRect = Rectangle.FromLTRB(
                            upDownButtonRect.Left,
                            upDownButtonRect.Top,
                            upDownButtonRect.Right,
                            upDownButtonRect.Bottom);
                        upDownRect = RectangleToClient(upDownRect);

                        tabRect.X = tabRect.X > upDownRect.X ?
                            upDownRect.X : tabRect.X;
                        tabRect.Width = tabRect.Right > upDownRect.X ?
                            upDownRect.X - tabRect.X : tabRect.Width;
                    }
                }

                switch (Alignment)
                {
                    case TabAlignment.Top:
                        points[0] = new Point(
                            tabRect.X,
                            tabRect.Bottom);
                        points[1] = new Point(
                            clipRect.X,
                            tabRect.Bottom);
                        points[2] = new Point(
                            clipRect.X,
                            clipRect.Bottom - 1);
                        points[3] = new Point(
                            clipRect.Right - 1,
                            clipRect.Bottom - 1);
                        points[4] = new Point(
                            clipRect.Right - 1,
                            tabRect.Bottom);
                        points[5] = new Point(
                            tabRect.Right,
                            tabRect.Bottom);
                        break;
                    case TabAlignment.Bottom:
                        points[0] = new Point(
                            tabRect.X,
                            tabRect.Y);
                        points[1] = new Point(
                            clipRect.X,
                            tabRect.Y);
                        points[2] = new Point(
                            clipRect.X,
                            clipRect.Y);
                        points[3] = new Point(
                            clipRect.Right - 1,
                            clipRect.Y);
                        points[4] = new Point(
                            clipRect.Right - 1,
                            tabRect.Y);
                        points[5] = new Point(
                            tabRect.Right,
                            tabRect.Y);
                        break;
                    case TabAlignment.Left:
                        points[0] = new Point(
                            tabRect.Right,
                            tabRect.Y);
                        points[1] = new Point(
                            tabRect.Right,
                            clipRect.Y);
    

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# NativePage类代码示例发布时间:2022-05-24
下一篇:
C# NativeMethods类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap