EnumDisplayDevices 到底怎么用?

yanjing_mail 2008-09-08 09:24:29
我想使用EnumDisplayDevices 获取我的电脑上连接的两个显示器。然后用EnumDisplaySettings获取两个屏幕的分辨率。
这两个函数怎么用?
...全文
2028 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jingzhongrong 2008-09-08
  • 打赏
  • 举报
回复
::EnumDisplayDevices(...);
cnzdgs 2008-09-08
  • 打赏
  • 举报
回复
这个函数就是获取系统中显示设备的信息。
如果自己找不出错误,就把出错的代码贴出来。
starytx 2008-09-08
  • 打赏
  • 举报
回复
贴一个罗列分辨率的代码
//---------------罗列系统支持的分辨率----------------------------
DEVMODE *lpDevMode;
lpDevMode=new DEVMODE;
int i=0;
CString Str[500];
CString str;
BOOL Result=EnumDisplaySettings(NULL,i,lpDevMode);
while(Result)
{
str.Format("%d",lpDevMode->dmPelsWidth);

lpDevMode=new DEVMODE;
Result=EnumDisplaySettings(NULL,++i,lpDevMode);
Str[i]=str;
}
delete lpDevMode;
for(int j=0;j<500;j++)
{

OutputDebugString(Str[i]);//显示横向像素值
}

scq2099yt 2008-09-08
  • 打赏
  • 举报
回复
参数过多就是说对于该函数多余四个参数
scq2099yt 2008-09-08
  • 打赏
  • 举报
回复
up
yanjing_mail 2008-09-08
  • 打赏
  • 举报
回复
提示参数过多。
怎么回事?
flm007 2008-09-08
  • 打赏
  • 举报
回复
汗!~MSDN都没翻译出来了,看来俺来强分又来晚了!
gaoxiaowei 2008-09-08
  • 打赏
  • 举报
回复
函数原型:BOOL EnumDisplaySettings(LPCTSTR lpszDeviceName, DWORD iModeNum, LPDEVMODE lpDevMode);

参数:

lpszDeviceName:指向一个以null的结尾的字符串,该字符串指定了显示设备。此函数将获得该显示设备的图形模式信息。该参数可以为NULL。NULL值表明调用线程正运行在计算机的当前显示设备上。如果lpszDeviceName为NULL,该字符串的形式为\\.\displayx,其中x的值可以为1、2或3。对于Windows 95和Windows 98,lpszDeviceName必须为NULL。

iModeNum:表明要检索的信息类型,该值可以是一个图形模式索引,也可以是下列一值:

ENUM_CURRENT_SETTINGS:检索显示设备的当前设置。

ENUM_REGISTRY_SETTINGS:检索当前存储在注册表中的显示设备的设置。

图形模式索引值从零开始,要得到一个显示设备的所有图形模式信息,可以一系列地调用EnumDisplaySettings函数,并且iModeNum显为一个非零值时,则函数返回的信息是最近一次使用iModeNum置为零调用该函数时存储的信息。

lpDevMode:DEVMODE结构的指针,该结构存储指定图形模式的信息,在调用EnumDisplaySettings之前,设置dmSize为sizeof(DEVMODE),并且以字节为单位,设置dmDriveExtra元素为接收专用驱动数据可用的附加空间。

EnumDisplaySettings函数设置如下五个DEVMODE元素的值:dmBitsPerpel、dmPelsWidth、dmPelsHeight、dmDisplayFlags、dmDisplayFrequency。

返回值:如果成功,返回非零值;如果失败,返回零。

Windows NT:若想获得更多错误信息,请调用GetLastError函数。

注释:如果iModeNum大于显示设备最后的图形模式索引,那么函数就会失败,如同在iModeNum参数中描述的那样,使用这种方法可以枚举显示设备所有的图形模式。
yjgx007 2008-09-08
  • 打赏
  • 举报
回复
MSDN不是讲得很清楚吗?

The EnumDisplayDevices function lets you obtain information about the display devices in a system.

BOOL EnumDisplayDevices(
LPCTSTR lpDevice, // device name
DWORD iDevNum, // display device
PDISPLAY_DEVICE lpDisplayDevice, // device information
DWORD dwFlags // reserved
);
Parameters
lpDevice
[in] Pointer to the device name. If NULL, function returns information for the display adapter(s) on the machine, based on iDevNum. For more information, see Remarks.
iDevNum
[in] Index value that specifies the display device of interest.
The operating system identifies each display device with an index value. The index values are consecutive integers, starting at 0. If a system has three display devices, for example, they are specified by the index values 0, 1, and 2.

lpDisplayDevice
[out] Pointer to a DISPLAY_DEVICE structure that receives information about the display device specified by iDevNum.
Before calling EnumDisplayDevices, you must initialize the cb member of DISPLAY_DEVICE to the size, in bytes, of DISPLAY_DEVICE.

dwFlags
This parameter is currently not used and should be set to zero.


Getting Information on a Display Monitor
The following code sample shows how to use EnumDisplayDevices to get information on a display monitor.

BOOL GetDisplayMonitorInfo(int nDeviceIndex, LPSTR lpszMonitorInfo)
{
FARPROC EnumDisplayDevices;
HINSTANCE hInstUser32;
DISPLAY_DEVICE DispDev;
char szSaveDeviceName[32];
BOOL bRet = TRUE;

hInstUser32 = LoadLibrary("User32.DLL");
if (!hInstUser32) return FALSE;

// Get the address of the EnumDisplayDevices function
EnumDisplayDevices = (FARPROC)GetProcAddress(hInstUser32,"EnumDisplayDevicesA");
if (!EnumDisplayDevices) {
FreeLibrary(hInstUser32);
return FALSE;
}

ZeroMemory(&DispDev, sizeof(DISPLAY_DEVICE));
DispDev.cb = sizeof(DISPLAY_DEVICE);

// After the first call to EnumDisplayDevices,
// DispDev.DeviceString is the adapter name
if (EnumDisplayDevices(NULL, nDeviceIndex, &DispDev, 0)) {
lstrcpy(szSaveDeviceName, DispDev.DeviceName);

// After second call, DispDev.DeviceString is the
// monitor name for that device
EnumDisplayDevices(szSaveDeviceName, 0, &DispDev, 0);

lstrcpy(lpszMonitorInfo, DispDev.DeviceString);
} else {
bRet = FALSE;
}

FreeLibrary(hInstUser32);

return bRet;
}
gaoxiaowei 2008-09-08
  • 打赏
  • 举报
回复
函数原型:BOOL EnumDisplayDevices(PVOID Unused, DWORD iDevNum, PDISPLAY_DEVICE lpDisplayDevice, DWORD dwFlags);

参数:

Unused:该参数当前不用,应设为Null。

iDevNum:指定感兴趣的显示设备的索引值,操作系统通过索引值确定每一个显示设备。索引值是连续的整数。从0开始,例如:如果一个系统有三个显示设备,那么它们的索引值为0、1、2。

lpdisplayDevice:DISPLAY_DEVICE结构的指针,该结构检索由iDevNum指定的显示设备的信息,在调用EnumDisplayDevices之前,必须以字节为单位把DISPLAY_DEVICE结构中cb元素初始化为DISPLAY_DEVICE结构的大小。

dwFlags:约束函数行为的一组标志,当前没有定义标志。

返回值:如果成功,则返回值非零;如果失败,则返回值为零;如果iDevNum大于最大的设备索引,则函数失败。

注释:为了查询系统的所有显示设备,在一个循环中调用该函数开始时iDevNum设为0,并增加iDevNum,直到函数失败。

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧