无法在Visual Studio中添加dwmapi.dll

编程入门 行业动态 更新时间:2024-10-21 09:17:27
本文介绍了无法在Visual Studio中添加dwmapi.dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我想尝试漂亮的WPF玻璃窗.但是,当我尝试在Visual Studio中尝试添加 dwmapi.dll 作为引用时,我遇到了一个问题. 有一个显示以下内容的消息框: 无法添加对~~ dwmapi.dll的引用.请确保您可以访问该文件,并且该文件是有效的程序集或com组件 一些教程提到我可以导入dwmapi.dll,但这也不起作用. 你能告诉我问题是什么吗?我正在使用Windows Vista和Visual Studio2008.

Hi guys, I wanted to try the nice WPF glass window. But I face a problem when I try to add dwmapi.dll as a reference in Visual Studio. There is a message box displaying the following: A reference to ~~dwmapi.dll could not be added .please make sure you that the file is accessible and that it is valid assembly or com component Some tutorials mention that I can import dwmapi.dll, but that does not work either. Can you tell me what the problem is please? I am using Windows Vista and Visual Studio 2008.

推荐答案

很简单,您无法添加对Windows DWM的引用,但是可以使用DllImport( msdn.microsoft/en-us/library/system.runtime.interopservices.dllimportattribute.aspx [ ^ ]) 我通常要做的是: 创建以下类: Its simple, you cannot add a reference to the DWM of the windows, BUT you can import it by using the DllImport (msdn.microsoft/en-us/library/system.runtime.interopservices.dllimportattribute.aspx[^]) What I usually do is: Create the following class: using System; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop; using System.Windows.Media; namespace WpfApplication1 { public static class GlassLib { struct MARGINS { public MARGINS(Thickness t) { Left = (int)t.Left; Right = (int)t.Right; Top = (int)t.Top; Bottom = (int)t.Bottom; } public int Left; public int Right; public int Top; public int Bottom; } [DllImport("dwmapi.dll", PreserveSig = false)] static extern void DwmExtendFrameIntoClientArea( IntPtr hwnd, ref MARGINS margins); [DllImport("dwmapi.dll", PreserveSig = false)] static extern bool DwmIsCompositionEnabled(); // Extension Method for the window public static void ApplyGlass(this Window window) { try { if (DwmIsCompositionEnabled()) { IntPtr hwnd = new WindowInteropHelper(window).Handle; if (hwnd == IntPtr.Zero) throw new InvalidOperationException( "The Window must be shown before extending glass."); window.Background = Brushes.Transparent; HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent; // Setting the MARGINS to -1 in all directions will // cover the client area with Glass Effect MARGINS margins = new MARGINS(new Thickness(-1)); DwmExtendFrameIntoClientArea(hwnd, ref margins); } } catch (Exception Ex) { throw Ex; } } } }

然后在窗口"中添加您要执行的玻璃效果":

Then in the Window you want to add the Glass Effect you do:

public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); Loaded += new RoutedEventHandler(MainWindow_Loaded); } void MainWindow_Loaded(object sender, RoutedEventArgs e) { this.ApplyGlass(); } }

生成,运行,然后转到玻璃. 请注意,要使此功能正常运行,您必须具有Windows OS 6(Vista)或更高版本,或者处理ApplyGlass方法将引发的异常. 希望这会有所帮助 最好, Raul Mainardi Neto

Build, Run, and there you go GLASS.. Note that in order for this to work you must either have a Windows OS 6 (Vista) or greater OR handle the Exception that WILL be thrown by the ApplyGlass Method. Hope this helps All Best, Raul Mainardi Neto

谢谢Raul. 这对我非常有帮助! :) Thank you , Raul . It was very helpful for me ! :)

-非常感谢宝贵的信息... -- Thanks a lot unvaluable infos...

更多推荐

无法在Visual Studio中添加dwmapi.dll

本文发布于:2023-11-13 14:37:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584596.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Studio   Visual   dll   dwmapi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!