none
Connaitre toutes les résolution de ma carte graphique C# / .NET RRS feed

  • Question

  • Bonjour à tous,

    Je souhaiterai récupéré en C# / .NET toutes les résolution que peux accepté ma carte graphique, en quelque sorte la liste contenue dans la fenêtre suivante :

    Je ne parle pas récupérer la résolution actuelle de mon écran, comme le fait le code ci-dessous :

    int screenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
    int screenHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
    

    Merci d'avance,


    Pierre STO


    dimanche 29 mars 2015 10:51

Réponses

  • Bonjour,

    J'ai commencé par regarder les WMI mais sans rien trouvé de probant

    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
         
            [DllImport("user32.dll")]
            public static extern bool EnumDisplaySettings(
                  string deviceName, int modeNum, ref DEVMODE devMode);
            const int ENUM_CURRENT_SETTINGS = -1;
    
            const int ENUM_REGISTRY_SETTINGS = -2;
    
            [StructLayout(LayoutKind.Sequential)]
            public struct DEVMODE
            {
    
                private const int CCHDEVICENAME = 0x20;
                private const int CCHFORMNAME = 0x20;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
                public string dmDeviceName;
                public short dmSpecVersion;
                public short dmDriverVersion;
                public short dmSize;
                public short dmDriverExtra;
                public int dmFields;
                public int dmPositionX;
                public int dmPositionY;
                public ScreenOrientation dmDisplayOrientation;
                public int dmDisplayFixedOutput;
                public short dmColor;
                public short dmDuplex;
                public short dmYResolution;
                public short dmTTOption;
                public short dmCollate;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
                public string dmFormName;
                public short dmLogPixels;
                public int dmBitsPerPel;
                public int dmPelsWidth;
                public int dmPelsHeight;
                public int dmDisplayFlags;
                public int dmDisplayFrequency;
                public int dmICMMethod;
                public int dmICMIntent;
                public int dmMediaType;
                public int dmDitherType;
                public int dmReserved1;
                public int dmReserved2;
                public int dmPanningWidth;
                public int dmPanningHeight;
    
            }
            private void button3_Click(object sender, EventArgs e)
            {
                DEVMODE vDevMode = new DEVMODE();
                int i = 0;
                while (EnumDisplaySettings(null, i, ref vDevMode))
                {
                    Console.WriteLine("Width:{0} Height:{1} Color:{2} Frequency:{3}",
                                            vDevMode.dmPelsWidth,
                                            vDevMode.dmPelsHeight,
                                            1 << vDevMode.dmBitsPerPel, vDevMode.dmDisplayFrequency
                                        );
                    i++;
                }
            }
        }
    }
    


    Cordialement,

    • Marqué comme réponse TroxsaEditor dimanche 29 mars 2015 15:17
    dimanche 29 mars 2015 12:01
    Auteur de réponse

Toutes les réponses

  • Bonjour,

    J'ai commencé par regarder les WMI mais sans rien trouvé de probant

    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
         
            [DllImport("user32.dll")]
            public static extern bool EnumDisplaySettings(
                  string deviceName, int modeNum, ref DEVMODE devMode);
            const int ENUM_CURRENT_SETTINGS = -1;
    
            const int ENUM_REGISTRY_SETTINGS = -2;
    
            [StructLayout(LayoutKind.Sequential)]
            public struct DEVMODE
            {
    
                private const int CCHDEVICENAME = 0x20;
                private const int CCHFORMNAME = 0x20;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
                public string dmDeviceName;
                public short dmSpecVersion;
                public short dmDriverVersion;
                public short dmSize;
                public short dmDriverExtra;
                public int dmFields;
                public int dmPositionX;
                public int dmPositionY;
                public ScreenOrientation dmDisplayOrientation;
                public int dmDisplayFixedOutput;
                public short dmColor;
                public short dmDuplex;
                public short dmYResolution;
                public short dmTTOption;
                public short dmCollate;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
                public string dmFormName;
                public short dmLogPixels;
                public int dmBitsPerPel;
                public int dmPelsWidth;
                public int dmPelsHeight;
                public int dmDisplayFlags;
                public int dmDisplayFrequency;
                public int dmICMMethod;
                public int dmICMIntent;
                public int dmMediaType;
                public int dmDitherType;
                public int dmReserved1;
                public int dmReserved2;
                public int dmPanningWidth;
                public int dmPanningHeight;
    
            }
            private void button3_Click(object sender, EventArgs e)
            {
                DEVMODE vDevMode = new DEVMODE();
                int i = 0;
                while (EnumDisplaySettings(null, i, ref vDevMode))
                {
                    Console.WriteLine("Width:{0} Height:{1} Color:{2} Frequency:{3}",
                                            vDevMode.dmPelsWidth,
                                            vDevMode.dmPelsHeight,
                                            1 << vDevMode.dmBitsPerPel, vDevMode.dmDisplayFrequency
                                        );
                    i++;
                }
            }
        }
    }
    


    Cordialement,

    • Marqué comme réponse TroxsaEditor dimanche 29 mars 2015 15:17
    dimanche 29 mars 2015 12:01
    Auteur de réponse
  • Je vous remercie pour cette réponse.

    Pierre STO

    dimanche 29 mars 2015 14:31