如何编写C#中得到我的机器上直接X版本? [英] How to code to get direct X version on my machine in C#?

查看:79
本文介绍了如何编写C#中得到我的机器上直接X版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要当用户点击他应该能够知道他的机器上安装的Direct X版本?菜单项知道

I want to know when the user clicks the menu item he should be able to know the direct X version installed on his machine?

我要在实现代码C#在VS2008。

I want to code this in C# in VS2008.

我应该写什么在菜单项单击事件?
我在C#中的初学者,所以不知道从哪里..

What should i write in the menu item click event? Am a beginner in C#,so dont know where to start from..

任何人可以请帮助?
谢谢..

can anybody please help? Thanks..

推荐答案

这可以帮助:的.NET如果DirectX 10的支持如何检测?

编辑:

下面是一些更好的代码,我想。我能想出的最好的是基于Windows版本在DX10或DX11的情况进行检查。这是不是100%准确(因为Vista的可升级到DX11,但我不检查这个),但有总比没有好。

Below is some better code I think. The best I can come up with is a check based on Windows version in the case of DX10 or DX11. This is not 100% accurate (because Vista can be upgraded to DX11 but I do not check for this), but better than nothing.

    private int GetDirectxMajorVersion()
    {
        int directxMajorVersion = 0;

        var OSVersion = Environment.OSVersion;

        // if Windows Vista or later
        if (OSVersion.Version.Major >= 6)
        {
            // if Windows 7 or later
            if (OSVersion.Version.Major > 6 || OSVersion.Version.Minor >= 1)
            {
                directxMajorVersion = 11;
            }
            // if Windows Vista
            else
            {
                directxMajorVersion = 10;
            }
        }
        // if Windows XP or earlier.
        else
        {
            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\DirectX"))
            {
                string versionStr = key.GetValue("Version") as string;
                if (!string.IsNullOrEmpty(versionStr))
                {
                    var versionComponents = versionStr.Split('.');
                    if (versionComponents.Length > 1)
                    {
                        int directXLevel;
                        if (int.TryParse(versionComponents[1], out directXLevel))
                        {
                            directxMajorVersion = directXLevel;
                        }
                    }
                }
            }
        }

        return directxMajorVersion;
    }

这篇关于如何编写C#中得到我的机器上直接X版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆