显示显卡的信息

  1using System;
  2using System.Drawing;
  3using System.Collections;
  4using System.ComponentModel;
  5using System.Windows.Forms;
  6using System.Data;
  7// 添加自定义的命名空间。
  8using DxVBLib;
  9
 10namespace DirectXShowCard
 11{
 12    /// <summary>
 13    /// 显示显卡的信息。
 14    /// </summary>

 15    public class Form1 : System.Windows.Forms.Form
 16    {
 17        private System.Windows.Forms.Button button1;
 18        private System.Windows.Forms.RichTextBox richTextBox1;
 19        /// <summary>
 20        /// 必需的设计器变量。
 21        /// </summary>

 22        private System.ComponentModel.Container components = null;
 23
 24        public Form1()
 25        {
 26            // Windows 窗体设计器支持所必需的
 27            InitializeComponent();
 28            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
 29        }

 30        /// <summary>
 31        /// 清理所有正在使用的资源。
 32        /// </summary>

 33        protected override void Dispose( bool disposing )
 34        {
 35            if( disposing )
 36            {
 37                if (components != null)
 38                {
 39                    components.Dispose();
 40                }

 41            }

 42            base.Dispose( disposing );
 43        }

 44
 45        Windows Form Designer generated code
 87
 88        /// <summary>
 89        /// 应用程序的主入口点。
 90        /// </summary>

 91        [STAThread]
 92        static void Main()
 93        {
 94            Application.Run(new Form1());
 95        }

 96        // 添加自定义的私有变量。
 97        private static DirectX7 DirectX;
 98        private void button1_Click(object sender, System.EventArgs e)
 99        {
100            DirectX = new DirectX7();
101            DirectDrawEnum ddEnum;
102            string guid;
103
104            ddEnum = DirectX.GetDDEnum();
105            richTextBox1.Text = "显卡信息:\n";
106            for (int i = 1; i <= ddEnum.GetCount(); i++)
107            {
108                richTextBox1.Text += "显卡号码:" + i.ToString() + "\n";
109                richTextBox1.Text += "描述:    " + ddEnum.GetDescription(i) + "\n";
110                richTextBox1.Text += "显卡名称:" + ddEnum.GetName(i) + "\n";
111                guid = ddEnum.GetGuid(i);
112                if(guid == "")
113                    richTextBox1.Text += "Guid号码:无\n";
114                else
115                    richTextBox1.Text += "Guid号码:" + ddEnum.GetGuid(i) + "\n";
116                GetDDCaps(guid);
117                GetD3DDevices(guid);
118                GetDisplayModes(guid);
119            }

120        }

121        private void GetDDCaps(string guid)
122        {
123            DirectDraw7 DirectDraw;
124            DDCAPS hwCaps = new DDCAPS();        // 硬件信息
125            DDCAPS helCaps = new DDCAPS();        // 软件信息
126
127            DirectDraw = DirectX.DirectDrawCreate(guid);
128            DirectDraw.GetCaps(ref hwCaps, ref helCaps);
129            richTextBox1.Text += "\n硬件信息:\n";
130            richTextBox1.Text += "    总的显存:  " + hwCaps.lVidMemTotal.ToString() + "\n";
131            richTextBox1.Text += "    可用的显存:" + hwCaps.lVidMemFree.ToString() + "\n";
132
133            // 支持的调色板。
134            CONST_DDPCAPSFLAGS value = hwCaps.lPalCaps;
135            if (value == 0)
136                richTextBox1.Text += "    没有调色板。\n";
137            if ((value & CONST_DDPCAPSFLAGS.DDPCAPS_1BIT) > 0)
138                richTextBox1.Text += "    支持 1 Bit调色板。\n";
139            if ((value & CONST_DDPCAPSFLAGS.DDPCAPS_2BIT) > 0)
140                richTextBox1.Text += "    支持 2 Bit调色板。\n";
141            if ((value & CONST_DDPCAPSFLAGS.DDPCAPS_8BIT) > 0)
142                richTextBox1.Text += "    支持 8 Bit调色板。\n";
143            if ((value & CONST_DDPCAPSFLAGS.DDPCAPS_8BITENTRIES) > 0)
144                richTextBox1.Text += "    支持 8 Bit Entries 调色板。\n";
145            if ((value & CONST_DDPCAPSFLAGS.DDPCAPS_ALLOW256) > 0)
146                richTextBox1.Text += "    支持 256色调色板。\n";
147
148            // 是否支持gamma ramp接口
149            if (((int)hwCaps.ddsCaps.lCaps2 &
150                 (int)CONST_DDCAPS2FLAGS.DDCAPS2_CANCALIBRATEGAMMA) > 0)
151                richTextBox1.Text += "    支持gamma连接。\n";
152            else
153                richTextBox1.Text += "    不支持gamma连接。\n";
154        }

155
156        private void GetD3DDevices(string guid)
157        {
158            Direct3DEnumDevices d3dEnum;
159            D3DDEVICEDESC7 hwDesc = new D3DDEVICEDESC7();
160            DirectDraw7 DirectDraw;
161            Direct3D7 d3d;
162
163            DirectDraw = DirectX.DirectDrawCreate(guid);
164            d3d = DirectDraw.GetDirect3D();
165            richTextBox1.Text += "\nD3D设备信息:\n";
166            d3dEnum = d3d.GetDevicesEnum();
167            for (int i = 1; i <= d3dEnum.GetCount(); i++)
168            {
169                d3dEnum.GetDesc(i, ref hwDesc);
170                richTextBox1.Text += "    描述:" + d3dEnum.GetDescription(i) + "\n";
171                richTextBox1.Text += "    名称:" + d3dEnum.GetName(i) + "\n";
172                richTextBox1.Text += "    Guid:" + d3dEnum.GetGuid(i) + "\n";
173                richTextBox1.Text += "    最大纹理高度:" +
174                    hwDesc.lMaxTextureHeight.ToString() + "\n";
175                richTextBox1.Text += "    最大纹理宽度:" +
176                    hwDesc.lMaxTextureWidth.ToString() + "\n";
177
178                if ((hwDesc.lDeviceRenderBitDepth & (int)CONST_DDBITDEPTHFLAGS.DDBD_8) > 0)
179                    richTextBox1.Text += "    支持8位渲染。\n";
180                if ((hwDesc.lDeviceRenderBitDepth & (int)CONST_DDBITDEPTHFLAGS.DDBD_16) > 0)
181                    richTextBox1.Text += "    支持16位渲染。\n";
182                if ((hwDesc.lDeviceRenderBitDepth & (int)CONST_DDBITDEPTHFLAGS.DDBD_24) > 0)
183                    richTextBox1.Text += "    支持24位渲染。\n";
184                if ((hwDesc.lDeviceRenderBitDepth & (int)CONST_DDBITDEPTHFLAGS.DDBD_32) > 0)
185                    richTextBox1.Text += "    支持32位渲染。\n";
186
187                if ((hwDesc.lDeviceZBufferBitDepth & (int)CONST_DDBITDEPTHFLAGS.DDBD_8) > 0)
188                    richTextBox1.Text += "    支持8比特的Z缓存。\n";
189                if ((hwDesc.lDeviceZBufferBitDepth & (int)CONST_DDBITDEPTHFLAGS.DDBD_16) > 0)
190                    richTextBox1.Text += "    支持16比特的Z缓存。\n";
191                if ((hwDesc.lDeviceZBufferBitDepth & (int)(int)CONST_DDBITDEPTHFLAGS.DDBD_24) > 0)
192                    richTextBox1.Text += "    支持24比特的Z缓存。\n";
193                if ((hwDesc.lDeviceZBufferBitDepth & (int)CONST_DDBITDEPTHFLAGS.DDBD_32) > 0)
194                    richTextBox1.Text += "    支持32比特的Z缓存。\n";
195                if (hwDesc.lDeviceZBufferBitDepth == 0)
196                    richTextBox1.Text += "    不支持Z缓存。\n";
197
198                if ((hwDesc.lDevCaps & CONST_D3DDEVICEDESCCAPS.D3DDEVCAPS_TEXTURENONLOCALVIDMEM) > 0)
199                    richTextBox1.Text += "    支持AGP纹理。\n";
200                if ((hwDesc.lDevCaps & CONST_D3DDEVICEDESCCAPS.D3DDEVCAPS_SORTDECREASINGZ) > 0)
201                    richTextBox1.Text += "    IM三角必须安递减深度排序。\n";
202                if ((hwDesc.lDevCaps & CONST_D3DDEVICEDESCCAPS.D3DDEVCAPS_SORTEXACT) > 0)
203                    richTextBox1.Text += "    IM三角必须完全排序。\n";
204                if ((hwDesc.lDevCaps & CONST_D3DDEVICEDESCCAPS.D3DDEVCAPS_SORTINCREASINGZ) > 0)
205                    richTextBox1.Text += "    IM三角必须安递增深度排序。\n";
206                if ((hwDesc.lDevCaps & CONST_D3DDEVICEDESCCAPS.D3DDEVCAPS_TEXTUREVIDEOMEMORY) > 0)
207                    richTextBox1.Text += "    IM三角可以使用显卡内存存储材质。\n";
208            }

209        }

210        // 取得显示模式信息。
211        public void GetDisplayModes(string guid)
212        {
213            DirectDrawEnumModes DisplayModesEnum;
214            DDSURFACEDESC2 ddsd2 = new DDSURFACEDESC2();
215            DirectDraw7 DirectDraw;
216
217            DirectDraw = DirectX.DirectDrawCreate(guid);
218            DisplayModesEnum = DirectDraw.GetDisplayModesEnum(0ref ddsd2);
219            richTextBox1.Text += "\n显示模式信息:\n";
220            // 列举支持的显示模式。
221            for (int i = 1; i <= DisplayModesEnum.GetCount(); i++)
222            {
223                DisplayModesEnum.GetItem(i, ref ddsd2);
224                richTextBox1.Text += "    显示模式[" + i.ToString() + "]:";
225                richTextBox1.Text += "宽度[" + ddsd2.lWidth.ToString() + "],";
226                richTextBox1.Text += "高度[" + ddsd2.lHeight.ToString() + "],";
227                richTextBox1.Text += "每象素的比特数[" + ddsd2.ddpfPixelFormat.lRGBBitCount.ToString() + "],";
228                richTextBox1.Text += "刷新频率[" + ddsd2.lRefreshRate.ToString()  + "]。" + "\n";
229            }

230        }

231    }

232}

233

Interop.DxVBLib.rar
posted on 2007-08-23 13:01  Gofficer  阅读(385)  评论(0)    收藏  举报