gpt4 book ai didi

c# - 如何使用 C# 列出可用的视频模式?

转载 作者:太空狗 更新时间:2023-10-29 20:02:21 33 4
gpt4 key购买 nike

我找到了使用 C++ ( http://www.codeproject.com/KB/tips/resswitch.aspx ) 的很好的示例,但不是在 C# 中。

有人可以帮忙吗?

编辑:列出视频模式的确切函数是:

BOOL CVideoModes::GetAvailableVideoModes(CAvailableVideoModes& modes)
{
modes.SetSize(0, 5);
int i=0;
DEVMODE dm;

while (EnumDisplaySettings(NULL, i, &dm))
{
CVideoMode thismode(dm.dmBitsPerPel, dm.dmPelsWidth,
dm.dmPelsHeight, dm.dmDisplayFrequency);
modes.SetAtGrow(i, thismode);
++i;
}

modes.FreeExtra();

return (i>0);
}

但老实说,我无法理解该 C++ 代码。我在哪里可以找到“thismode”功能?

最佳答案

如果您的意思是视频模式是可用的分辨率,请尝试调用 EnumDisplaySettingsEx

详情可以在这里找到:

http://msdn.microsoft.com/en-us/library/dd162612(VS.85).aspx

列出可用分辨率的小程序:

using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace ListResolutions
{

class Program
{
[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;

}

static void Main(string[] args)
{
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++;
}
}

}

}

关于c# - 如何使用 C# 列出可用的视频模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/744541/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com