gpt4 book ai didi

window - “使用System.Windows.Interop;”它在哪里?

转载 作者:行者123 更新时间:2023-12-04 16:53:19 24 4
gpt4 key购买 nike

我看到了无边界窗口周围阴影的代码,但是这是我的问题。 using System.Windows.Interop;带下划线,我在引用文献中找不到它。同样在public static void DropShadowToWindow(Window window)中,此窗口带有下划线,因此我想它与Interop链接...

using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;

class DwmDropShadow
{

[DllImport("dwmapi.dll", PreserveSig = true)]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);

[DllImport("dwmapi.dll")]
private static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMarInset);

/// <summary>
/// Drops a standard shadow to a WPF Window, even if the window isborderless. Only works with DWM (Vista and Seven).
/// This method is much more efficient than setting AllowsTransparency to true and using the DropShadow effect,
/// as AllowsTransparency involves a huge permormance issue (hardware acceleration is turned off for all the window).
/// </summary>
/// <param name="window">Window to which the shadow will be applied</param>
public static void DropShadowToWindow(Window window)
{
if (!DropShadow(window))
{
window.SourceInitialized += new EventHandler(window_SourceInitialized);
}
}

private static void window_SourceInitialized(object sender, EventArgs e) //fixed typo
{
Window window = (Window)sender;

DropShadow(window);

window.SourceInitialized -= new EventHandler(window_SourceInitialized);
}

/// <summary>
/// The actual method that makes API calls to drop the shadow to the window
/// </summary>
/// <param name="window">Window to which the shadow will be applied</param>
/// <returns>True if the method succeeded, false if not</returns>
private static bool DropShadow(Window window)
{
try
{
WindowInteropHelper helper = new WindowInteropHelper(window);
int val = 2;
int ret1 = DwmSetWindowAttribute(helper.Handle, 2, ref val, 4);

if (ret1 == 0)
{
Margins m = new Margins { Bottom = 0, Left = 0, Right = 0, Top = 0 };
int ret2 = DwmExtendFrameIntoClientArea(helper.Handle, ref m);
return ret2 == 0;
}
else
{
return false;
}
}
catch (Exception ex)
{
// Probably dwmapi.dll not found (incompatible OS)
return false;
}
}
}

最佳答案

它在WindowsBase.DLL中,这是.NET Framework 3.0中引入的。它位于c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll

关于window - “使用System.Windows.Interop;”它在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19460075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com