diff --git a/src/Common/src/NativeMethods.cs b/src/Common/src/NativeMethods.cs index a34a4dab577..0ba1d0ab726 100644 --- a/src/Common/src/NativeMethods.cs +++ b/src/Common/src/NativeMethods.cs @@ -1822,7 +1822,7 @@ public class HH_POPUP internal IntPtr hinst = IntPtr.Zero; internal int idString = 0; internal IntPtr pszText; - internal POINT pt; + internal Point pt; internal int clrForeground = -1; internal int clrBackground = -1; internal Interop.RECT rcMargins = new Interop.RECT(-1, -1, -1, -1); // amount of space between edges of window and text, -1 for each member to ignore @@ -2087,30 +2087,6 @@ public class TRACKMOUSEEVENT public int dwHoverTime = 100; // Never set this to field ZERO, or to HOVER_DEFAULT, ever! } - [StructLayout(LayoutKind.Sequential)] - public class POINT - { - public int x; - public int y; - - public POINT() - { - } - - public POINT(int x, int y) - { - this.x = x; - this.y = y; - } - -#if DEBUG - public override string ToString() - { - return "{x=" + x + ", y=" + y + "}"; - } -#endif - } - // use this in cases where the Native API takes a POINT not a POINT* // classes marshal by ref. [StructLayout(LayoutKind.Sequential)] @@ -2171,9 +2147,7 @@ public struct MSG public IntPtr wParam; public IntPtr lParam; public int time; - // pt was a by-value POINT structure - public int pt_x; - public int pt_y; + public Point pt; } [StructLayout(LayoutKind.Sequential)] @@ -2248,12 +2222,8 @@ public struct WINDOWPLACEMENT public int length; public int flags; public int showCmd; - // ptMinPosition was a by-value POINT structure - public int ptMinPosition_x; - public int ptMinPosition_y; - // ptMaxPosition was a by-value POINT structure - public int ptMaxPosition_x; - public int ptMaxPosition_y; + public Point ptMinPosition; + public Point ptMaxPosition; // rcNormalPosition was a by-value RECT structure public int rcNormalPosition_left; public int rcNormalPosition_top; @@ -2292,10 +2262,7 @@ public class PAGESETUPDLG public IntPtr hDevMode; public IntPtr hDevNames; public int Flags; - - //POINT ptPaperSize; - public int paperSizeX = 0; - public int paperSizeY = 0; + public Point paperSize; // RECT rtMinMargin; public int minMarginLeft; @@ -3649,11 +3616,7 @@ public struct NMTREEVIEW public int action; public TV_ITEM itemOld; public TV_ITEM itemNew; - public int ptDrag_X; // This should be declared as POINT - public int ptDrag_Y; // we use unsafe blocks to manipulate - // NMTREEVIEW quickly, and POINT is declared - // as a class. Too much churn to change POINT - // now. + public Point ptDrag; } [StructLayout(LayoutKind.Sequential)] @@ -3850,7 +3813,7 @@ public class HELPINFO public int iCtrlId = 0; public IntPtr hItemHandle = IntPtr.Zero; public IntPtr dwContextId = IntPtr.Zero; - public POINT MousePos = null; + public Point MousePos; } [StructLayout(LayoutKind.Sequential)] @@ -3864,11 +3827,11 @@ public class ACCEL [StructLayout(LayoutKind.Sequential)] public class MINMAXINFO { - public POINT ptReserved = null; - public POINT ptMaxSize = null; - public POINT ptMaxPosition = null; - public POINT ptMinTrackSize = null; - public POINT ptMaxTrackSize = null; + public Point ptReserved; + public Point ptMaxSize; + public Point ptMaxPosition; + public Point ptMinTrackSize; + public Point ptMaxTrackSize; } [ComImport] @@ -4130,8 +4093,7 @@ public struct LVFINDINFO public int flags; public string psz; public IntPtr lParam; - public int ptX; // was POINT pt - public int ptY; + public Point pt; public int vkDirection; } @@ -4321,9 +4283,7 @@ public class NMHEADER [StructLayout(LayoutKind.Sequential)] public class MOUSEHOOKSTRUCT { - // pt was a by-value POINT structure - public int pt_x = 0; - public int pt_y = 0; + public Point pt; public IntPtr hWnd = IntPtr.Zero; public int wHitTestCode = 0; public int dwExtraInfo = 0; @@ -5462,7 +5422,7 @@ public UiaRect(Drawing.Rectangle r) public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, ref Interop.RECT rect, int cPoints); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, [In, Out] POINT pt, int cPoints); + public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, ref Point pt, uint cPoints); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] public static extern IntPtr WindowFromPoint(int x, int y); @@ -5489,7 +5449,7 @@ public UiaRect(Drawing.Rectangle r) public static extern IntPtr GetCursor(); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern bool GetCursorPos([In, Out] POINT pt); + public static extern bool GetCursorPos(out Point pt); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] public static extern IntPtr SetParent(IntPtr hWnd, IntPtr hWndParent); diff --git a/src/Common/src/SafeNativeMethods.cs b/src/Common/src/SafeNativeMethods.cs index b78bd897d01..1a0b94b8558 100644 --- a/src/Common/src/SafeNativeMethods.cs +++ b/src/Common/src/SafeNativeMethods.cs @@ -82,7 +82,7 @@ internal static class SafeNativeMethods public static extern bool LineTo(HandleRef hdc, int x, int y); [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern bool MoveToEx(HandleRef hdc, int x, int y, NativeMethods.POINT pt); + public static unsafe extern bool MoveToEx(HandleRef hdc, int x, int y, Point *lppt); [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)] public static extern bool Rectangle( @@ -360,7 +360,14 @@ public static IntPtr ImageList_Read(UnsafeNativeMethods.IStream pstm) public static extern IntPtr /* HPALETTE */SelectPalette(HandleRef hdc, HandleRef hpal, int bForceBackground); [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern bool SetViewportOrgEx(HandleRef hDC, int x, int y, [In, Out] NativeMethods.POINT point); + public static unsafe extern bool SetViewportOrgEx(IntPtr hdc, int x, int y, Point *lppt); + + public static unsafe bool SetViewportOrgEx(HandleRef hdc, int x, int y, Point *lppt) + { + bool result = SetViewportOrgEx(hdc.Handle, x, y, lppt); + GC.KeepAlive(hdc.Wrapper); + return result; + } [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)] public static extern int RealizePalette(HandleRef hDC); @@ -369,10 +376,10 @@ public static IntPtr ImageList_Read(UnsafeNativeMethods.IStream pstm) public static extern bool LPtoDP(HandleRef hDC, ref Interop.RECT lpRect, int nCount); [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern bool SetWindowOrgEx(HandleRef hDC, int x, int y, [In, Out] NativeMethods.POINT point); + public static unsafe extern bool SetWindowOrgEx(IntPtr hdc, int x, int y, Point *lppt); [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern bool GetViewportOrgEx(HandleRef hDC, [In, Out] NativeMethods.POINT point); + public static extern bool GetViewportOrgEx(HandleRef hdc, out Point lppoint); [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)] public static extern int SetMapMode(HandleRef hDC, int nMapMode); @@ -590,7 +597,7 @@ public static extern bool BitBlt(HandleRef hDC, int x, int y, int nWidth, int nH public static extern int GetThemePartSize(HandleRef hTheme, HandleRef hdc, int iPartId, int iStateId, [In] NativeMethods.COMRECT prc, VisualStyles.ThemeSizeType eSize, [Out] NativeMethods.SIZE psz); [DllImport(ExternDll.Uxtheme, CharSet = CharSet.Auto)] - public static extern int GetThemePosition(HandleRef hTheme, int iPartId, int iStateId, int iPropId, [Out] NativeMethods.POINT pPoint); + public static extern int GetThemePosition(HandleRef hTheme, int iPartId, int iStateId, int iPropId, out Point pPoint); [DllImport(ExternDll.Uxtheme, CharSet = CharSet.Auto)] public static extern int GetThemeMargins(HandleRef hTheme, HandleRef hDC, int iPartId, int iStateId, int iPropId, NativeMethods.COMRECT prc, ref NativeMethods.MARGINS margins); diff --git a/src/Common/src/UnsafeNativeMethods.cs b/src/Common/src/UnsafeNativeMethods.cs index d8a36c97ee1..485ef8a8ccc 100644 --- a/src/Common/src/UnsafeNativeMethods.cs +++ b/src/Common/src/UnsafeNativeMethods.cs @@ -261,7 +261,7 @@ public static int DragQueryFileLongPath(HandleRef hDrop, int iFile, StringBuilde public static extern IntPtr CallNextHookEx(HandleRef hhook, int code, IntPtr wparam, IntPtr lparam); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern int ScreenToClient(HandleRef hWnd, [In, Out] NativeMethods.POINT pt); + public static extern int ScreenToClient(HandleRef hWnd, ref Point pt); [DllImport(ExternDll.Kernel32, CharSet = CharSet.Auto, SetLastError = true)] public static extern int GetModuleFileName(HandleRef hModule, StringBuilder buffer, int length); @@ -373,7 +373,7 @@ public static IntPtr ChildWindowFromPointEx(HandleRef hwndParent, int x, int y, public static extern IntPtr GetFocus(); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern bool GetCursorPos([In, Out] NativeMethods.POINT pt); + public static extern bool GetCursorPos(out Point pt); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] public static extern short GetKeyState(int keyCode); @@ -454,7 +454,7 @@ public static IntPtr ChildWindowFromPointEx(HandleRef hwndParent, int x, int y, public static extern int MapWindowPoints(HandleRef hWndFrom, HandleRef hWndTo, ref Interop.RECT rect, int cPoints); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern int MapWindowPoints(HandleRef hWndFrom, HandleRef hWndTo, [In, Out] NativeMethods.POINT pt, int cPoints); + public static extern int MapWindowPoints(HandleRef hWndFrom, HandleRef hWndTo, ref Point pt, uint cPoints); [DllImport(ExternDll.User32, CharSet = CharSet.Auto)] public static extern IntPtr SendMessage(HandleRef hWnd, int msg, bool wParam, int lParam); @@ -548,10 +548,10 @@ public static IntPtr ChildWindowFromPointEx(HandleRef hwndParent, int x, int y, public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, NativeMethods.TEXTRANGE lParam); [DllImport(ExternDll.User32, CharSet = CharSet.Auto)] - public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, NativeMethods.POINT lParam); + public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, ref Point lParam); [DllImport(ExternDll.User32, CharSet = CharSet.Auto)] - public static extern IntPtr SendMessage(HandleRef hWnd, int msg, NativeMethods.POINT wParam, int lParam); + public static extern IntPtr SendMessage(HandleRef hWnd, int msg, ref Point wParam, int lParam); [DllImport(ExternDll.User32, CharSet = CharSet.Auto)] public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, NativeMethods.EDITSTREAM lParam); @@ -588,7 +588,7 @@ public static IntPtr ChildWindowFromPointEx(HandleRef hwndParent, int x, int y, public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, NativeMethods.LVGROUP lParam); [DllImport(ExternDll.User32, CharSet = CharSet.Auto)] - public static extern IntPtr SendMessage(HandleRef hWnd, int msg, NativeMethods.POINT wParam, [In, Out] NativeMethods.LVINSERTMARK lParam); + public static extern IntPtr SendMessage(HandleRef hWnd, int msg, ref Point wParam, [In, Out] NativeMethods.LVINSERTMARK lParam); [DllImport(ExternDll.User32, CharSet = CharSet.Auto)] public static extern bool SendMessage(HandleRef hWnd, int msg, int wParam, NativeMethods.LVINSERTMARK lParam); @@ -787,7 +787,7 @@ public unsafe static bool TrySystemParametersInfoForDpi(ref NativeMethods.NONCLI public static extern bool GetUserObjectInformation(HandleRef hObj, int nIndex, ref NativeMethods.USEROBJECTFLAGS pvBuffer, int nLength, ref int lpnLengthNeeded); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern int ClientToScreen(HandleRef hWnd, [In, Out] NativeMethods.POINT pt); + public static extern int ClientToScreen(HandleRef hWnd, ref Point lpPoint); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] public static extern IntPtr GetForegroundWindow(); @@ -1507,10 +1507,8 @@ public interface IDocHostUIHandler [return: MarshalAs(UnmanagedType.I4)] [PreserveSig] int ShowContextMenu( - [In, MarshalAs(UnmanagedType.U4)] - int dwID, - [In] - NativeMethods.POINT pt, + uint dwID, + ref Point pt, [In, MarshalAs(UnmanagedType.Interface)] object pcmdtReserved, [In, MarshalAs(UnmanagedType.Interface)] diff --git a/src/System.Windows.Forms.Design.Editors/src/Misc/NativeMethods.cs b/src/System.Windows.Forms.Design.Editors/src/Misc/NativeMethods.cs index 97f4cc6a9f9..f4e833e314b 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Misc/NativeMethods.cs +++ b/src/System.Windows.Forms.Design.Editors/src/Misc/NativeMethods.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Drawing; using System.Runtime.InteropServices; namespace System.Windows.Forms.Design @@ -57,23 +58,6 @@ internal static partial class NativeMethods [DllImport(ExternDll.User32, CharSet = CharSet.Auto)] public static extern IntPtr PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam); - [StructLayout(LayoutKind.Sequential)] - public class POINT - { - public int x; - public int y; - - public POINT() - { - } - - public POINT(int x, int y) - { - this.x = x; - this.y = y; - } - } - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)] public class TV_ITEM { @@ -107,7 +91,7 @@ public class NMTREEVIEW public readonly TV_ITEM itemNew = null; public readonly TV_ITEM itemOld = null; public readonly NMHDR nmhdr = null; - public readonly POINT ptDrag = null; + public readonly Point ptDrag; } [StructLayout(LayoutKind.Sequential)] @@ -160,9 +144,7 @@ public struct MSG public int time; - // pt was a by-value POINT structure - public int pt_x; - public int pt_y; + public Point pt; } [StructLayout(LayoutKind.Sequential)] diff --git a/src/System.Windows.Forms.Design.Editors/src/Misc/UnsafeNativeMethods.cs b/src/System.Windows.Forms.Design.Editors/src/Misc/UnsafeNativeMethods.cs index 2390e8ccbbf..1d8c7129d79 100644 --- a/src/System.Windows.Forms.Design.Editors/src/Misc/UnsafeNativeMethods.cs +++ b/src/System.Windows.Forms.Design.Editors/src/Misc/UnsafeNativeMethods.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Drawing; using System.Runtime.InteropServices; using IComDataObject = System.Runtime.InteropServices.ComTypes.IDataObject; @@ -10,10 +11,10 @@ namespace System.Windows.Forms.Design internal class UnsafeNativeMethods { [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern int ClientToScreen(HandleRef hWnd, [In] [Out] NativeMethods.POINT pt); + public static extern int ClientToScreen(HandleRef hWnd, ref Point lpPoint); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern int ScreenToClient(HandleRef hWnd, [In, Out] NativeMethods.POINT pt); + public static extern int ScreenToClient(HandleRef hWnd, ref Point lpPoint); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] public static extern IntPtr GetActiveWindow(); diff --git a/src/System.Windows.Forms.Design.Editors/src/System/Drawing/Design/ColorEditor.cs b/src/System.Windows.Forms.Design.Editors/src/System/Drawing/Design/ColorEditor.cs index 076f0ace665..258e2f52ee6 100644 --- a/src/System.Windows.Forms.Design.Editors/src/System/Drawing/Design/ColorEditor.cs +++ b/src/System.Windows.Forms.Design.Editors/src/System/Drawing/Design/ColorEditor.cs @@ -587,11 +587,10 @@ public override AccessibleObject GetChild(int id) public override AccessibleObject HitTest(int x, int y) { // Convert from screen to client coordinates - // - NativeMethods.POINT pt = new NativeMethods.POINT(x, y); - UnsafeNativeMethods.ScreenToClient(new HandleRef(ColorPalette, ColorPalette.Handle), pt); + var pt = new Point(x, y); + UnsafeNativeMethods.ScreenToClient(new HandleRef(ColorPalette, ColorPalette.Handle), ref pt); - int cell = ColorPalette.GetCellFromLocationMouse(pt.x, pt.y); + int cell = ColorPalette.GetCellFromLocationMouse(pt.X, pt.Y); if (cell != -1) { return GetChild(cell); @@ -624,10 +623,10 @@ public override Rectangle Bounds // Translate rect to screen coordinates // - NativeMethods.POINT pt = new NativeMethods.POINT(rect.X, rect.Y); - UnsafeNativeMethods.ClientToScreen(new HandleRef(parent.ColorPalette, parent.ColorPalette.Handle), pt); + var pt = new Point(rect.X, rect.Y); + UnsafeNativeMethods.ClientToScreen(new HandleRef(parent.ColorPalette, parent.ColorPalette.Handle), ref pt); - return new Rectangle(pt.x, pt.y, rect.Width, rect.Height); + return new Rectangle(pt.X, pt.Y, rect.Width, rect.Height); } } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorService.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorService.cs index da20faeba77..fc344337962 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorService.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorService.cs @@ -324,9 +324,8 @@ private void OnBeginDrag(BehaviorDragDropEventArgs e) /// public Point AdornerWindowPointToScreen(Point p) { - NativeMethods.POINT offset = new NativeMethods.POINT(p.X, p.Y); - NativeMethods.MapWindowPoints(_adornerWindow.Handle, IntPtr.Zero, offset, 1); - return new Point(offset.x, offset.y); + NativeMethods.MapWindowPoints(_adornerWindow.Handle, IntPtr.Zero, ref p, 1); + return p; } /// @@ -348,17 +347,13 @@ public Point ControlToAdornerWindow(Control c) return Point.Empty; } - NativeMethods.POINT pt = new NativeMethods.POINT - { - x = c.Left, - y = c.Top - }; - NativeMethods.MapWindowPoints(c.Parent.Handle, _adornerWindow.Handle, pt, 1); + var pt = new Point(c.Left, c.Top); + NativeMethods.MapWindowPoints(c.Parent.Handle, _adornerWindow.Handle, ref pt, 1); if (c.Parent.IsMirrored) { - pt.x -= c.Width; + pt.X -= c.Width; } - return new Point(pt.x, pt.y); + return pt; } /// @@ -366,13 +361,8 @@ public Point ControlToAdornerWindow(Control c) /// public Point MapAdornerWindowPoint(IntPtr handle, Point pt) { - NativeMethods.POINT nativePoint = new NativeMethods.POINT - { - x = pt.X, - y = pt.Y - }; - NativeMethods.MapWindowPoints(handle, _adornerWindow.Handle, nativePoint, 1); - return new Point(nativePoint.x, nativePoint.y); + NativeMethods.MapWindowPoints(handle, _adornerWindow.Handle, ref pt, 1); + return pt; } /// @@ -566,13 +556,8 @@ public void PushCaptureBehavior(Behavior behavior) /// public Point ScreenToAdornerWindow(Point p) { - NativeMethods.POINT offset = new NativeMethods.POINT - { - x = p.X, - y = p.Y - }; - NativeMethods.MapWindowPoints(IntPtr.Zero, _adornerWindow.Handle, offset, 1); - return new Point(offset.x, offset.y); + NativeMethods.MapWindowPoints(IntPtr.Zero, _adornerWindow.Handle, ref p, 1); + return p; } internal void OnLoseCapture() @@ -832,11 +817,9 @@ protected override void OnDragEnter(DragEventArgs e) if (!IsLocalDrag(e)) { _behaviorService._validDragArgs = e; - NativeMethods.POINT pt = new NativeMethods.POINT(); - NativeMethods.GetCursorPos(pt); - NativeMethods.MapWindowPoints(IntPtr.Zero, Handle, pt, 1); - Point mousePos = new Point(pt.x, pt.y); - _behaviorService.PropagateHitTest(mousePos); + NativeMethods.GetCursorPos(out Point pt); + NativeMethods.MapWindowPoints(IntPtr.Zero, Handle, ref pt, 1); + _behaviorService.PropagateHitTest(pt); } _behaviorService.OnDragEnter(null, e); @@ -868,11 +851,9 @@ protected override void OnDragOver(DragEventArgs e) if (!IsLocalDrag(e)) { _behaviorService._validDragArgs = e; - NativeMethods.POINT pt = new NativeMethods.POINT(); - NativeMethods.GetCursorPos(pt); - NativeMethods.MapWindowPoints(IntPtr.Zero, Handle, pt, 1); - Point mousePos = new Point(pt.x, pt.y); - _behaviorService.PropagateHitTest(mousePos); + NativeMethods.GetCursorPos(out Point pt); + NativeMethods.MapWindowPoints(IntPtr.Zero, Handle, ref pt, 1); + _behaviorService.PropagateHitTest(pt); } _behaviorService.OnDragOver(e); @@ -954,13 +935,9 @@ protected override void WndProc(ref Message m) case Interop.WindowMessages.WM_NCHITTEST: Point pt = new Point((short)NativeMethods.Util.LOWORD(unchecked((int)(long)m.LParam)), (short)NativeMethods.Util.HIWORD(unchecked((int)(long)m.LParam))); - NativeMethods.POINT pt1 = new NativeMethods.POINT - { - x = 0, - y = 0 - }; - NativeMethods.MapWindowPoints(IntPtr.Zero, Handle, pt1, 1); - pt.Offset(pt1.x, pt1.y); + var pt1 = new Point(); + NativeMethods.MapWindowPoints(IntPtr.Zero, Handle, ref pt1, 1); + pt.Offset(pt1.X, pt1.Y); if (_behaviorService.PropagateHitTest(pt) && !ProcessingDrag) { m.Result = (IntPtr)(NativeMethods.HTTRANSPARENT); @@ -1128,7 +1105,7 @@ private unsafe IntPtr MouseHookProc(int nCode, IntPtr wparam, IntPtr lparam) { try { - if (ProcessMouseMessage(mhs.hWnd, unchecked((int)(long)wparam), mhs.pt_x, mhs.pt_y)) + if (ProcessMouseMessage(mhs.hWnd, unchecked((int)(long)wparam), mhs.pt.X, mhs.pt.Y)) { return (IntPtr)1; } @@ -1202,13 +1179,9 @@ private bool ProcessMouseMessage(IntPtr hWnd, int msg, int x, int y) try { _processingMessage = true; - NativeMethods.POINT pt = new NativeMethods.POINT - { - x = x, - y = y - }; - NativeMethods.MapWindowPoints(IntPtr.Zero, adornerWindow.Handle, pt, 1); - Message m = Message.Create(hWnd, msg, (IntPtr)0, (IntPtr)MAKELONG(pt.y, pt.x)); + var pt = new Point(x, y); + NativeMethods.MapWindowPoints(IntPtr.Zero, adornerWindow.Handle, ref pt, 1); + Message m = Message.Create(hWnd, msg, (IntPtr)0, (IntPtr)MAKELONG(pt.Y, pt.X)); // No one knows why we get an extra click here from VS. As a workaround, we check the TimeStamp and discard it. if (m.Msg == Interop.WindowMessages.WM_LBUTTONDOWN) { @@ -1223,7 +1196,7 @@ private bool ProcessMouseMessage(IntPtr hWnd, int msg, int x, int y) } } - if (!adornerWindow.WndProcProxy(ref m, pt.x, pt.y)) + if (!adornerWindow.WndProcProxy(ref m, pt.X, pt.Y)) { // we did the work, stop the message propogation return true; diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/ResizeBehavior.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/ResizeBehavior.cs index 46e1873c2eb..cf4d29f3b10 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/ResizeBehavior.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/ResizeBehavior.cs @@ -38,7 +38,7 @@ private struct ResizeComponent private Point _lastMouseLoc; //helps us avoid re-entering code if the mouse hasn't moved private Point _parentLocation; //used to snap resize ops to the grid private Size _parentGridSize; //used to snap resize ops to the grid - private NativeMethods.POINT _lastMouseAbs; // last absolute mouse position + private Point _lastMouseAbs; // last absolute mouse position private Point _lastSnapOffset; //the last snapoffset we used. private bool _didSnap; //did we actually snap. private Control _primaryControl; //the primary control the status bar will queue off of @@ -465,9 +465,9 @@ public override bool OnMouseMove(Glyph g, MouseButtons button, Point mouseLoc) // When DesignerWindowPane has scrollbars and we resize, shrinking the the DesignerWindowPane makes it look like the mouse has moved to the BS. To compensate for that we keep track of the mouse's previous position in screen coordinates, and use that to compare if the mouse has really moved. if (_lastMouseAbs != null) { - NativeMethods.POINT mouseLocAbs = new NativeMethods.POINT(mouseLoc.X, mouseLoc.Y); - UnsafeNativeMethods.ClientToScreen(new HandleRef(this, _behaviorService.AdornerWindowControl.Handle), mouseLocAbs); - if (mouseLocAbs.x == _lastMouseAbs.x && mouseLocAbs.y == _lastMouseAbs.y) + var mouseLocAbs = new Point(mouseLoc.X, mouseLoc.Y); + UnsafeNativeMethods.ClientToScreen(new HandleRef(this, _behaviorService.AdornerWindowControl.Handle), ref mouseLocAbs); + if (mouseLocAbs.X == _lastMouseAbs.X && mouseLocAbs.Y == _lastMouseAbs.Y) { return true; } @@ -528,8 +528,8 @@ public override bool OnMouseMove(Glyph g, MouseButtons button, Point mouseLoc) Control targetControl = _resizeComponents[0].resizeControl as Control; _lastMouseLoc = mouseLoc; - _lastMouseAbs = new NativeMethods.POINT(mouseLoc.X, mouseLoc.Y); - UnsafeNativeMethods.ClientToScreen(new HandleRef(this, _behaviorService.AdornerWindowControl.Handle), _lastMouseAbs); + _lastMouseAbs = new Point(mouseLoc.X, mouseLoc.Y); + UnsafeNativeMethods.ClientToScreen(new HandleRef(this, _behaviorService.AdornerWindowControl.Handle), ref _lastMouseAbs); int minHeight = Math.Max(targetControl.MinimumSize.Height, MINSIZE); int minWidth = Math.Max(targetControl.MinimumSize.Width, MINSIZE); if (_dragManager != null) diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/CommandSet.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/CommandSet.cs index c2aa98793fc..90988988d47 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/CommandSet.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/CommandSet.cs @@ -541,9 +541,8 @@ protected virtual bool OnKeyCancel(object sender) if (tbx != null && tbx.GetSelectedToolboxItem((IDesignerHost)GetService(typeof(IDesignerHost))) != null) { tbx.SelectedToolboxItemUsed(); - NativeMethods.POINT p = new NativeMethods.POINT(); - NativeMethods.GetCursorPos(p); - IntPtr hwnd = NativeMethods.WindowFromPoint(p.x, p.y); + NativeMethods.GetCursorPos(out Point p); + IntPtr hwnd = NativeMethods.WindowFromPoint(p.X, p.Y); if (hwnd != IntPtr.Zero) { NativeMethods.SendMessage(hwnd, Interop.WindowMessages.WM_SETCURSOR, hwnd, (IntPtr)NativeMethods.HTCLIENT); diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ComponentTray.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ComponentTray.cs index 1c98551f4cb..6ca4ec3ce27 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ComponentTray.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ComponentTray.cs @@ -1641,13 +1641,9 @@ protected override void WndProc(ref Message m) { // Get a hit test on any glyhs that we are managing this way - we know where to route appropriate messages Point pt = new Point((short)NativeMethods.Util.LOWORD(unchecked((int)(long)m.LParam)), (short)NativeMethods.Util.HIWORD(unchecked((int)(long)m.LParam))); - NativeMethods.POINT pt1 = new NativeMethods.POINT - { - x = 0, - y = 0 - }; - NativeMethods.MapWindowPoints(IntPtr.Zero, Handle, pt1, 1); - pt.Offset(pt1.x, pt1.y); + var pt1 = new Point(); + NativeMethods.MapWindowPoints(IntPtr.Zero, Handle, ref pt1, 1); + pt.Offset(pt1.X, pt1.Y); glyphManager.GetHitTest(pt); } base.WndProc(ref m); @@ -2576,13 +2572,9 @@ protected override void WndProc(ref Message m) { // Make sure tha we send our glyphs hit test messages over the TrayControls too Point pt = new Point((short)NativeMethods.Util.LOWORD(unchecked((int)(long)m.LParam)), (short)NativeMethods.Util.HIWORD(unchecked((int)(long)m.LParam))); - NativeMethods.POINT pt1 = new NativeMethods.POINT - { - x = 0, - y = 0 - }; - NativeMethods.MapWindowPoints(IntPtr.Zero, Handle, pt1, 1); - pt.Offset(pt1.x, pt1.y); + var pt1 = new Point(); + NativeMethods.MapWindowPoints(IntPtr.Zero, Handle, ref pt1, 1); + pt.Offset(pt1.X, pt1.Y); pt.Offset(Location.X, Location.Y);//offset the loc of the traycontrol -so now we're in comptray coords _tray.glyphManager.GetHitTest(pt); } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs index 6ce98371e56..fdb0a63c68f 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs @@ -284,15 +284,15 @@ internal virtual bool ControlSupportsSnaplines internal Point GetOffsetToClientArea() { - NativeMethods.POINT nativeOffset = new NativeMethods.POINT(0, 0); - NativeMethods.MapWindowPoints(Control.Handle, Control.Parent.Handle, nativeOffset, 1); + var nativeOffset = new Point(); + NativeMethods.MapWindowPoints(Control.Handle, Control.Parent.Handle, ref nativeOffset, 1); Point offset = Control.Location; // If the 2 controls do not have the same orientation, then force one to make sure we calculate the correct offset if (Control.IsMirrored != Control.Parent.IsMirrored) { offset.Offset(Control.Width, 0); } - return (new Point(Math.Abs(nativeOffset.x - offset.X), nativeOffset.y - offset.Y)); + return (new Point(Math.Abs(nativeOffset.X - offset.X), nativeOffset.Y - offset.Y)); } private bool IsResizableConsiderAutoSize(PropertyDescriptor autoSizeProp, PropertyDescriptor autoSizeModeProp) @@ -1743,14 +1743,14 @@ protected virtual void WndProc(ref Message m) if (m.Msg >= Interop.WindowMessages.WM_MOUSEFIRST && m.Msg <= Interop.WindowMessages.WM_MOUSELAST) { - NativeMethods.POINT pt = new NativeMethods.POINT + var pt = new Point { - x = NativeMethods.Util.SignedLOWORD(unchecked((int)(long)m.LParam)), - y = NativeMethods.Util.SignedHIWORD(unchecked((int)(long)m.LParam)) + X = NativeMethods.Util.SignedLOWORD(unchecked((int)(long)m.LParam)), + Y = NativeMethods.Util.SignedHIWORD(unchecked((int)(long)m.LParam)) }; - NativeMethods.MapWindowPoints(m.HWnd, IntPtr.Zero, pt, 1); - x = pt.x; - y = pt.y; + NativeMethods.MapWindowPoints(m.HWnd, IntPtr.Zero, ref pt, 1); + x = pt.X; + y = pt.Y; } else if (m.Msg >= Interop.WindowMessages.WM_NCMOUSEMOVE && m.Msg <= Interop.WindowMessages.WM_NCMBUTTONDBLCLK) { @@ -2059,13 +2059,9 @@ protected virtual void WndProc(ref Message m) if (m.HWnd != Control.Handle) { // Re-map the clip rect we pass to the paint event args to our child coordinates. - NativeMethods.POINT pt = new NativeMethods.POINT - { - x = 0, - y = 0 - }; - NativeMethods.MapWindowPoints(m.HWnd, Control.Handle, pt, 1); - gr.TranslateTransform(-pt.x, -pt.y); + var pt = new Point(); + NativeMethods.MapWindowPoints(m.HWnd, Control.Handle, ref pt, 1); + gr.TranslateTransform(-pt.X, -pt.Y); NativeMethods.MapWindowPoints(m.HWnd, Control.Handle, ref clip, 2); } paintRect = new Rectangle(clip.left, clip.top, clip.right - clip.left, clip.bottom - clip.top); diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripAdornerWindowService.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripAdornerWindowService.cs index 07052b75c83..3611d73a4ce 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripAdornerWindowService.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripAdornerWindowService.cs @@ -97,9 +97,8 @@ public void Dispose() /// public Point AdornerWindowPointToScreen(Point p) { - NativeMethods.POINT offset = new NativeMethods.POINT(p.X, p.Y); - NativeMethods.MapWindowPoints(_toolStripAdornerWindow.Handle, IntPtr.Zero, offset, 1); - return new Point(offset.x, offset.y); + NativeMethods.MapWindowPoints(_toolStripAdornerWindow.Handle, IntPtr.Zero, ref p, 1); + return p; } /// @@ -120,13 +119,10 @@ public Point ControlToAdornerWindow(Control c) { return Point.Empty; } - NativeMethods.POINT pt = new NativeMethods.POINT - { - x = c.Left, - y = c.Top - }; - NativeMethods.MapWindowPoints(c.Parent.Handle, _toolStripAdornerWindow.Handle, pt, 1); - return new Point(pt.x, pt.y); + + var pt = new Point(c.Left, c.Top); + NativeMethods.MapWindowPoints(c.Parent.Handle, _toolStripAdornerWindow.Handle, ref pt, 1); + return pt; } /// diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripDesigner.cs index b2eeb348e32..3d09e0d7f87 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripDesigner.cs @@ -1813,26 +1813,25 @@ protected override void OnDragDrop(DragEventArgs de) // There is a "drop region" before firstItem which is not included in the "ToolStrip Item glyhs" so if the drop point falls in this drop region we should insert the items at the head instead of the tail of the toolStrip. bool dropAtHead = false; ToolStrip parentToolStrip = ToolStrip; - NativeMethods.POINT offset = new NativeMethods.POINT(de.X, de.Y); - NativeMethods.MapWindowPoints(IntPtr.Zero, parentToolStrip.Handle, offset, 1); - Point dropPoint = new Point(offset.x, offset.y); + var offset = new Point(de.X, de.Y); + NativeMethods.MapWindowPoints(IntPtr.Zero, parentToolStrip.Handle, ref offset, 1); if (ToolStrip.Orientation == Orientation.Horizontal) { if (ToolStrip.RightToLeft == RightToLeft.Yes) { - if (dropPoint.X >= parentToolStrip.Items[0].Bounds.X) + if (offset.X >= parentToolStrip.Items[0].Bounds.X) { dropAtHead = true; } } - else if (dropPoint.X <= parentToolStrip.Items[0].Bounds.X) + else if (offset.X <= parentToolStrip.Items[0].Bounds.X) { dropAtHead = true; } } else { - if (dropPoint.Y <= parentToolStrip.Items[0].Bounds.Y) + if (offset.Y <= parentToolStrip.Items[0].Bounds.Y) { dropAtHead = true; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/AxHost.cs b/src/System.Windows.Forms/src/System/Windows/Forms/AxHost.cs index 4646af0377f..2202946e4a9 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/AxHost.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/AxHost.cs @@ -2043,10 +2043,8 @@ protected internal override bool ProcessMnemonic(char charCode) lParam = (IntPtr)0x20180001, time = SafeNativeMethods.GetTickCount() }; - NativeMethods.POINT p = new NativeMethods.POINT(); - UnsafeNativeMethods.GetCursorPos(p); - msg.pt_x = p.x; - msg.pt_y = p.y; + UnsafeNativeMethods.GetCursorPos(out Point p); + msg.pt = p; if (SafeNativeMethods.IsAccelerator(new HandleRef(ctlInfo, ctlInfo.hAccel), ctlInfo.cAccel, ref msg, null)) { GetOleControl().OnMnemonic(ref msg); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ContainerControl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ContainerControl.cs index b1d0248735c..b8c3b6d1ffd 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ContainerControl.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ContainerControl.cs @@ -687,11 +687,11 @@ internal override Rectangle GetToolNativeScreenRectangle() if (GetTopLevel()) { // Get window's client rectangle (i.e. without chrome) expressed in screen coordinates - Interop.RECT clientRectangle = new Interop.RECT(); + var clientRectangle = new Interop.RECT(); UnsafeNativeMethods.GetClientRect(new HandleRef(this, Handle), ref clientRectangle); - NativeMethods.POINT topLeftPoint = new NativeMethods.POINT(0, 0); - UnsafeNativeMethods.ClientToScreen(new HandleRef(this, Handle), topLeftPoint); - return new Rectangle(topLeftPoint.x, topLeftPoint.y, clientRectangle.right, clientRectangle.bottom); + var topLeftPoint = new Point(); + UnsafeNativeMethods.ClientToScreen(new HandleRef(this, Handle), ref topLeftPoint); + return new Rectangle(topLeftPoint.X, topLeftPoint.Y, clientRectangle.right, clientRectangle.bottom); } return base.GetToolNativeScreenRectangle(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.ActiveXImpl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.ActiveXImpl.cs index b256cf80e55..e4ad1c2db26 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.ActiveXImpl.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.ActiveXImpl.cs @@ -360,24 +360,24 @@ internal void DoVerb(int iVerb, IntPtr lpmsg, UnsafeNativeMethods.IOleClientSite { // Must translate message coordniates over to our HWND. We first try IntPtr hwndMap = msg.hwnd == IntPtr.Zero ? hwndParent : msg.hwnd; - NativeMethods.POINT pt = new NativeMethods.POINT + var pt = new Point { - x = NativeMethods.Util.LOWORD(msg.lParam), - y = NativeMethods.Util.HIWORD(msg.lParam) + X = NativeMethods.Util.LOWORD(msg.lParam), + Y = NativeMethods.Util.HIWORD(msg.lParam) }; - UnsafeNativeMethods.MapWindowPoints(new HandleRef(null, hwndMap), new HandleRef(_control, _control.Handle), pt, 1); + UnsafeNativeMethods.MapWindowPoints(new HandleRef(null, hwndMap), new HandleRef(_control, _control.Handle), ref pt, 1); // check to see if this message should really go to a child // control, and if so, map the point into that child's window // coordinates - Control realTarget = target.GetChildAtPoint(new Point(pt.x, pt.y)); + Control realTarget = target.GetChildAtPoint(pt); if (realTarget != null && realTarget != target) { - UnsafeNativeMethods.MapWindowPoints(new HandleRef(target, target.Handle), new HandleRef(realTarget, realTarget.Handle), pt, 1); + UnsafeNativeMethods.MapWindowPoints(new HandleRef(target, target.Handle), new HandleRef(realTarget, realTarget.Handle), ref pt, 1); target = realTarget; } - msg.lParam = NativeMethods.Util.MAKELPARAM(pt.x, pt.y); + msg.lParam = NativeMethods.Util.MAKELPARAM(pt.X, pt.Y); } #if DEBUG @@ -421,7 +421,7 @@ internal void DoVerb(int iVerb, IntPtr lpmsg, UnsafeNativeMethods.IOleClientSite /// /// Implements IViewObject2::Draw. /// - internal void Draw(int dwDrawAspect, int lindex, IntPtr pvAspect, NativeMethods.tagDVTARGETDEVICE ptd, + internal unsafe void Draw(int dwDrawAspect, int lindex, IntPtr pvAspect, NativeMethods.tagDVTARGETDEVICE ptd, IntPtr hdcTargetDev, IntPtr hdcDraw, NativeMethods.COMRECT prcBounds, NativeMethods.COMRECT lprcWBounds, IntPtr pfnContinue, int dwContinue) { @@ -450,8 +450,8 @@ internal void Draw(int dwDrawAspect, int lindex, IntPtr pvAspect, NativeMethods. } Interop.RECT rc; - NativeMethods.POINT pVp = new NativeMethods.POINT(); - NativeMethods.POINT pW = new NativeMethods.POINT(); + var pVp = new Point(); + var pW = new Point(); NativeMethods.SIZE sWindowExt = new NativeMethods.SIZE(); NativeMethods.SIZE sViewportExt = new NativeMethods.SIZE(); int iMode = NativeMethods.MM_TEXT; @@ -475,9 +475,9 @@ internal void Draw(int dwDrawAspect, int lindex, IntPtr pvAspect, NativeMethods. SafeNativeMethods.LPtoDP(new HandleRef(null, hdcDraw), ref rc, 2); iMode = SafeNativeMethods.SetMapMode(new HandleRef(null, hdcDraw), NativeMethods.MM_ANISOTROPIC); - SafeNativeMethods.SetWindowOrgEx(new HandleRef(null, hdcDraw), 0, 0, pW); + SafeNativeMethods.SetWindowOrgEx(hdcDraw, 0, 0, &pW); SafeNativeMethods.SetWindowExtEx(new HandleRef(null, hdcDraw), _control.Width, _control.Height, sWindowExt); - SafeNativeMethods.SetViewportOrgEx(new HandleRef(null, hdcDraw), rc.left, rc.top, pVp); + SafeNativeMethods.SetViewportOrgEx(hdcDraw, rc.left, rc.top, &pVp); SafeNativeMethods.SetViewportExtEx(new HandleRef(null, hdcDraw), rc.right - rc.left, rc.bottom - rc.top, sViewportExt); } @@ -503,9 +503,9 @@ internal void Draw(int dwDrawAspect, int lindex, IntPtr pvAspect, NativeMethods. // And clean up the DC if (prcBounds != null) { - SafeNativeMethods.SetWindowOrgEx(new HandleRef(null, hdcDraw), pW.x, pW.y, null); + SafeNativeMethods.SetWindowOrgEx(hdcDraw, pW.X, pW.Y, null); SafeNativeMethods.SetWindowExtEx(new HandleRef(null, hdcDraw), sWindowExt.cx, sWindowExt.cy, null); - SafeNativeMethods.SetViewportOrgEx(new HandleRef(null, hdcDraw), pVp.x, pVp.y, null); + SafeNativeMethods.SetViewportOrgEx(hdcDraw, pVp.X, pVp.Y, null); SafeNativeMethods.SetViewportExtEx(new HandleRef(null, hdcDraw), sViewportExt.cx, sViewportExt.cy, null); SafeNativeMethods.SetMapMode(new HandleRef(null, hdcDraw), iMode); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs index 7ab445aa5a9..f34afc2b070 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs @@ -1896,12 +1896,11 @@ public virtual Cursor Cursor { // We want to instantly change the cursor if the mouse is within our bounds. // This includes the case where the mouse is over one of our children - NativeMethods.POINT p = new NativeMethods.POINT(); - Interop.RECT r = new Interop.RECT(); - UnsafeNativeMethods.GetCursorPos(p); + var r = new Interop.RECT(); + UnsafeNativeMethods.GetCursorPos(out Point p); UnsafeNativeMethods.GetWindowRect(new HandleRef(this, Handle), ref r); - if ((r.left <= p.x && p.x < r.right && r.top <= p.y && p.y < r.bottom) || UnsafeNativeMethods.GetCapture() == Handle) + if ((r.left <= p.X && p.X < r.right && r.top <= p.Y && p.Y < r.bottom) || UnsafeNativeMethods.GetCapture() == Handle) { SendMessage(Interop.WindowMessages.WM_SETCURSOR, Handle, (IntPtr)NativeMethods.HTCLIENT); } @@ -3132,9 +3131,8 @@ public static Point MousePosition { get { - var pt = new NativeMethods.POINT(); - UnsafeNativeMethods.GetCursorPos(pt); - return new Point(pt.x, pt.y); + UnsafeNativeMethods.GetCursorPos(out Point pt); + return pt; } } @@ -9233,9 +9231,8 @@ internal bool PerformContainerValidation(ValidationConstraints validationConstra /// public Point PointToClient(Point p) { - var point = new NativeMethods.POINT(p.X, p.Y); - UnsafeNativeMethods.MapWindowPoints(NativeMethods.NullHandleRef, new HandleRef(this, Handle), point, 1); - return new Point(point.x, point.y); + UnsafeNativeMethods.MapWindowPoints(NativeMethods.NullHandleRef, new HandleRef(this, Handle), ref p, 1); + return p; } /// @@ -9243,9 +9240,8 @@ public Point PointToClient(Point p) /// public Point PointToScreen(Point p) { - NativeMethods.POINT point = new NativeMethods.POINT(p.X, p.Y); - UnsafeNativeMethods.MapWindowPoints(new HandleRef(this, Handle), NativeMethods.NullHandleRef, point, 1); - return new Point(point.x, point.y); + UnsafeNativeMethods.MapWindowPoints(new HandleRef(this, Handle), NativeMethods.NullHandleRef, ref p, 1); + return p; } /// @@ -9469,11 +9465,10 @@ private void PrintToMetaFile(HandleRef hDC, IntPtr lParam) // We're the root contol, so we need to set up our clipping region. Retrieve the // x-coordinates and y-coordinates of the viewport origin for the specified device context. - NativeMethods.POINT viewportOrg = new NativeMethods.POINT(); - bool success = SafeNativeMethods.GetViewportOrgEx(hDC, viewportOrg); + bool success = SafeNativeMethods.GetViewportOrgEx(hDC, out Point viewportOrg); Debug.Assert(success, "GetViewportOrgEx() failed."); - IntPtr hClippingRegion = Interop.Gdi32.CreateRectRgn(viewportOrg.x, viewportOrg.y, viewportOrg.x + Width, viewportOrg.y + Height); + IntPtr hClippingRegion = Interop.Gdi32.CreateRectRgn(viewportOrg.X, viewportOrg.Y, viewportOrg.X + Width, viewportOrg.Y + Height); Debug.Assert(hClippingRegion != IntPtr.Zero, "CreateRectRgn() failed."); try @@ -12326,7 +12321,7 @@ private void WmHelp(ref Message m) // Note: info.hItemHandle is the handle of the window that sent the help message. NativeMethods.HELPINFO info = (NativeMethods.HELPINFO)m.GetLParam(typeof(NativeMethods.HELPINFO)); - HelpEventArgs hevent = new HelpEventArgs(new Point(info.MousePos.x, info.MousePos.y)); + HelpEventArgs hevent = new HelpEventArgs(info.MousePos); OnHelpRequested(hevent); if (!hevent.Handled) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ControlPaint.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ControlPaint.cs index dc005cee5f3..4fb1099fe50 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ControlPaint.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ControlPaint.cs @@ -2015,7 +2015,7 @@ public static void DrawReversibleFrame(Rectangle rectangle, Color backColor, Fra /// Draws a reversible line on the screen. A reversible line can /// be erased by just drawing over it again. /// - public static void DrawReversibleLine(Point start, Point end, Color backColor) + public static unsafe void DrawReversibleLine(Point start, Point end, Color backColor) { int rop2 = GetColorRop(backColor, 0xA, // RasterOp.PEN.Invert().XorWith(RasterOp.TARGET), diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Cursor.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Cursor.cs index 7e35e5db02b..9d11be4016c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Cursor.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Cursor.cs @@ -234,14 +234,10 @@ public static Point Position { get { - NativeMethods.POINT p = new NativeMethods.POINT(); - UnsafeNativeMethods.GetCursorPos(p); - return new Point(p.x, p.y); - } - set - { - UnsafeNativeMethods.SetCursorPos(value.X, value.Y); + UnsafeNativeMethods.GetCursorPos(out Point p); + return p; } + set => UnsafeNativeMethods.SetCursorPos(value.X, value.Y); } /// diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Form.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Form.cs index ec159b4729a..c694c0967ef 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Form.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Form.cs @@ -4601,14 +4601,11 @@ protected override void OnVisibleChanged(EventArgs e) { Control button = AcceptButton as Control; - NativeMethods.POINT ptToSnap = new NativeMethods.POINT( - button.Left + button.Width / 2, - button.Top + button.Height / 2); - - UnsafeNativeMethods.ClientToScreen(new HandleRef(this, Handle), ptToSnap); + var ptToSnap = new Point(button.Left + button.Width / 2, button.Top + button.Height / 2); + UnsafeNativeMethods.ClientToScreen(new HandleRef(this, Handle), ref ptToSnap); if (!button.IsWindowObscured) { - Cursor.Position = new Point(ptToSnap.x, ptToSnap.y); + Cursor.Position = ptToSnap; } } } @@ -6843,8 +6840,8 @@ private void WmGetMinMaxInfoHelper(ref Message m, Size minTrack, Size maxTrack, if (!minTrack.IsEmpty) { - mmi.ptMinTrackSize.x = minTrack.Width; - mmi.ptMinTrackSize.y = minTrack.Height; + mmi.ptMinTrackSize.X = minTrack.Width; + mmi.ptMinTrackSize.Y = minTrack.Height; // When the MinTrackSize is set to a value larger than the screen // size but the MaxTrackSize is not set to a value equal to or greater than the @@ -6861,11 +6858,11 @@ private void WmGetMinMaxInfoHelper(ref Message m, Size minTrack, Size maxTrack, Size virtualScreen = SystemInformation.VirtualScreen.Size; if (minTrack.Height > virtualScreen.Height) { - mmi.ptMaxTrackSize.y = int.MaxValue; + mmi.ptMaxTrackSize.Y = int.MaxValue; } if (minTrack.Width > virtualScreen.Width) { - mmi.ptMaxTrackSize.x = int.MaxValue; + mmi.ptMaxTrackSize.X = int.MaxValue; } } } @@ -6874,16 +6871,16 @@ private void WmGetMinMaxInfoHelper(ref Message m, Size minTrack, Size maxTrack, { // Is the specified MaxTrackSize smaller than the smallest allowable Window size? Size minTrackWindowSize = SystemInformation.MinWindowTrackSize; - mmi.ptMaxTrackSize.x = Math.Max(maxTrack.Width, minTrackWindowSize.Width); - mmi.ptMaxTrackSize.y = Math.Max(maxTrack.Height, minTrackWindowSize.Height); + mmi.ptMaxTrackSize.X = Math.Max(maxTrack.Width, minTrackWindowSize.Width); + mmi.ptMaxTrackSize.Y = Math.Max(maxTrack.Height, minTrackWindowSize.Height); } if (!maximizedBounds.IsEmpty) { - mmi.ptMaxPosition.x = maximizedBounds.X; - mmi.ptMaxPosition.y = maximizedBounds.Y; - mmi.ptMaxSize.x = maximizedBounds.Width; - mmi.ptMaxSize.y = maximizedBounds.Height; + mmi.ptMaxPosition.X = maximizedBounds.X; + mmi.ptMaxPosition.Y = maximizedBounds.Y; + mmi.ptMaxSize.X = maximizedBounds.Width; + mmi.ptMaxSize.Y = maximizedBounds.Height; } Marshal.StructureToPtr(mmi, m.LParam, false); @@ -7038,9 +7035,8 @@ private void WmNCHitTest(ref Message m) int y = NativeMethods.Util.HIWORD(m.LParam); // Convert to client coordinates - // - NativeMethods.POINT pt = new NativeMethods.POINT(x, y); - UnsafeNativeMethods.ScreenToClient(new HandleRef(this, Handle), pt); + var pt = new Point(x, y); + UnsafeNativeMethods.ScreenToClient(new HandleRef(this, Handle), ref pt); Size clientSize = ClientSize; @@ -7048,8 +7044,8 @@ private void WmNCHitTest(ref Message m) // the grip area in this case not to get in the way of the control box. We only need to check for the client's // height since the window width will be at least the size of the control box which is always bigger than the // grip width. - if (pt.x >= (clientSize.Width - SizeGripSize) && - pt.y >= (clientSize.Height - SizeGripSize) && + if (pt.X >= (clientSize.Width - SizeGripSize) && + pt.Y >= (clientSize.Height - SizeGripSize) && clientSize.Height >= SizeGripSize) { m.Result = IsMirrored ? (IntPtr)NativeMethods.HTBOTTOMLEFT : (IntPtr)NativeMethods.HTBOTTOMRIGHT; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Help.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Help.cs index e61f804b034..6fd3511004e 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Help.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Help.cs @@ -143,7 +143,7 @@ public static void ShowPopup(Control parent, string caption, Point location) { pop.pszText = pszText; pop.idString = 0; - pop.pt = new NativeMethods.POINT(location.X, location.Y); + pop.pt = location; // Looks like a windows diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/LinkLabel.cs b/src/System.Windows.Forms/src/System/Windows/Forms/LinkLabel.cs index 4710dd5e3e9..c0aa301ddb5 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/LinkLabel.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/LinkLabel.cs @@ -419,13 +419,10 @@ protected Cursor OverrideCursor { // We want to instantly change the cursor if the mouse is within our bounds. // This includes the case where the mouse is over one of our children - NativeMethods.POINT p = new NativeMethods.POINT(); - Interop.RECT r = new Interop.RECT(); - UnsafeNativeMethods.GetCursorPos(p); + var r = new Interop.RECT(); + UnsafeNativeMethods.GetCursorPos(out Point p); UnsafeNativeMethods.GetWindowRect(new HandleRef(this, Handle), ref r); - - // - if ((r.left <= p.x && p.x < r.right && r.top <= p.y && p.y < r.bottom) || UnsafeNativeMethods.GetCapture() == Handle) + if ((r.left <= p.X && p.X < r.right && r.top <= p.Y && p.Y < r.bottom) || UnsafeNativeMethods.GetCapture() == Handle) { SendMessage(Interop.WindowMessages.WM_SETCURSOR, Handle, NativeMethods.HTCLIENT); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs index 628240d9e53..c6c41eb005d 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs @@ -3302,8 +3302,7 @@ private ListViewItem FindItem(bool isTextSearch, string text, bool isPrefixSearc else { lvFindInfo.flags = NativeMethods.LVFI_NEARESTXY; - lvFindInfo.ptX = pt.X; - lvFindInfo.ptY = pt.Y; + lvFindInfo.pt = pt; // we can do this because SearchDirectionHint is set to the VK_* lvFindInfo.vkDirection = (int)dir; } @@ -3548,10 +3547,9 @@ internal void GetSubItemAt(int x, int y, out int iItem, out int iSubItem) internal Point GetItemPosition(int index) { - NativeMethods.POINT pt = new NativeMethods.POINT(); - UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.LVM_GETITEMPOSITION, index, pt); - - return new Point(pt.x, pt.y); + var pt = new Point(); + UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.LVM_GETITEMPOSITION, index, ref pt); + return pt; } internal int GetItemState(int index) @@ -5391,12 +5389,8 @@ internal void SetItemPosition(int index, int x, int y) Debug.Assert(IsHandleCreated, "How did we add items without a handle?"); - NativeMethods.POINT pt = new NativeMethods.POINT - { - x = x, - y = y - }; - UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.LVM_SETITEMPOSITION32, index, pt); + var pt = new Point(x, y); + UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.LVM_SETITEMPOSITION32, index, ref pt); } internal void SetItemState(int index, int state, int mask) @@ -6587,7 +6581,7 @@ private unsafe void WmReflectNotify(ref Message m) Point startingPoint = Point.Empty; if ((nmlvif.lvfi.flags & NativeMethods.LVFI_NEARESTXY) != 0) { - startingPoint = new Point(nmlvif.lvfi.ptX, nmlvif.lvfi.ptY); + startingPoint = nmlvif.lvfi.pt; } SearchDirectionHint dir = SearchDirectionHint.Down; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ListViewInsertionMark.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ListViewInsertionMark.cs index 54e50d12e0c..6eb1865cb79 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ListViewInsertionMark.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ListViewInsertionMark.cs @@ -121,15 +121,8 @@ public int Index /// public int NearestIndex(Point pt) { - NativeMethods.POINT point = new NativeMethods.POINT - { - x = pt.X, - y = pt.Y - }; - NativeMethods.LVINSERTMARK lvInsertMark = new NativeMethods.LVINSERTMARK(); - UnsafeNativeMethods.SendMessage(new HandleRef(listView, listView.Handle), NativeMethods.LVM_INSERTMARKHITTEST, point, lvInsertMark); - + UnsafeNativeMethods.SendMessage(new HandleRef(listView, listView.Handle), NativeMethods.LVM_INSERTMARKHITTEST, ref pt, lvInsertMark); return lvInsertMark.iItem; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/MDIClient.cs b/src/System.Windows.Forms/src/System/Windows/Forms/MDIClient.cs index d8354b54080..ecd1078e941 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/MDIClient.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/MDIClient.cs @@ -242,16 +242,16 @@ protected override void SetBoundsCore(int x, int y, int width, int height, Bound if (child.CanRecreateHandle() && child.WindowState == FormWindowState.Minimized) { UnsafeNativeMethods.GetWindowPlacement(new HandleRef(child, child.Handle), ref wp); - wp.ptMinPosition_y -= yDelta; - if (wp.ptMinPosition_y == -1) + wp.ptMinPosition.Y -= yDelta; + if (wp.ptMinPosition.Y == -1) { if (yDelta < 0) { - wp.ptMinPosition_y = 0; + wp.ptMinPosition.Y = 0; } else { - wp.ptMinPosition_y = -2; + wp.ptMinPosition.Y = -2; } } wp.flags = NativeMethods.WPF_SETMINPOSITION; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/NotifyIcon.cs b/src/System.Windows.Forms/src/System/Windows/Forms/NotifyIcon.cs index a719e06254f..7038e5b7e8e 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/NotifyIcon.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/NotifyIcon.cs @@ -644,8 +644,7 @@ private void ShowContextMenu() { if (contextMenu != null || contextMenuStrip != null) { - NativeMethods.POINT pt = new NativeMethods.POINT(); - UnsafeNativeMethods.GetCursorPos(pt); + UnsafeNativeMethods.GetCursorPos(out Point pt); // Summary: the current window must be made the foreground window // before calling TrackPopupMenuEx, and a task switch must be @@ -658,8 +657,8 @@ private void ShowContextMenu() SafeNativeMethods.TrackPopupMenuEx(new HandleRef(contextMenu, contextMenu.Handle), NativeMethods.TPM_VERTICAL | NativeMethods.TPM_RIGHTALIGN, - pt.x, - pt.y, + pt.X, + pt.Y, new HandleRef(window, window.Handle), null); @@ -670,7 +669,7 @@ private void ShowContextMenu() { // this will set the context menu strip to be toplevel // and will allow us to overlap the system tray - contextMenuStrip.ShowInTaskbar(pt.x, pt.y); + contextMenuStrip.ShowInTaskbar(pt.X, pt.Y); } } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGrid.cs b/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGrid.cs index 13609a28803..85a51d3f9c2 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGrid.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGrid.cs @@ -4933,18 +4933,14 @@ private bool ShouldForwardChildMouseMessage(Control child, MouseEventArgs me, re if (me.Y <= 1 || (size.Height - me.Y) <= 1) { // convert the coordinates to - NativeMethods.POINT temp = new NativeMethods.POINT - { - x = me.X, - y = me.Y - }; - UnsafeNativeMethods.MapWindowPoints(new HandleRef(child, child.Handle), new HandleRef(this, Handle), temp, 1); + var temp = new Point(me.X, me.Y); + UnsafeNativeMethods.MapWindowPoints(new HandleRef(child, child.Handle), new HandleRef(this, Handle), ref temp, 1); // forward the message - pt.X = temp.x; - pt.Y = temp.y; + pt = temp; return true; } + return false; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGridInternal/PropertyGridView.cs b/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGridInternal/PropertyGridView.cs index 25828ad151d..0149bb9e95f 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGridInternal/PropertyGridView.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGridInternal/PropertyGridView.cs @@ -870,25 +870,24 @@ internal Rectangle AccessibilityGetGridEntryBounds(GridEntry gridEntry) Rectangle rect = GetRectangle(row, ROWVALUE | ROWLABEL); // Translate rect to screen coordinates - // - NativeMethods.POINT pt = new NativeMethods.POINT(rect.X, rect.Y); - UnsafeNativeMethods.ClientToScreen(new HandleRef(this, Handle), pt); + var pt = new Point(rect.X, rect.Y); + UnsafeNativeMethods.ClientToScreen(new HandleRef(this, Handle), ref pt); Rectangle parent = gridEntry.OwnerGrid.GridViewAccessibleObject.Bounds; int propertyGridViewBottom = parent.Bottom - 1; // - 1 is PropertyGridView bottom border - if (pt.y > propertyGridViewBottom) + if (pt.Y > propertyGridViewBottom) { return Rectangle.Empty; } - if (pt.y + rect.Height > propertyGridViewBottom) + if (pt.Y + rect.Height > propertyGridViewBottom) { - rect.Height = propertyGridViewBottom - pt.y; + rect.Height = propertyGridViewBottom - pt.Y; } - return new Rectangle(pt.x, pt.y, rect.Width, rect.Height); + return new Rectangle(pt.X, pt.Y, rect.Width, rect.Height); } internal int AccessibilityGetGridEntryChildID(GridEntry gridEntry) @@ -8194,7 +8193,7 @@ private IntPtr MouseHookProc(int nCode, IntPtr wparam, IntPtr lparam) case Interop.WindowMessages.WM_NCMBUTTONDOWN: case Interop.WindowMessages.WM_NCRBUTTONDOWN: case Interop.WindowMessages.WM_MOUSEACTIVATE: - if (ProcessMouseDown(mhs.hWnd, mhs.pt_x, mhs.pt_y)) + if (ProcessMouseDown(mhs.hWnd, mhs.pt.X, mhs.pt.Y)) { return (IntPtr)1; } @@ -8808,15 +8807,13 @@ public override AccessibleObject GetSelected() /// public override AccessibleObject HitTest(int x, int y) { - // Convert to client coordinates - // - NativeMethods.POINT pt = new NativeMethods.POINT(x, y); - UnsafeNativeMethods.ScreenToClient(new HandleRef(Owner, Owner.Handle), pt); + var pt = new Point(x, y); + UnsafeNativeMethods.ScreenToClient(new HandleRef(Owner, Owner.Handle), ref pt); // Find the grid entry at the given client coordinates // - Point pos = ((PropertyGridView)Owner).FindPosition(pt.x, pt.y); + Point pos = ((PropertyGridView)Owner).FindPosition(pt.X, pt.Y); if (pos != PropertyGridView.InvalidPosition) { GridEntry gridEntry = ((PropertyGridView)Owner).GetGridEntryFromRow(pos.Y); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/RichTextBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/RichTextBox.cs index a746ffdbd4b..71de1e51f27 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/RichTextBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/RichTextBox.cs @@ -2462,8 +2462,8 @@ Font GetCharFormatFont(bool selectionOnly) /// public override int GetCharIndexFromPosition(Point pt) { - NativeMethods.POINT wpt = new NativeMethods.POINT(pt.X, pt.Y); - int index = (int)UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), Interop.EditMessages.EM_CHARFROMPOS, 0, wpt); + var wpt = new Point(pt.X, pt.Y); + int index = (int)UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), Interop.EditMessages.EM_CHARFROMPOS, 0, ref wpt); string t = Text; // EM_CHARFROMPOS will return an invalid number if the last character in the RichEdit @@ -2518,9 +2518,9 @@ public override Point GetPositionFromCharIndex(int index) return Point.Empty; } - NativeMethods.POINT pt = new NativeMethods.POINT(); - UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), Interop.EditMessages.EM_POSFROMCHAR, pt, index); - return new Point(pt.x, pt.y); + var pt = new Point(); + UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), Interop.EditMessages.EM_POSFROMCHAR, ref pt, index); + return pt; } private bool GetProtectedError() diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/SplitContainer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/SplitContainer.cs index 5684d30a1c8..b8291867f7b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/SplitContainer.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/SplitContainer.cs @@ -584,11 +584,10 @@ private Cursor OverrideCursor if (IsHandleCreated) { // We want to instantly change the cursor if the mouse is within our bounds. - NativeMethods.POINT p = new NativeMethods.POINT(); - Interop.RECT r = new Interop.RECT(); - UnsafeNativeMethods.GetCursorPos(p); + var r = new Interop.RECT(); + UnsafeNativeMethods.GetCursorPos(out Point p); UnsafeNativeMethods.GetWindowRect(new HandleRef(this, Handle), ref r); - if ((r.left <= p.x && p.x < r.right && r.top <= p.y && p.y < r.bottom) || UnsafeNativeMethods.GetCapture() == Handle) + if ((r.left <= p.X && p.X < r.right && r.top <= p.Y && p.Y < r.bottom) || UnsafeNativeMethods.GetCapture() == Handle) { SendMessage(Interop.WindowMessages.WM_SETCURSOR, Handle, NativeMethods.HTCLIENT); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/StatusStrip.cs b/src/System.Windows.Forms/src/System/Windows/Forms/StatusStrip.cs index e3751085aae..748b971025c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/StatusStrip.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/StatusStrip.cs @@ -634,19 +634,19 @@ protected override void WndProc(ref Message m) UnsafeNativeMethods.GetClientRect(rootHwnd, ref rootHwndClientArea); // map the size grip FROM statusStrip coords TO the toplevel window coords. - NativeMethods.POINT gripLocation; + Point gripLocation; if (RightToLeft == RightToLeft.Yes) { - gripLocation = new NativeMethods.POINT(SizeGripBounds.Left, SizeGripBounds.Bottom); + gripLocation = new Point(SizeGripBounds.Left, SizeGripBounds.Bottom); } else { - gripLocation = new NativeMethods.POINT(SizeGripBounds.Right, SizeGripBounds.Bottom); + gripLocation = new Point(SizeGripBounds.Right, SizeGripBounds.Bottom); } - UnsafeNativeMethods.MapWindowPoints(new HandleRef(this, Handle), rootHwnd, gripLocation, 1); + UnsafeNativeMethods.MapWindowPoints(new HandleRef(this, Handle), rootHwnd, ref gripLocation, 1); - int deltaBottomEdge = Math.Abs(rootHwndClientArea.bottom - gripLocation.y); - int deltaRightEdge = Math.Abs(rootHwndClientArea.right - gripLocation.x); + int deltaBottomEdge = Math.Abs(rootHwndClientArea.bottom - gripLocation.Y); + int deltaRightEdge = Math.Abs(rootHwndClientArea.right - gripLocation.X); if (RightToLeft != RightToLeft.Yes) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ToolBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ToolBar.cs index 1eb60f30f60..e3c06195469 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ToolBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ToolBar.cs @@ -1770,31 +1770,31 @@ protected override void WndProc(ref Message m) // We'll need screen coordinates of this position for setting the tooltip's position int x = Location.X + buttonRight + 1; int y = Location.Y + (ButtonSize.Height / 2); - NativeMethods.POINT leftTop = new NativeMethods.POINT(x, y); - UnsafeNativeMethods.ClientToScreen(new HandleRef(this, Handle), leftTop); + var leftTop = new Point(x, y); + UnsafeNativeMethods.ClientToScreen(new HandleRef(this, Handle), ref leftTop); // Will the tooltip bleed off the top? - if (leftTop.y < SystemInformation.WorkingArea.Y) + if (leftTop.Y < SystemInformation.WorkingArea.Y) { // Reposition the tooltip to be displayed below the button - leftTop.y += (ButtonSize.Height / 2) + 1; + leftTop.Y += (ButtonSize.Height / 2) + 1; } // Will the tooltip bleed off the bottom? - if (leftTop.y + tooltipHeight > SystemInformation.WorkingArea.Height) + if (leftTop.Y + tooltipHeight > SystemInformation.WorkingArea.Height) { // Reposition the tooltip to be displayed above the button - leftTop.y -= ((ButtonSize.Height / 2) + tooltipHeight + 1); + leftTop.Y -= ((ButtonSize.Height / 2) + tooltipHeight + 1); } // Will the tooltip bleed off the right edge? - if (leftTop.x + tooltipWidth > SystemInformation.WorkingArea.Right) + if (leftTop.X + tooltipWidth > SystemInformation.WorkingArea.Right) { // Move the tooltip far enough left that it will display in the working area - leftTop.x -= (ButtonSize.Width + tooltipWidth + 2); + leftTop.X -= (ButtonSize.Width + tooltipWidth + 2); } - SafeNativeMethods.SetWindowPos(new HandleRef(null, note.hwndFrom), NativeMethods.NullHandleRef, leftTop.x, leftTop.y, 0, 0, NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOACTIVATE); + SafeNativeMethods.SetWindowPos(new HandleRef(null, note.hwndFrom), NativeMethods.NullHandleRef, leftTop.X, leftTop.Y, 0, 0, NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOACTIVATE); m.Result = (IntPtr)1; return; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripManager.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripManager.cs index 197ccc043cb..bad29683014 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripManager.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ToolStripManager.cs @@ -1169,13 +1169,9 @@ private void ProcessMouseButtonPressed(IntPtr hwndMouseMessageIsFrom, int x, int if (activeToolStrip != null) { - NativeMethods.POINT pt = new NativeMethods.POINT - { - x = x, - y = y - }; - UnsafeNativeMethods.MapWindowPoints(new HandleRef(activeToolStrip, hwndMouseMessageIsFrom), new HandleRef(activeToolStrip, activeToolStrip.Handle), pt, 1); - if (!activeToolStrip.ClientRectangle.Contains(pt.x, pt.y)) + var pt = new Point(x, y); + UnsafeNativeMethods.MapWindowPoints(new HandleRef(activeToolStrip, hwndMouseMessageIsFrom), new HandleRef(activeToolStrip, activeToolStrip.Handle), ref pt, 1); + if (!activeToolStrip.ClientRectangle.Contains(pt.X, pt.Y)) { if (activeToolStrip is ToolStripDropDown activeToolStripDropDown) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ToolTip.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ToolTip.cs index d25b7a1caa8..67aa8096816 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ToolTip.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ToolTip.cs @@ -2138,10 +2138,9 @@ private void WmMouseActivate(ref Message msg) /// private void WmWindowFromPoint(ref Message msg) { - NativeMethods.POINT sc = (NativeMethods.POINT)msg.GetLParam(typeof(NativeMethods.POINT)); - Point screenCoords = new Point(sc.x, sc.y); + var sc = (Point)msg.GetLParam(typeof(Point)); bool result = false; - msg.Result = GetWindowFromPoint(screenCoords, ref result); + msg.Result = GetWindowFromPoint(sc, ref result); } /// diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs index a547ac52b2e..b8d2c9e31f5 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs @@ -3159,9 +3159,7 @@ private void ShowContextMenu(TreeNode treeNode) if (contextMenu != null) { - - NativeMethods.POINT pt = new NativeMethods.POINT(); - UnsafeNativeMethods.GetCursorPos(pt); + UnsafeNativeMethods.GetCursorPos(out Point pt); // Summary: the current window must be made the foreground window // before calling TrackPopupMenuEx, and a task switch must be @@ -3173,8 +3171,8 @@ private void ShowContextMenu(TreeNode treeNode) SafeNativeMethods.TrackPopupMenuEx(new HandleRef(contextMenu, contextMenu.Handle), NativeMethods.TPM_VERTICAL, - pt.x, - pt.y, + pt.X, + pt.Y, new HandleRef(this, Handle), null); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/UpDownBase.cs b/src/System.Windows.Forms/src/System/Windows/Forms/UpDownBase.cs index e00a923095d..90334d5f8b6 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/UpDownBase.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/UpDownBase.cs @@ -1129,9 +1129,9 @@ private MouseEventArgs TranslateMouseEvent(Control child, MouseEventArgs e) { // same control as PointToClient or PointToScreen, just // with two specific controls in mind. - NativeMethods.POINT point = new NativeMethods.POINT(e.X, e.Y); - UnsafeNativeMethods.MapWindowPoints(new HandleRef(child, child.Handle), new HandleRef(this, Handle), point, 1); - return new MouseEventArgs(e.Button, e.Clicks, point.x, point.y, e.Delta); + var point = new Point(e.X, e.Y); + UnsafeNativeMethods.MapWindowPoints(new HandleRef(child, child.Handle), new HandleRef(this, Handle), ref point, 1); + return new MouseEventArgs(e.Button, e.Clicks, point.X, point.Y, e.Delta); } return e; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/VisualStyles/VisualStyleRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/VisualStyles/VisualStyleRenderer.cs index 3696d3ff6c0..a2463e520e2 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/VisualStyles/VisualStyleRenderer.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/VisualStyles/VisualStyleRenderer.cs @@ -813,9 +813,8 @@ public Point GetPoint(PointProperty prop) throw new InvalidEnumArgumentException(nameof(prop), (int)prop, typeof(PointProperty)); } - NativeMethods.POINT point = new NativeMethods.POINT(); - lastHResult = SafeNativeMethods.GetThemePosition(new HandleRef(this, Handle), part, state, (int)prop, point); - return new Point(point.x, point.y); + lastHResult = SafeNativeMethods.GetThemePosition(new HandleRef(this, Handle), part, state, (int)prop, out Point point); + return point; } /// diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/WebBrowser.cs b/src/System.Windows.Forms/src/System/Windows/Forms/WebBrowser.cs index fbf9e3b5fe4..144528c25b3 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/WebBrowser.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/WebBrowser.cs @@ -1528,7 +1528,7 @@ public WebBrowserSite(WebBrowser host) : base(host) // // IDocHostUIHandler Implementation // - int UnsafeNativeMethods.IDocHostUIHandler.ShowContextMenu(int dwID, NativeMethods.POINT pt, object pcmdtReserved, object pdispReserved) + int UnsafeNativeMethods.IDocHostUIHandler.ShowContextMenu(uint dwID, ref Point pt, object pcmdtReserved, object pdispReserved) { WebBrowser wb = (WebBrowser)Host; @@ -1539,14 +1539,14 @@ int UnsafeNativeMethods.IDocHostUIHandler.ShowContextMenu(int dwID, NativeMethod } else { - if (pt.x == 0 && pt.y == 0) + if (pt.X == 0 && pt.Y == 0) { // IDocHostUIHandler::ShowContextMenu sends (0,0) when the context menu is invoked via the keyboard // make it (-1, -1) for the WebBrowser::ShowContextMenu method - pt.x = -1; - pt.y = -1; + pt.X = -1; + pt.Y = -1; } - wb.ShowContextMenu(pt.x, pt.y); + wb.ShowContextMenu(pt.X, pt.Y); // MSHTML should not display its context menu because we displayed ours return NativeMethods.S_OK; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/WebBrowserBase.cs b/src/System.Windows.Forms/src/System/Windows/Forms/WebBrowserBase.cs index 5602ff15868..f2c56d59643 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/WebBrowserBase.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/WebBrowserBase.cs @@ -351,10 +351,9 @@ protected internal override bool ProcessMnemonic(char charCode) lParam = (IntPtr)0x20180001, time = SafeNativeMethods.GetTickCount() }; - NativeMethods.POINT p = new NativeMethods.POINT(); - UnsafeNativeMethods.GetCursorPos(p); - msg.pt_x = p.x; - msg.pt_y = p.y; + + UnsafeNativeMethods.GetCursorPos(out Point p); + msg.pt = p; if (SafeNativeMethods.IsAccelerator(new HandleRef(ctlInfo, ctlInfo.hAccel), ctlInfo.cAccel, ref msg, null)) { axOleControl.OnMnemonic(ref msg); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/WinFormsUtils.cs b/src/System.Windows.Forms/src/System/Windows/Forms/WinFormsUtils.cs index c69791682fa..8fa02b4d6d0 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/WinFormsUtils.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/WinFormsUtils.cs @@ -311,9 +311,8 @@ public static string TextWithoutMnemonics(string text) /// public static Point TranslatePoint(Point point, Control fromControl, Control toControl) { - NativeMethods.POINT pt = new NativeMethods.POINT(point.X, point.Y); - UnsafeNativeMethods.MapWindowPoints(new HandleRef(fromControl, fromControl.Handle), new HandleRef(toControl, toControl.Handle), pt, 1); - return new Point(pt.x, pt.y); + UnsafeNativeMethods.MapWindowPoints(new HandleRef(fromControl, fromControl.Handle), new HandleRef(toControl, toControl.Handle), ref point, 1); + return point; } /// @@ -570,7 +569,7 @@ internal struct DCMapping : IDisposable private Graphics _graphics; private Rectangle _translatedBounds; - public DCMapping(HandleRef hDC, Rectangle bounds) + public unsafe DCMapping(HandleRef hDC, Rectangle bounds) { if (hDC.Handle == IntPtr.Zero) { @@ -578,7 +577,6 @@ public DCMapping(HandleRef hDC, Rectangle bounds) } bool success; - NativeMethods.POINT viewportOrg = new NativeMethods.POINT(); IntPtr hOriginalClippingRegion = IntPtr.Zero; _translatedBounds = bounds; @@ -587,11 +585,11 @@ public DCMapping(HandleRef hDC, Rectangle bounds) _dc.SaveHdc(); // Retrieve the x-coordinates and y-coordinates of the viewport origin for the specified device context. - success = SafeNativeMethods.GetViewportOrgEx(hDC, viewportOrg); + success = SafeNativeMethods.GetViewportOrgEx(hDC, out Point viewportOrg); Debug.Assert(success, "GetViewportOrgEx() failed."); // Create a new rectangular clipping region based off of the bounds specified, shifted over by the x & y specified in the viewport origin. - IntPtr hClippingRegion = Interop.Gdi32.CreateRectRgn(viewportOrg.x + bounds.Left, viewportOrg.y + bounds.Top, viewportOrg.x + bounds.Right, viewportOrg.y + bounds.Bottom); + IntPtr hClippingRegion = Interop.Gdi32.CreateRectRgn(viewportOrg.X + bounds.Left, viewportOrg.Y + bounds.Top, viewportOrg.X + bounds.Right, viewportOrg.Y + bounds.Bottom); Debug.Assert(hClippingRegion != IntPtr.Zero, "CreateRectRgn() failed."); try @@ -605,8 +603,8 @@ public DCMapping(HandleRef hDC, Rectangle bounds) Debug.Assert(result != -1, "GetClipRgn() failed."); // Shift the viewpoint origint by coordinates specified in "bounds". - NativeMethods.POINT lastViewPort = new NativeMethods.POINT(); - success = SafeNativeMethods.SetViewportOrgEx(hDC, viewportOrg.x + bounds.Left, viewportOrg.y + bounds.Top, lastViewPort); + var lastViewPort = new Point(); + success = SafeNativeMethods.SetViewportOrgEx(hDC, viewportOrg.X + bounds.Left, viewportOrg.Y + bounds.Top, &lastViewPort); Debug.Assert(success, "SetViewportOrgEx() failed."); Interop.RegionType originalRegionType; diff --git a/src/System.Windows.Forms/src/misc/GDI/DeviceContext2.cs b/src/System.Windows.Forms/src/misc/GDI/DeviceContext2.cs index fa532a8bb30..2c098a7e0e3 100644 --- a/src/System.Windows.Forms/src/misc/GDI/DeviceContext2.cs +++ b/src/System.Windows.Forms/src/misc/GDI/DeviceContext2.cs @@ -376,8 +376,7 @@ public Point ViewportOrigin { get { - Point point = new Point(); - IntUnsafeNativeMethods.GetViewportOrgEx(new HandleRef(this, Hdc), ref point); + IntUnsafeNativeMethods.GetViewportOrgEx(new HandleRef(this, Hdc), out Point point); return point; } set @@ -390,10 +389,10 @@ public Point ViewportOrigin /// Sets the DC Viewport origin to the specified value and returns its previous value; /// origin values are in device units. /// - public Point SetViewportOrigin(Point newOrigin) + public unsafe Point SetViewportOrigin(Point newOrigin) { - Point oldOrigin = new Point(); - IntUnsafeNativeMethods.SetViewportOrgEx(new HandleRef(this, Hdc), newOrigin.X, newOrigin.Y, ref oldOrigin); + var oldOrigin = new Point(); + IntUnsafeNativeMethods.SetViewportOrgEx(new HandleRef(this, Hdc), newOrigin.X, newOrigin.Y, &oldOrigin); return oldOrigin; } } diff --git a/src/System.Windows.Forms/src/misc/GDI/UnsafeNativeMethods.cs b/src/System.Windows.Forms/src/misc/GDI/UnsafeNativeMethods.cs index 39f27bea9bd..6582dbe47fc 100644 --- a/src/System.Windows.Forms/src/misc/GDI/UnsafeNativeMethods.cs +++ b/src/System.Windows.Forms/src/misc/GDI/UnsafeNativeMethods.cs @@ -84,7 +84,7 @@ public static bool LineTo(HandleRef hdc, int x, int y) } [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)] - public static extern bool MoveToEx(HandleRef hdc, int x, int y, ref Point pt); + public static unsafe extern bool MoveToEx(HandleRef hdc, int x, int y, Point *lppt); [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, EntryPoint = "Rectangle", CharSet = CharSet.Auto)] public static extern bool IntRectangle(HandleRef hdc, int left, int top, int right, int bottom); @@ -130,13 +130,13 @@ public static int GetMapMode(HandleRef hDC) public static extern bool GetViewportExtEx(HandleRef hdc, ref Size lpSize); [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)] - public static extern bool GetViewportOrgEx(HandleRef hdc, ref Point lpPoint); + public static extern bool GetViewportOrgEx(HandleRef hdc, out Point lpPoint); [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)] public static extern bool SetViewportExtEx(HandleRef hDC, int x, int y, ref Size size); [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true)] - public static extern bool SetViewportOrgEx(HandleRef hDC, int x, int y, ref Point point); + public static unsafe extern bool SetViewportOrgEx(HandleRef hDC, int x, int y, Point *point); [DllImport(ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] public static extern int GetTextMetricsW(HandleRef hDC, ref IntNativeMethods.TEXTMETRIC lptm); diff --git a/src/System.Windows.Forms/src/misc/GDI/WindowsGraphics2.cs b/src/System.Windows.Forms/src/misc/GDI/WindowsGraphics2.cs index 9fd38349dc3..b22d1b4def9 100644 --- a/src/System.Windows.Forms/src/misc/GDI/WindowsGraphics2.cs +++ b/src/System.Windows.Forms/src/misc/GDI/WindowsGraphics2.cs @@ -45,7 +45,7 @@ public TextPaddingOptions TextPadding /// Drawing methods. - public void DrawPie(WindowsPen pen, Rectangle bounds, float startAngle, float sweepAngle) + public unsafe void DrawPie(WindowsPen pen, Rectangle bounds, float startAngle, float sweepAngle) { HandleRef hdc = new HandleRef(dc, dc.Hdc); @@ -65,7 +65,7 @@ public void DrawPie(WindowsPen pen, Rectangle bounds, float startAngle, float sw int radius = sideLength / 2; IntUnsafeNativeMethods.BeginPath(hdc); Point oldPoint = default; - IntUnsafeNativeMethods.MoveToEx(hdc, p.X, p.Y, ref oldPoint); + IntUnsafeNativeMethods.MoveToEx(hdc, p.X, p.Y, &oldPoint); IntUnsafeNativeMethods.AngleArc(hdc, p.X, p.Y, radius, startAngle, sweepAngle); IntUnsafeNativeMethods.LineTo(hdc, p.X, p.Y); IntUnsafeNativeMethods.EndPath(hdc); @@ -558,7 +558,7 @@ public void DrawLine(WindowsPen pen, Point p1, Point p2) DrawLine(pen, p1.X, p1.Y, p2.X, p2.Y); } - public void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2) + public unsafe void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2) { HandleRef hdc = new HandleRef(dc, dc.Hdc); @@ -582,7 +582,7 @@ public void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2) Point oldPoint = new Point(); - IntUnsafeNativeMethods.MoveToEx(hdc, x1, y1, ref oldPoint); + IntUnsafeNativeMethods.MoveToEx(hdc, x1, y1, &oldPoint); IntUnsafeNativeMethods.LineTo(hdc, x2, y2); if (bckMode != DeviceContextBackgroundMode.Transparent) @@ -595,7 +595,7 @@ public void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2) dc.SetRasterOperation(rasterOp); } - IntUnsafeNativeMethods.MoveToEx(hdc, oldPoint.X, oldPoint.Y, ref oldPoint); + IntUnsafeNativeMethods.MoveToEx(hdc, oldPoint.X, oldPoint.Y, &oldPoint); } ///