English 中文(简体)
• 在XNA找到得到支持的屏幕决议?
原标题:Get the supported screen resolutions in XNA?
  • 时间:2012-04-06 05:02:49
  •  标签:
  • c#
  • .net
  • xna

我如何能够在XNA获得得到支持的屏幕决议? 就像你改变窗户中的屏幕分辨率,而不是给你一份所有可能选择的清单一样,它只给你们少数。

最佳回答

仅此用:

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

但是,它会给你留下几个重复之处,因为它也考虑到rash的 re失行为率,因此你可能包括这种wel,或做一些过滤。

问题回答

我不喜欢与意大利-日本合作,但我不认为是迅速而容易地运作。 采用老的温树图象是一种方法,但是,由于我个人不想与其他应用联系起来,最容易的是利用土著职能。

第一,界定将使用的土质:

[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;
}

我们还需要确定我们将使用的两种本土职能:

[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);

最后,我们的职能是列出所有屏幕决议,以及获得目前屏幕解决的职能:

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);
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签