Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ bool IMouseInputProvider.CaptureMouse()
// WORKAROUND for the fact that WM_MOUSELEAVE not sent when capture changes
if (success && !_active)
{
NativeMethods.POINT ptCursor = new NativeMethods.POINT();
NativeMethods.POINT ptCursor = default;

success = UnsafeNativeMethods.TryGetCursorPos(ptCursor);
success = UnsafeNativeMethods.TryGetCursorPos(ref ptCursor);

if(success)
{
try
{
SafeNativeMethods.ScreenToClient(new HandleRef(this, _source.Value.CriticalHandle), ptCursor);
SafeNativeMethods.ScreenToClient(new HandleRef(this, _source.Value.CriticalHandle), ref ptCursor);
}
catch(System.ComponentModel.Win32Exception)
{
Expand Down Expand Up @@ -334,7 +334,7 @@ internal IntPtr FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, Int
return result;
}
/*
NativeMethods.POINT ptCursor = new NativeMethods.POINT();
NativeMethods.POINT ptCursor = default;
int messagePos = 0;
try
{
Expand Down Expand Up @@ -471,7 +471,7 @@ internal IntPtr FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, Int
NativeMethods.POINT pt = new NativeMethods.POINT(x,y);
try
{
SafeNativeMethods.ScreenToClient(new HandleRef(this,hwnd), pt);
SafeNativeMethods.ScreenToClient(new HandleRef(this,hwnd), ref pt);

x = pt.x;
y = pt.y;
Expand Down Expand Up @@ -956,7 +956,7 @@ private void PossiblyDeactivate(IntPtr hwndCapture, bool stillActiveIfOverSelf)
{
NativeMethods.RECT rcClient = new NativeMethods.RECT();
SafeNativeMethods.GetClientRect(new HandleRef(this,hwndToCheck), ref rcClient);
SafeNativeMethods.ScreenToClient(new HandleRef(this,hwndToCheck), ptCursor);
SafeNativeMethods.ScreenToClient(new HandleRef(this,hwndToCheck), ref ptCursor);

if(ptCursor.x < rcClient.left || ptCursor.x >= rcClient.right ||
ptCursor.y < rcClient.top || ptCursor.y >= rcClient.bottom)
Expand Down Expand Up @@ -1163,10 +1163,10 @@ private bool ReportInput(
{
// If we get this far, "A" does NOT have capture
// - now ensure mouse is over "A"
NativeMethods.POINT ptCursor = new NativeMethods.POINT();
NativeMethods.POINT ptCursor = default;
try
{
UnsafeNativeMethods.GetCursorPos(ptCursor);
UnsafeNativeMethods.GetCursorPos(ref ptCursor);
}
catch(System.ComponentModel.Win32Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ IntPtr IStylusInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr
NativeMethods.POINT pt1 = new NativeMethods.POINT(
NativeMethods.SignedLOWORD(lParam),
NativeMethods.SignedHIWORD(lParam));
SafeNativeMethods.ScreenToClient(new HandleRef(this, hwnd), pt1);
SafeNativeMethods.ScreenToClient(new HandleRef(this, hwnd), ref pt1);
Point ptClient1 = new Point(pt1.x, pt1.y);

IInputElement inputElement = StylusDevice.LocalHitTest(_source.Value, ptClient1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1636,10 +1636,10 @@ private void UpdateWindowAndClientCoordinates()

// Convert the client rect to screen coordinates, adjusting for RTL
NativeMethods.POINT ptClientTopLeft = new NativeMethods.POINT(rcClient.left, rcClient.top);
UnsafeNativeMethods.ClientToScreen(hWnd, ptClientTopLeft);
UnsafeNativeMethods.ClientToScreen(hWnd, ref ptClientTopLeft);

NativeMethods.POINT ptClientBottomRight = new NativeMethods.POINT(rcClient.right, rcClient.bottom);
UnsafeNativeMethods.ClientToScreen(hWnd, ptClientBottomRight);
UnsafeNativeMethods.ClientToScreen(hWnd, ref ptClientBottomRight);

if(ptClientBottomRight.x >= ptClientTopLeft.x)
{
Expand Down Expand Up @@ -2201,7 +2201,10 @@ private void UpdateWindowSettings(bool enableRenderTarget, DUCE.ChannelSet? chan
NativeMethods.BLENDFUNCTION blend = new NativeMethods.BLENDFUNCTION();
blend.BlendOp = NativeMethods.AC_SRC_OVER;
blend.SourceConstantAlpha = 0; // transparent
UnsafeNativeMethods.UpdateLayeredWindow(_hWnd.h, IntPtr.Zero, null, null, IntPtr.Zero, null, 0, ref blend, NativeMethods.ULW_ALPHA);
unsafe
{
UnsafeNativeMethods.UpdateLayeredWindow(_hWnd.h, IntPtr.Zero, null, null, IntPtr.Zero, null, 0, ref blend, NativeMethods.ULW_ALPHA);
}
}
isLayered = (flags != MILTransparencyFlags.Opaque);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int UnsafeNativeMethods.IOleControlSite.GetExtendedControl(out object ppDisp)
return NativeMethods.E_NOTIMPL;
}

int UnsafeNativeMethods.IOleControlSite.TransformCoords(NativeMethods.POINT pPtlHimetric, NativeMethods.POINTF pPtfContainer, int dwFlags)
int UnsafeNativeMethods.IOleControlSite.TransformCoords(ref NativeMethods.POINT pPtlHimetric, ref NativeMethods.POINTF pPtfContainer, int dwFlags)
{
if ((dwFlags & NativeMethods.XFORMCOORDS_HIMETRICTOCONTAINER) != 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal WebBrowserSite(WebBrowser host) : base(host)

#region IDocHostUIHandler Implementation

int UnsafeNativeMethods.IDocHostUIHandler.ShowContextMenu(int dwID, NativeMethods.POINT pt, object pcmdtReserved, object pdispReserved)
int UnsafeNativeMethods.IDocHostUIHandler.ShowContextMenu(int dwID, ref NativeMethods.POINT pt, object pcmdtReserved, object pdispReserved)
{
//
// Returning S_FALSE will allow the native control to do default processing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ private void BuildWindow(Visual targetVisual)
// the Display on which the PopupRoot is situated, and return that value here.
var origin =
_positionInfo != null
? new NativeMethods.POINTSTRUCT(_positionInfo.X, _positionInfo.Y)
? new NativeMethods.POINT(_positionInfo.X, _positionInfo.Y)
: PopupInitialPlacementHelper.GetPlacementOrigin(this);

_secHelper.BuildWindow(origin.x, origin.y, targetVisual, IsTransparent, PopupFilterMessage, OnWindowResize, OnDpiChanged);
Expand Down Expand Up @@ -3057,7 +3057,7 @@ internal NativeMethods.POINT GetMouseCursorPos(Visual targetVisual)
// This is a fallback if we couldn't convert Mouse.GetPosition
NativeMethods.POINT mousePoint = new NativeMethods.POINT(0, 0);

UnsafeNativeMethods.TryGetCursorPos(mousePoint);
UnsafeNativeMethods.TryGetCursorPos(ref mousePoint);

return mousePoint;
}
Expand Down Expand Up @@ -3527,7 +3527,7 @@ internal static bool IsPerMonitorDpiScalingActive
/// <summary>
/// Finds the screen coordinates of the PlacementTarget's (left, top)
/// </summary>
private static NativeMethods.POINTSTRUCT? GetPlacementTargetOriginInScreenCoordinates(Popup popup)
private static NativeMethods.POINT? GetPlacementTargetOriginInScreenCoordinates(Popup popup)
{
var target = popup?.GetTarget() as UIElement;
if (target != null)
Expand All @@ -3541,7 +3541,7 @@ internal static bool IsPerMonitorDpiScalingActive
if (targetToClientTransform.TryTransform(new Point(0, 0), out ptPlacementTargetOrigin))
{
var screenOrigin = popup._secHelper.ClientToScreen(rootVisual, ptPlacementTargetOrigin);
return new NativeMethods.POINTSTRUCT((int)screenOrigin.X, (int)screenOrigin.Y);
return new NativeMethods.POINT((int)screenOrigin.X, (int)screenOrigin.Y);
}
}

Expand All @@ -3551,13 +3551,13 @@ internal static bool IsPerMonitorDpiScalingActive
/// <summary>
/// Finds the (top,left) screen coordinates of the monitor that contains the placement target
/// </summary>
internal static NativeMethods.POINTSTRUCT GetPlacementOrigin(Popup popup)
internal static NativeMethods.POINT GetPlacementOrigin(Popup popup)
{
var placementOrigin = new NativeMethods.POINTSTRUCT(0, 0);
NativeMethods.POINT placementOrigin = default;

if (IsPerMonitorDpiScalingActive)
{
var screenOrigin = GetPlacementTargetOriginInScreenCoordinates(popup);
NativeMethods.POINT? screenOrigin = GetPlacementTargetOriginInScreenCoordinates(popup);
if (screenOrigin.HasValue)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ private void OnWmImeNotify(IntPtr hwnd, IntPtr wParam)
candform.rcArea.right = 0;
candform.rcArea.top = 0;
candform.rcArea.bottom = 0;
candform.ptCurrentPos = new NativeMethods.POINT(0, 0);
candform.ptCurrentPos = default;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ public void GetACPFromPoint(int viewCookie, ref UnsafeNativeMethods.POINT tsfPoi
compositionTarget = source.CompositionTarget;

// Convert to client coordinates.
SafeNativeMethods.ScreenToClient(new HandleRef(null,win32Window.Handle), point);
SafeNativeMethods.ScreenToClient(new HandleRef(null, win32Window.Handle), ref point);

// Convert to mil measure units.
milPoint = new Point(point.x, point.y);
Expand Down Expand Up @@ -2347,8 +2347,8 @@ private static UnsafeNativeMethods.RECT TransformRootRectToScreenCoordinates(Poi
hwnd = win32Window.Handle;

// Transform to screen coords.
clientPoint = new NativeMethods.POINT();
UnsafeNativeMethods.ClientToScreen(new HandleRef(null, hwnd), /* ref by interop */ clientPoint);
clientPoint = default;
UnsafeNativeMethods.ClientToScreen(new HandleRef(null, hwnd), ref clientPoint);

rect.left = (int)(clientPoint.x + milPointTopLeft.X);
rect.right = (int)(clientPoint.x + milPointBottomRight.X);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3212,10 +3212,10 @@ public static void UnregisterClass(string lpClassName, IntPtr hInstance)
private static extern bool _UpdateLayeredWindow(
IntPtr hwnd,
SafeDC hdcDst,
[In] ref POINT pptDst,
[In] ref SIZE psize,
ref POINT pptDst,
ref SIZE psize,
SafeDC hdcSrc,
[In] ref POINT pptSrc,
ref POINT pptSrc,
int crKey,
ref BLENDFUNCTION pblend,
ULW dwFlags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3582,12 +3582,11 @@ private void SetIWindowService()
IntPtr GetCurrentMonitorFromMousePosition()
{
// center on the screen on which the mouse is on
NativeMethods.POINT pt = new NativeMethods.POINT();
NativeMethods.POINT pt = default;

UnsafeNativeMethods.TryGetCursorPos(pt);
UnsafeNativeMethods.TryGetCursorPos(ref pt);

NativeMethods.POINTSTRUCT ptStruct = new NativeMethods.POINTSTRUCT(pt.x, pt.y);
return SafeNativeMethods.MonitorFromPoint(ptStruct, NativeMethods.MONITOR_DEFAULTTONEAREST);
return SafeNativeMethods.MonitorFromPoint(pt, NativeMethods.MONITOR_DEFAULTTONEAREST);
}

// <summary>
Expand Down Expand Up @@ -4699,7 +4698,11 @@ internal virtual void WmMoveChangedHelper()

private bool WmGetMinMaxInfo( IntPtr lParam )
{
NativeMethods.MINMAXINFO mmi = (NativeMethods.MINMAXINFO)UnsafeNativeMethods.PtrToStructure( lParam, typeof(NativeMethods.MINMAXINFO));
NativeMethods.MINMAXINFO mmi;
unsafe
{
mmi = *(NativeMethods.MINMAXINFO*)lParam;
}

//
// For Bug 1380569: Window SizeToContent does not work after changing Max size properties
Expand Down Expand Up @@ -4760,7 +4763,10 @@ private bool WmGetMinMaxInfo( IntPtr lParam )

// Notify Win32 of the new Min/Max value for this HWND.

Marshal.StructureToPtr(mmi, lParam, true);
unsafe
{
*(NativeMethods.MINMAXINFO*)lParam = mmi;
}
}

return true;
Expand Down Expand Up @@ -7277,7 +7283,7 @@ internal NativeMethods.RECT WindowBounds
private NativeMethods.POINT GetWindowScreenLocation(FlowDirection flowDirection)
{
Debug.Assert(IsSourceWindowNull != true, "IsSourceWindowNull cannot be true here");
NativeMethods.POINT pt = new NativeMethods.POINT(0, 0);
NativeMethods.POINT pt = default;
if (flowDirection == FlowDirection.RightToLeft)
{
NativeMethods.RECT rc = new NativeMethods.RECT(0, 0, 0, 0);
Expand All @@ -7288,7 +7294,7 @@ private NativeMethods.POINT GetWindowScreenLocation(FlowDirection flowDirection)
// note that we use rc.right here for the RTL case and client to screen that point
pt = new NativeMethods.POINT(rc.right, rc.top);
}
UnsafeNativeMethods.ClientToScreen(new HandleRef(this, _sourceWindow.CriticalHandle), pt);
UnsafeNativeMethods.ClientToScreen(new HandleRef(this, _sourceWindow.CriticalHandle), ref pt);

return pt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static Point ClientToScreen(Point pointClient, PresentationSource present
NativeMethods.POINT ptClient = FromPoint(pointClient);
NativeMethods.POINT ptClientRTLAdjusted = AdjustForRightToLeft(ptClient, handleRef);

UnsafeNativeMethods.ClientToScreen(handleRef, ptClientRTLAdjusted);
UnsafeNativeMethods.ClientToScreen(handleRef, ref ptClientRTLAdjusted);

return ToPoint(ptClientRTLAdjusted);
}
Expand All @@ -200,7 +200,7 @@ internal static Point ScreenToClient(Point pointScreen, PresentationSource prese

NativeMethods.POINT ptClient = FromPoint(pointScreen);

SafeNativeMethods.ScreenToClient(handleRef, ptClient);
SafeNativeMethods.ScreenToClient(handleRef, ref ptClient);

ptClient = AdjustForRightToLeft(ptClient, handleRef);

Expand Down
38 changes: 10 additions & 28 deletions src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2996,13 +2996,10 @@ private static int SizeOf()
}

[StructLayout(LayoutKind.Sequential)]
public class POINT {
public struct POINT {
public int x;
public int y;

public POINT() {
}

public POINT(int x, int y) {
this.x = x;
this.y = y;
Expand All @@ -3014,18 +3011,6 @@ public override string ToString() {
#endif
}

// use this in cases where the Native API takes a POINT not a POINT*
// classes marshal by ref.
[StructLayout(LayoutKind.Sequential)]
public struct POINTSTRUCT {
public int x;
public int y;
public POINTSTRUCT(int x, int y) {
this.x = x;
this.y = y;
}
}

public delegate IntPtr WndProc(IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam);


Expand Down Expand Up @@ -4216,14 +4201,11 @@ public void Disconnect(bool release) {
#endif

[StructLayout(LayoutKind.Sequential)/*leftover(noAutoOffset)*/]
public sealed class POINTF
public struct POINTF
{
[MarshalAs(UnmanagedType.R4)/*leftover(offset=0, x)*/]
public float x;

[MarshalAs(UnmanagedType.R4)/*leftover(offset=4, y)*/]
public float y;
}
}

[StructLayout(LayoutKind.Sequential)/*leftover(noAutoOffset)*/]
public sealed class OLEINPLACEFRAMEINFO
Expand All @@ -4237,7 +4219,7 @@ public sealed class OLEINPLACEFRAMEINFO

[MarshalAs(UnmanagedType.U4)/*leftover(offset=16, cAccelEntries)*/]
public uint cAccelEntries;
}
}

#if never
[StructLayout(LayoutKind.Sequential)]
Expand Down Expand Up @@ -5216,12 +5198,12 @@ public class ACCEL {
#endif

[StructLayout(LayoutKind.Sequential)]
public class MINMAXINFO {
public POINT ptReserved = new POINT();
public POINT ptMaxSize = new POINT();
public POINT ptMaxPosition = new POINT();
public POINT ptMinTrackSize = new POINT();
public POINT ptMaxTrackSize = new POINT();
public struct MINMAXINFO {
public POINT ptReserved;
public POINT ptMaxSize;
public POINT ptMaxPosition;
public POINT ptMinTrackSize;
public POINT ptMaxTrackSize;
}
#if never
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal static class NativeMethodsSetLastError
public static extern int MapWindowPoints(NativeMethods.HWND hWndFrom, NativeMethods.HWND hWndTo, [In, Out] ref NativeMethods.RECT rect, int cPoints);

[DllImport(PresentationNativeDll, EntryPoint="MapWindowPointsWrapper", SetLastError = true, ExactSpelling=true, CharSet=CharSet.Auto)]
public static extern int MapWindowPoints(NativeMethods.HWND hWndFrom, NativeMethods.HWND hWndTo, [In, Out] ref NativeMethods.POINT pt, int cPoints);
public static extern int MapWindowPoints(NativeMethods.HWND hWndFrom, NativeMethods.HWND hWndTo, ref NativeMethods.POINT pt, int cPoints);

#elif UIAUTOMATIONCLIENTSIDEPROVIDERS // UIAutomationClientSideProviders

Expand Down
Loading