使用EnumDisplaySettings获取屏幕颜色数

​编者:李国帅​


背景原因:

判断当前屏幕的颜色数,因为远程桌面播放视频时,将播放格式限定为只能是16位色。

 

所需资源:

VC

 

解决方案:

int m_nBitsPerPel;       //获得系统颜色数
int m_nDisplayFrequency;//至少包含分辨率和刷新率
m_nBitsPerPel = 16;
m_nDisplayFrequency = 70;

DEVMODE dmDevMode;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS,&dmDevMode);
m_nBitsPerPel = dmDevMode.dmBitsPerPel;
m_nDisplayFrequency = dmDevMode.dmDisplayFrequency;

if(m_nBitsPerPel > 16)
{
LONG nConfirm = IDNO;
LONG nCurLang =((CXXRunApp*)AfxGetApp())->m_nCurLang;
if(nCurLang == 0)
{
nConfirm = MessageBox(L"客户端在16位显示模式下有较好的性能,是否要改变?",L"提示",MB_YESNO);
}
else
{
nConfirm = MessageBox(L"Client have better performance in 16 BitsPerPel, will you change to it?",L"Tip",MB_YESNO);
}
if(nConfirm == IDYES)
{//如果颜色数>16,更改为16色深显示。
memset(&dmDevMode, 0,sizeof(dmDevMode));
dmDevMode.dmBitsPerPel=16;
dmDevMode.dmDisplayFrequency=m_nDisplayFrequency;
dmDevMode.dmSize=sizeof(DEVMODE);
dmDevMode.dmFields=DM_BITSPERPEL|DM_DISPLAYFREQUENCY;
ChangeDisplaySettings(&dmDevMode, CDS_FULLSCREEN);
}
}