Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port ControlDesigner #681

Merged
merged 13 commits into from
Apr 12, 2019
15 changes: 8 additions & 7 deletions src/Common/src/CompModSwitches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ internal static class CompModSwitches {
private static TraceSwitch setBounds;

private static BooleanSwitch lifetimeTracing;

private static TraceSwitch s_handleLeak;
private static BooleanSwitch s_traceCollect;
private static BooleanSwitch s_commonDesignerServices;

public static TraceSwitch ActiveX {
Expand Down Expand Up @@ -294,7 +295,7 @@ internal static class CompModSwitches {
return setBounds;
}
}
#endif
#endif

public static TraceSwitch HandleLeak {
get {
Expand All @@ -305,16 +306,16 @@ internal static class CompModSwitches {
}
}

private static BooleanSwitch traceCollect;
public static BooleanSwitch TraceCollect {
get {
if (traceCollect == null) {
traceCollect = new BooleanSwitch("TRACECOLLECT", "HandleCollector: Trace HandleCollector operations");
if (s_traceCollect == null) {
s_traceCollect = new BooleanSwitch("TRACECOLLECT", "HandleCollector: Trace HandleCollector operations");
}
return traceCollect;
return s_traceCollect;
}
}
internal static BooleanSwitch CommonDesignerServices

public static BooleanSwitch CommonDesignerServices
{
get
{
Expand Down
9 changes: 9 additions & 0 deletions src/Common/src/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1962,6 +1962,7 @@ public const int
WM_MBUTTONDOWN = 0x0207,
WM_MBUTTONUP = 0x0208,
WM_MBUTTONDBLCLK = 0x0209,
WM_NCMOUSEHOVER = 0x02A0,
WM_XBUTTONDOWN = 0x020B,
WM_XBUTTONUP = 0x020C,
WM_XBUTTONDBLCLK = 0x020D,
Expand Down Expand Up @@ -5701,6 +5702,8 @@ public enum MONTCALENDAR_VIEW_MODE
public const int PS_GEOMETRIC = 0x00010000;
public const int PS_ENDCAP_SQUARE = 0x00000100;

public const int WS_EX_TRANSPARENT = 0x00000020;

public const int NULL_BRUSH = 5;
public const int MM_HIMETRIC = 3;

Expand Down Expand Up @@ -6042,6 +6045,10 @@ public struct UiaRect {
[DllImport(ExternDll.User32, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public extern static IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, [In, Out] TV_HITTESTINFO lParam);

[DllImport(ExternDll.User32, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public static extern IntPtr DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public static extern short GetKeyState(int keyCode);
Expand All @@ -6065,6 +6072,8 @@ public static bool DeleteObject(IntPtr hObject)
[DllImport(ExternDll.Gdi32, ExactSpelling = true, EntryPoint = "CreateRectRgn", CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.Process)]
private static extern IntPtr IntCreateRectRgn(int x1, int y1, int x2, int y2);
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
public static IntPtr CreateRectRgn(int x1, int y1, int x2, int y2)
{
return System.Internal.HandleCollector.Add(IntCreateRectRgn(x1, y1, x2, y2), CommonHandles.GDI);
Expand Down
33 changes: 16 additions & 17 deletions src/Common/src/SafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ internal static class SafeNativeMethods {

public static extern bool ValidateRect(HandleRef hWnd, [In, Out] ref NativeMethods.RECT rect);


[DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public static extern bool ValidateRect(IntPtr hwnd, IntPtr prect);

//
// WARNING: Don't uncomment this code unless you absolutelly need it. Use instead Marshal.GetLastWin32Error
// and mark your PInvoke [DllImport(..., SetLastError=true)]
Expand Down Expand Up @@ -573,11 +578,12 @@ internal static class SafeNativeMethods {
public static extern bool ShowWindow(HandleRef hWnd, int nCmdShow);
[DllImport(ExternDll.User32, ExactSpelling=true, CharSet=CharSet.Auto)]

public static extern bool SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter, int x, int y, int cx, int cy, int flags);
public static extern bool SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter,
int x, int y, int cx, int cy, int flags);

[DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, int flags);
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
int x, int y, int cx, int cy, int flags);

[DllImport(ExternDll.User32, CharSet=CharSet.Auto)]

Expand All @@ -598,8 +604,8 @@ internal static class SafeNativeMethods {
public static extern bool RedrawWindow(HandleRef hwnd, NativeMethods.COMRECT rcUpdate, HandleRef hrgnUpdate, int flags);

[DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public static extern bool RedrawWindow(IntPtr hwnd, NativeMethods.COMRECT rcUpdate, IntPtr hrgnUpdate, int flags);

[DllImport(ExternDll.User32, ExactSpelling=true, CharSet=CharSet.Auto)]

public static extern bool InvalidateRect(HandleRef hWnd, ref NativeMethods.RECT rect, bool erase);
Expand Down Expand Up @@ -699,7 +705,6 @@ internal static class SafeNativeMethods {
HandleRef hSrcDC, int xSrc, int ySrc, int dwRop);

[DllImport(ExternDll.Gdi32, ExactSpelling = true, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public static extern bool BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);

[DllImport(ExternDll.User32, ExactSpelling=true, CharSet=CharSet.Auto)]
Expand Down Expand Up @@ -864,6 +869,12 @@ internal static class SafeNativeMethods {
[DllImport(ExternDll.Kernel32, SetLastError = true)]
public static extern IntPtr OpenProcess(uint dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId);

[DllImport(ExternDll.Gdi32, ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern bool RoundRect(HandleRef hDC, int left, int top, int right, int bottom, int width, int height);

[DllImport(ExternDll.Uxtheme, CharSet = CharSet.Auto)]
public extern static int SetWindowTheme(IntPtr hWnd, string subAppName, string subIdList);

internal const int PROCESS_QUERY_INFORMATION = 0x0400;
internal const int PROCESS_VM_READ = 0x0010;

Expand Down Expand Up @@ -910,18 +921,6 @@ public interface IFontDisp {

short Charset {get;set;}
}

[DllImport(ExternDll.Gdi32, ExactSpelling = true, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public static extern bool RoundRect(HandleRef hDC, int left, int top, int right, int bottom, int width, int height);

[DllImport(ExternDll.Gdi32, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public static extern bool GetTextMetrics(HandleRef hdc, NativeMethods.TEXTMETRIC tm);

[ResourceExposure(ResourceScope.None)]
[DllImport(ExternDll.Uxtheme, CharSet = CharSet.Auto)]
public extern static int SetWindowTheme(IntPtr hWnd, string subAppName, string subIdList);
}
}

69 changes: 37 additions & 32 deletions src/Common/src/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ internal static class UnsafeNativeMethods {

public static extern int ReadClassStg(HandleRef pStg, [In, Out] ref Guid pclsid);

[DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern int GetMessageTime();

[DllImport(ExternDll.Ole32, SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = true)]
internal extern static void CoTaskMemFree(IntPtr pv);

Expand Down Expand Up @@ -198,20 +201,6 @@ internal static bool IsVista

public static extern int CoGetMalloc(int dwReserved, out IMalloc pMalloc);

/* Commenting this out until someone actually needs to use it again...
[DllImport(ExternDll.Ole32)]
public static extern int OleSetMenuDescriptor(IntPtr hOleMenu, IntPtr hWndFrame, IntPtr hWndActiveObject, IOleInPlaceFrame frame, IOleInPlaceActiveObject activeObject);
*/

/* Commenting this out until someone actually needs to use it again...
[DllImport(ExternDll.Kernel32)]
public static extern bool IsBadReadPtr(HandleRef ptr, int size);
*/

[DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public static extern int GetMessageTime();

[DllImport(ExternDll.User32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
[ResourceExposure(ResourceScope.Process)]
public static extern int GetWindowThreadProcessId(HandleRef hWnd, out int lpdwProcessId);
Expand Down Expand Up @@ -836,7 +825,12 @@ public static StringBuilder GetModuleFileNameLongPath(HandleRef hModule)
[DllImport(ExternDll.User32, CharSet=CharSet.Auto)]

public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, NativeMethods.LVBKIMAGE lParam);


[DllImport(ExternDll.User32, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
[SuppressMessage("Microsoft.Portability", "CA1901:PInvokeDeclarationsShouldBePortable")]
[ResourceExposure(ResourceScope.None)]
public static extern IntPtr SendMessage(IntPtr hwnd, int msg, bool wparam, int lparam);

[DllImport(ExternDll.User32, CharSet=CharSet.Auto)]

public static extern int SendMessage(HandleRef hWnd, int msg, int wParam, ref NativeMethods.LVHITTESTINFO lParam);
Expand Down Expand Up @@ -1001,7 +995,11 @@ public static StringBuilder GetModuleFileNameLongPath(HandleRef hModule)

public static extern IntPtr GetWindow(HandleRef hWnd, int uCmd);
[DllImport(ExternDll.User32, ExactSpelling=true, CharSet=CharSet.Auto)]


[ResourceExposure(ResourceScope.None)]
public static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
[DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)]

public static extern IntPtr GetDlgItem(HandleRef hWnd, int nIDDlgItem);
[DllImport(ExternDll.Kernel32, CharSet=CharSet.Auto)]

Expand All @@ -1016,17 +1014,7 @@ public static StringBuilder GetModuleFileNameLongPath(HandleRef hModule)

public static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hWnd, int msg,
IntPtr wParam, IntPtr lParam);

/*
[DllImport(ExternDll.User32, CharSet=CharSet.Auto)]
public static extern IntPtr GetProp(HandleRef hWnd, int atom);
[DllImport(ExternDll.User32, CharSet=CharSet.Auto)]
public static extern IntPtr GetProp(HandleRef hWnd, string name);
[DllImport(ExternDll.User32, CharSet=CharSet.Auto)]
public static extern IntPtr RemoveProp(HandleRef hWnd, short atom);
[DllImport(ExternDll.User32, CharSet=CharSet.Auto)]
public static extern IntPtr RemoveProp(HandleRef hWnd, string propName);
*/

[DllImport(ExternDll.Kernel32, ExactSpelling=true, CharSet=CharSet.Auto)]

public static extern short GlobalDeleteAtom(short atom);
Expand All @@ -1041,10 +1029,7 @@ public static StringBuilder GetModuleFileNameLongPath(HandleRef hModule)
[DllImport(ExternDll.User32, CharSet=CharSet.Auto)]

public static extern bool GetClassInfo(HandleRef hInst, string lpszClass, IntPtr h);
/*
[DllImport(ExternDll.Shell32, CharSet=CharSet.Auto)]
public static extern int SHGetFolderPath(HandleRef hwndOwner, int nFolder, HandleRef hToken, int dwFlags, StringBuilder lpszPath);
*/

[DllImport(ExternDll.User32, ExactSpelling=true, CharSet=CharSet.Auto)]

public static extern int GetSystemMetrics(int nIndex);
Expand All @@ -1054,6 +1039,9 @@ public static StringBuilder GetModuleFileNameLongPath(HandleRef hModule)

public static extern int GetSystemMetricsForDpi(int nIndex, uint dpi);

[DllImport(ExternDll.Gdi32, CharSet = CharSet.Auto)]
public static extern bool GetTextMetrics(HandleRef hdc, NativeMethods.TEXTMETRIC tm);

/// <summary>
/// Tries to get system metrics for the dpi. dpi is ignored if "GetSystemMetricsForDpi" is not available on the OS that this application is running.
/// </summary>
Expand Down Expand Up @@ -1143,6 +1131,10 @@ public static StringBuilder GetModuleFileNameLongPath(HandleRef hModule)
[DllImport(ExternDll.Ole32, ExactSpelling=true, CharSet=CharSet.Auto)]

public static extern int RevokeDragDrop(HandleRef hwnd);

[DllImport(ExternDll.Ole32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public static extern int RevokeDragDrop(IntPtr hwnd);
[DllImport(ExternDll.User32, CharSet=CharSet.Auto)]

public static extern bool PeekMessage([In, Out] ref NativeMethods.MSG msg, HandleRef hwnd, int msgMin, int msgMax, int remove);
Expand All @@ -1169,6 +1161,11 @@ public static StringBuilder GetModuleFileNameLongPath(HandleRef hModule)
[DllImport(ExternDll.Oleacc, ExactSpelling=true, CharSet=CharSet.Auto)]

public static extern IntPtr LresultFromObject(ref Guid refiid, IntPtr wParam, HandleRef pAcc);

[DllImport(ExternDll.Oleacc, ExactSpelling = true, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.Process)]
public static extern IntPtr LresultFromObject(ref Guid refiid, IntPtr wParam, IntPtr pAcc);

[DllImport(ExternDll.Oleacc, ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Auto)]

public static extern int CreateStdAccessibleObject(HandleRef hWnd, int objID, ref Guid refiid, [In, Out, MarshalAs(UnmanagedType.Interface)] ref object pAcc);
Expand All @@ -1193,7 +1190,11 @@ public static StringBuilder GetModuleFileNameLongPath(HandleRef hModule)
public static IntPtr BeginPaint(HandleRef hWnd, [In, Out, MarshalAs(UnmanagedType.LPStruct)] ref NativeMethods.PAINTSTRUCT lpPaint) {
return System.Internal.HandleCollector.Add(IntBeginPaint(hWnd, ref lpPaint), NativeMethods.CommonHandles.HDC);
}


[DllImport(ExternDll.User32, ExactSpelling = true, EntryPoint = "BeginPaint", CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public static extern IntPtr BeginPaint(IntPtr hWnd, [In, Out] ref NativeMethods.PAINTSTRUCT lpPaint);

[DllImport(ExternDll.User32, ExactSpelling=true, EntryPoint="EndPaint", CharSet=CharSet.Auto)]

private static extern bool IntEndPaint(HandleRef hWnd, ref NativeMethods.PAINTSTRUCT lpPaint);
Expand All @@ -1202,6 +1203,10 @@ public static StringBuilder GetModuleFileNameLongPath(HandleRef hModule)
return IntEndPaint(hWnd, ref lpPaint);
}

[DllImport(ExternDll.User32, ExactSpelling = true, EntryPoint = "EndPaint", CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
public static extern bool EndPaint(IntPtr hWnd, ref NativeMethods.PAINTSTRUCT lpPaint);

[DllImport(ExternDll.User32, ExactSpelling=true, EntryPoint="GetDC", CharSet=CharSet.Auto)]

private static extern IntPtr IntGetDC(HandleRef hWnd);
Expand Down
Loading