Nei*_*ell 8 c# backwards-compatibility windows-api-code-pack
我没有方便的XP机器.如果我使用Windows API Codepack在C#中对Vista/Win7做一些新的事情(例如"TaskDialog"),它如何应对在Windows XP机器上运行?
如果我使用Codepack,我是否有效地使我的应用程序仅支持Vista和更高版本的Windows?
JPW*_*JPW 13
如果你查看"TaskDialog.cs",你会发现TastDialog的构造函数包括以下几行:
// Throw PlatformNotSupportedException if the user is not running Vista or beyond
CoreHelpers.ThrowIfNotVista();
Run Code Online (Sandbox Code Playgroud)
如果您只包含对Windows API代码包程序集的引用,那么您将没问题.但是使用当前运行应用程序的操作系统上不存在的功能将引发异常.要检查某个功能是否可以安全调用(即当前操作系统支持),大多数类都包含静态IsPlatformSupported属性.
因此TaskDialog.IsPlatformSupported,MessageBox.Show()如果您的操作系统不支持TaskDialogs,您可以先检查并调用.