当前位置:首页 > c++ > 正文内容

c++获取windows显卡等显示设备信息

xuwenyan10个月前 (12-12)c++325
#include <Windows.h>
#include <iostream>  
#include <DXGI.h>  
#include <vector>
#pragma comment(lib, "DXGI.lib")

using namespace std;

int main(int argc, char* argv[])
{
    // 参数定义  
    IDXGIFactory* pFactory;
    IDXGIAdapter* pAdapter;
    std::vector <IDXGIAdapter*> vAdapters;            // 显卡  

    // 显卡的数量  
    int iAdapterNum = 0;

    // 创建一个DXGI工厂  
    HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&pFactory));
    if (FAILED(hr))
        return -1;

    // 枚举适配器  
    while (pFactory->EnumAdapters(iAdapterNum, &pAdapter) != DXGI_ERROR_NOT_FOUND)
    {
        vAdapters.push_back(pAdapter);
        ++iAdapterNum;
    }

    // 信息输出   
    cout << "===============获取到" << iAdapterNum << "块显卡===============" << endl;
    for (size_t i = 0; i < vAdapters.size(); i++)
    {
        // 获取信息  
        DXGI_ADAPTER_DESC adapterDesc;
        vAdapters[i]->GetDesc(&adapterDesc);
        wstring aa(adapterDesc.Description);
        // 输出显卡信息  
        cout << "系统视频内存:" << adapterDesc.DedicatedSystemMemory / 1024 / 1024 << "M" << endl;
        cout << "专用视频内存:" << adapterDesc.DedicatedVideoMemory / 1024 / 1024 << "M" << endl;
        cout << "共享系统内存:" << adapterDesc.SharedSystemMemory / 1024 / 1024 << "M" << endl;
        wcout << L"设备描述:" << aa.c_str() << endl;
        cout << "设备ID:" << adapterDesc.DeviceId << endl;
        cout << "PCI ID修正版本:" << adapterDesc.Revision << endl;
        cout << "子系统PIC ID:" << adapterDesc.SubSysId << endl;
        cout << "厂商编号:" << adapterDesc.VendorId << endl;

        // 输出设备  
        IDXGIOutput* pOutput;
        std::vector<IDXGIOutput*> vOutputs;
        // 输出设备数量  
        int iOutputNum = 0;
        while (vAdapters[i]->EnumOutputs(iOutputNum, &pOutput) != DXGI_ERROR_NOT_FOUND)
        {
            vOutputs.push_back(pOutput);
            iOutputNum++;
        }

        cout << "-----------------------------------------" << endl;
        cout << "获取到" << iOutputNum << "个显示设备:" << endl;
        cout << endl;

        for (size_t n = 0; n < vOutputs.size(); n++)
        {
            // 获取显示设备信息  
            DXGI_OUTPUT_DESC outputDesc;
            vOutputs[n]->GetDesc(&outputDesc);

            // 获取设备支持  
            UINT uModeNum = 0;
            DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
            UINT flags = DXGI_ENUM_MODES_INTERLACED;

            vOutputs[n]->GetDisplayModeList(format, flags, &uModeNum, 0);
            DXGI_MODE_DESC* pModeDescs = new DXGI_MODE_DESC[uModeNum];
            vOutputs[n]->GetDisplayModeList(format, flags, &uModeNum, pModeDescs);

            cout << "显示设备名称:" << outputDesc.DeviceName << endl;
            cout << "显示设备当前分辨率:" << outputDesc.DesktopCoordinates.right - outputDesc.DesktopCoordinates.left << "*" << outputDesc.DesktopCoordinates.bottom - outputDesc.DesktopCoordinates.top << endl;
            cout << endl;

            // 所支持的分辨率信息  
            cout << "分辨率信息:" << endl;
            for (UINT m = 0; m < uModeNum; m++)
            {
                cout << "== 分辨率:" << pModeDescs[m].Width << "*" << pModeDescs[m].Height << "     刷新率" << (pModeDescs[m].RefreshRate.Numerator) / (pModeDescs[m].RefreshRate.Denominator) << endl;
            }
        }
        vOutputs.clear();

    }
    vAdapters.clear();

    system("pause");
    return 0;
}


    文章作者:xuwenyan
    版权声明:本文为本站原创文章,转载请注明出处,非常感谢,如版权漏申明或您觉得任何有异议的地方欢迎与本站取得联系。

    扫描二维码推送至手机访问。

    版权声明:本文由艺文笔记发布,如需转载请注明出处。

    本文链接:https://www.xuwenyan.com/archives/2948

    标签: C++编程
    分享给朋友:

    “c++获取windows显卡等显示设备信息” 的相关文章

    C++智能指针基本原理

    C++智能指针基本原理

    什么是智能指针?最简单来说就是会自动释放内存的指针,使用方便,不用担心内存泄漏问题。它其实就是通过封装,利用对象的析构函数释放申请的内存,基本上自动释放的用法都是利用析构函数去做一些释放工作。如:自动释放的句柄智能指针的基本实现class TestClass {  p...

    7z的简介和使用

    7z的简介和使用

    7z是一个支持多种压缩格式的开源项目,由Igor Pavlov开发,源码下载位置:https://www.7-zip.org/download.html源码结构项目源码目录结构是如下图:Asm包含主要算法实现的汇编代码,直接使用汇编的好处是可以提高运行效率,当然这对跨平台的支持不是很好。C主要是算法...

    C++如何实现远程注入dll

    C++如何实现远程注入dll

    如何把我们的代码放到别人的进程里面运行?我们需要做一个dll动态库,然后使用远程注入技术,将我们的dll注入到别人的进程里面,然后加载起来。这样我们的代码就可以在别人的进程里面工作了。注入代码#include "stdafx.h" int EnableD...

    VC的ATL工程向导同时生成一个PS工程是做什么的?可以不要吗?

    VC的ATL工程向导同时生成一个PS工程是做什么的?可以不要吗?

    例如,我用VC2015的工程向导新建一个ATL的工程名字叫myAtl,那么VC会同时给我生成一个叫做myAtlPS的工程。这个myAtlPS工程是做什么的?什么情况下可以不需要它?什么情况下它又是必须存在的? PS工程是什么?可以不要吗? 这个PS工程叫做代理与存根(proxy&nbs...

    uafxcwd.lib(afxmem.obj) : error LNK2005:

    uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)"解决办法

    如果在编译MFC程序的时候出现下列及类似的错误: 1˃uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMTD.lib(new...

    C++ 获取进程所在目录(进程全路径)

    C++ 获取进程所在目录(进程全路径)

    打开windows任务管理器,会看到很多的进程在运行,随机挑选一个,如何通过c++代码获取某一个进程的所在全路径呢?这也是在windows软件开发中经常遇到的需求。通过进程名获取进程全路径由于可能很多进程叫同一个名字,所以获得的结果也有可能是多个#include <windows.h...