refactor Interop classes
This commit is contained in:
1 parent
de5c2e7a6e
commit
a3dd633a66
28 files changed
+948
-976
No files matched your search
@@ -79,13 +79,13 @@ namespace HandyControl.Tools
|
||||
|
||||
try
|
||||
{
|
||||
var bi = new BITMAPINFO(width, -height, 32)
|
||||
var bi = new InteropValues.BITMAPINFO(width, -height, 32)
|
||||
{
|
||||
bmiHeader_biCompression = NativeMethods.BI_RGB
|
||||
bmiHeader_biCompression = InteropValues.BI_RGB
|
||||
};
|
||||
|
||||
var bits = IntPtr.Zero;
|
||||
colorBitmap = UnsafeNativeMethods.CreateDIBSection(new HandleRef(null, IntPtr.Zero), ref bi, NativeMethods.DIB_RGB_COLORS, ref bits, null, 0);
|
||||
colorBitmap = InteropMethods.CreateDIBSection(new HandleRef(null, IntPtr.Zero), ref bi, InteropValues.DIB_RGB_COLORS, ref bits, null, 0);
|
||||
|
||||
if (colorBitmap.IsInvalid || bits == IntPtr.Zero)
|
||||
{
|
||||
@@ -95,13 +95,13 @@ namespace HandyControl.Tools
|
||||
Marshal.Copy(colorArray, 0, bits, colorArray.Length);
|
||||
var maskArray = GenerateMaskArray(width, height, colorArray);
|
||||
|
||||
maskBitmap = UnsafeNativeMethods.CreateBitmap(width, height, 1, 1, maskArray);
|
||||
maskBitmap = InteropMethods.CreateBitmap(width, height, 1, 1, maskArray);
|
||||
if (maskBitmap.IsInvalid)
|
||||
{
|
||||
return IconHandle.GetInvalidIcon();
|
||||
}
|
||||
|
||||
var iconInfo = new ICONINFO
|
||||
var iconInfo = new InteropValues.ICONINFO
|
||||
{
|
||||
fIcon = isIcon,
|
||||
xHotspot = xHotspot,
|
||||
@@ -110,7 +110,7 @@ namespace HandyControl.Tools
|
||||
hbmColor = colorBitmap
|
||||
};
|
||||
|
||||
return UnsafeNativeMethods.CreateIconIndirect(iconInfo);
|
||||
return InteropMethods.CreateIconIndirect(iconInfo);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -252,21 +252,21 @@ namespace HandyControl.Tools
|
||||
{
|
||||
if (SystemBitDepth == 0)
|
||||
{
|
||||
var hdcDesktop = new HandleRef(null, UnsafeNativeMethods.GetDC(new HandleRef()));
|
||||
var hdcDesktop = new HandleRef(null, InteropMethods.GetDC(new HandleRef()));
|
||||
try
|
||||
{
|
||||
var sysBitDepth = UnsafeNativeMethods.GetDeviceCaps(hdcDesktop, NativeMethods.BITSPIXEL);
|
||||
sysBitDepth *= UnsafeNativeMethods.GetDeviceCaps(hdcDesktop, NativeMethods.PLANES);
|
||||
var sysBitDepth = InteropMethods.GetDeviceCaps(hdcDesktop, InteropValues.BITSPIXEL);
|
||||
sysBitDepth *= InteropMethods.GetDeviceCaps(hdcDesktop, InteropValues.PLANES);
|
||||
|
||||
if (sysBitDepth == 8)
|
||||
{
|
||||
sysBitDepth = 4;
|
||||
}
|
||||
|
||||
var cxSmallIcon = UnsafeNativeMethods.GetSystemMetrics(SM.CXSMICON);
|
||||
var cySmallIcon = UnsafeNativeMethods.GetSystemMetrics(SM.CYSMICON);
|
||||
var cxIcon = UnsafeNativeMethods.GetSystemMetrics(SM.CXICON);
|
||||
var cyIcon = UnsafeNativeMethods.GetSystemMetrics(SM.CYICON);
|
||||
var cxSmallIcon = InteropMethods.GetSystemMetrics(InteropValues.SM.CXSMICON);
|
||||
var cySmallIcon = InteropMethods.GetSystemMetrics(InteropValues.SM.CYSMICON);
|
||||
var cxIcon = InteropMethods.GetSystemMetrics(InteropValues.SM.CXICON);
|
||||
var cyIcon = InteropMethods.GetSystemMetrics(InteropValues.SM.CYICON);
|
||||
|
||||
SmallIconSize = new Size(cxSmallIcon, cySmallIcon);
|
||||
IconSize = new Size(cxIcon, cyIcon);
|
||||
@@ -274,7 +274,7 @@ namespace HandyControl.Tools
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnsafeNativeMethods.ReleaseDC(new HandleRef(), hdcDesktop);
|
||||
InteropMethods.ReleaseDC(new HandleRef(), hdcDesktop);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -287,8 +287,8 @@ namespace HandyControl.Tools
|
||||
|
||||
SecurityHelper.DemandUIWindowPermission();
|
||||
|
||||
var iconModuleFile = UnsafeNativeMethods.GetModuleFileName(new HandleRef());
|
||||
UnsafeNativeMethods.ExtractIconEx(iconModuleFile, 0, out largeIconHandle, out smallIconHandle, 1);
|
||||
var iconModuleFile = InteropMethods.GetModuleFileName(new HandleRef());
|
||||
InteropMethods.ExtractIconEx(iconModuleFile, 0, out largeIconHandle, out smallIconHandle, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ namespace HandyControl.Tools
|
||||
/// <returns></returns>
|
||||
public static Window GetActiveWindow() => Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
|
||||
|
||||
private static readonly BitArray _cacheValid = new BitArray((int)CacheSlot.NumSlots);
|
||||
private static readonly BitArray _cacheValid = new BitArray((int)InteropValues.CacheSlot.NumSlots);
|
||||
|
||||
private static bool _setDpiX = true;
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace HandyControl.Tools
|
||||
var desktopWnd = new HandleRef(null, IntPtr.Zero);
|
||||
|
||||
// Win32Exception will get the Win32 error code so we don't have to
|
||||
var dc = UnsafeNativeMethods.GetDC(desktopWnd);
|
||||
var dc = InteropMethods.GetDC(desktopWnd);
|
||||
|
||||
// Detecting error case from unmanaged call, required by PREsharp to throw a Win32Exception
|
||||
if (dc == IntPtr.Zero)
|
||||
@@ -53,12 +53,12 @@ namespace HandyControl.Tools
|
||||
|
||||
try
|
||||
{
|
||||
_dpi = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, dc), NativeMethods.LOGPIXELSY);
|
||||
_dpi = InteropMethods.GetDeviceCaps(new HandleRef(null, dc), InteropValues.LOGPIXELSY);
|
||||
_dpiInitialized = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnsafeNativeMethods.ReleaseDC(desktopWnd, new HandleRef(null, dc));
|
||||
InteropMethods.ReleaseDC(desktopWnd, new HandleRef(null, dc));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,19 +82,19 @@ namespace HandyControl.Tools
|
||||
{
|
||||
_setDpiX = false;
|
||||
var desktopWnd = new HandleRef(null, IntPtr.Zero);
|
||||
var dc = UnsafeNativeMethods.GetDC(desktopWnd);
|
||||
var dc = InteropMethods.GetDC(desktopWnd);
|
||||
if (dc == IntPtr.Zero)
|
||||
{
|
||||
throw new Win32Exception();
|
||||
}
|
||||
try
|
||||
{
|
||||
_dpiX = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, dc), NativeMethods.LOGPIXELSX);
|
||||
_cacheValid[(int)CacheSlot.DpiX] = true;
|
||||
_dpiX = InteropMethods.GetDeviceCaps(new HandleRef(null, dc), InteropValues.LOGPIXELSX);
|
||||
_cacheValid[(int)InteropValues.CacheSlot.DpiX] = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnsafeNativeMethods.ReleaseDC(desktopWnd, new HandleRef(null, dc));
|
||||
InteropMethods.ReleaseDC(desktopWnd, new HandleRef(null, dc));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,11 +113,11 @@ namespace HandyControl.Tools
|
||||
{
|
||||
lock (_cacheValid)
|
||||
{
|
||||
while (!_cacheValid[(int)CacheSlot.WindowResizeBorderThickness])
|
||||
while (!_cacheValid[(int)InteropValues.CacheSlot.WindowResizeBorderThickness])
|
||||
{
|
||||
_cacheValid[(int)CacheSlot.WindowResizeBorderThickness] = true;
|
||||
_cacheValid[(int)InteropValues.CacheSlot.WindowResizeBorderThickness] = true;
|
||||
|
||||
var frameSize = new Size(NativeMethods.GetSystemMetrics(SM.CXSIZEFRAME), NativeMethods.GetSystemMetrics(SM.CYSIZEFRAME));
|
||||
var frameSize = new Size(InteropMethods.GetSystemMetrics(InteropValues.SM.CXSIZEFRAME), InteropMethods.GetSystemMetrics(InteropValues.SM.CYSIZEFRAME));
|
||||
var frameSizeInDips = DpiHelper.DeviceSizeToLogical(frameSize, DpiX / 96.0, Dpi / 96.0);
|
||||
|
||||
_windowResizeBorderThickness = new Thickness(frameSizeInDips.Width, frameSizeInDips.Height, frameSizeInDips.Width, frameSizeInDips.Height);
|
||||
@@ -135,9 +135,9 @@ namespace HandyControl.Tools
|
||||
#if netle40
|
||||
return WindowResizeBorderThickness;
|
||||
#elif Core
|
||||
var hdc = UnsafeNativeMethods.GetDC(IntPtr.Zero);
|
||||
var scale = UnsafeNativeMethods.GetDeviceCaps(hdc, NativeMethods.DESKTOPVERTRES) / (float)UnsafeNativeMethods.GetDeviceCaps(hdc, NativeMethods.VERTRES);
|
||||
UnsafeNativeMethods.ReleaseDC(IntPtr.Zero, hdc);
|
||||
var hdc = InteropMethods.GetDC(IntPtr.Zero);
|
||||
var scale = InteropMethods.GetDeviceCaps(hdc, InteropValues.DESKTOPVERTRES) / (float)InteropMethods.GetDeviceCaps(hdc, InteropValues.VERTRES);
|
||||
InteropMethods.ReleaseDC(IntPtr.Zero, hdc);
|
||||
return WindowResizeBorderThickness.Add(new Thickness(4 * scale));
|
||||
#else
|
||||
return WindowResizeBorderThickness.Add(new Thickness(4));
|
||||
|
||||
Reference in new issue
Block a user