2012-04-06 6 views

答えて

5

ちょうどこれを使用:

foreach (DisplayMode mode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes) { 
    //mode.whatever (and use any of avaliable information) 
} 

しかし、あなたはそのaswelが含まれ、または何らかのフィルタリングを行う可能性がありますので、それはまた、accoundのrefrash率にかかるので、それは、あなたにいくつかの重複を与えるだろう。

3

私はXNAの最新バージョンではありませんが、すばやく簡単な機能はないと思いました。古いWinForms APIを使用する方法がありますが、個人的には他のアプリケーションとリンクしたくないので、最も簡単な方法はネイティブ関数を使用することです。

[DllImport("user32.dll")] 
private static extern bool EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode); 

[DllImport("user32.dll")] 
private static extern int GetSystemMetrics(int nIndex); 

そして最後に、私達の機能はすべてを一覧表示する:我々はまた、我々が使用する2つのネイティブ関数を定義する必要が

[StructLayout(LayoutKind.Sequential)] 
internal 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 int 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; 
} 

まず、使用されるネイティブの構造体を定義します画面の解像度と現在の画面解像度を取得するには:

public static List<string> GetScreenResolutions() 
{ 
    var resolutions = new List<string>(); 

    try 
    { 
     var devMode = new DEVMODE(); 
     int i = 0; 

     while (EnumDisplaySettings(null, i, ref devMode)) 
     { 
      resolutions.Add(string.Format("{0}x{1}", devMode.dmPelsWidth, devMode.dmPelsHeight)); 
      i++; 
     } 

     resolutions = resolutions.Distinct(StringComparer.InvariantCulture).ToList(); 
    } 
    catch (Exception ex) 
    { 
     Console.WriteLine("Could not get screen resolutions."); 
    } 

    return resolutions; 
} 

public static string GetCurrentScreenResolution() 
{ 
    int width = GetSystemMetrics(0x00); 
    int height = GetSystemMetrics(0x01); 

    return string.Format("{0}x{1}", width, height); 
} 
+1

受け入れられた答えが行く方法ですが、XNAとは独立した方法を説明するため+1してください。 –

関連する問題