工控编程吧
标题:
上位机MFC如何设置显示属性
[打印本页]
作者:
qq263946146
时间:
2019-8-18 15:22
标题:
上位机MFC如何设置显示属性
ChangeDisplaySettings可以用于设置显示属性。
(, 下载次数: 2)
上传
点击文件名下载附件
如上图,我们可以在界面上准备三个组合框,
关联控件变量后,初始化它们
CComboBox m_ctrlPixels;
CComboBox m_ctrlDispalyFrequencry;
CComboBox m_ctrlBitsPerPixel;
// TODO: Add extra initialization here
m_ctrlBitsPerPixel.AddString(_T("16 位"));
m_ctrlBitsPerPixel.AddString(_T("32 位"));
m_ctrlPixels.AddString(_T("600×800 像素"));
m_ctrlPixels.AddString(_T("1024×768 像素"));
m_ctrlDispalyFrequencry.AddString(_T("60 赫兹"));
m_ctrlDispalyFrequencry.AddString(_T("75 赫兹"));
DEVMODE DevMode;
//获得显示属性
EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &DevMode);
//颜色深度
if (DevMode.dmBitsPerPel == 16)
{
m_ctrlBitsPerPixel.SetCurSel(0);
}
else if (DevMode.dmBitsPerPel == 32)
{
m_ctrlBitsPerPixel.SetCurSel(1);
}
//分辨率
if ((DevMode.dmPelsWidth == 800) && (DevMode.dmPelsHeight == 600))
{
m_ctrlPixels.SetCurSel(0);
}
else
m_ctrlPixels.SetCurSel(1);
//刷新率
if (DevMode.dmDisplayFrequency == 60)
{
m_ctrlDispalyFrequencry.SetCurSel(0);
}
else if (DevMode.dmDisplayFrequency == 75)
{
m_ctrlDispalyFrequencry.SetCurSel(1);
}
复制代码
然后就可以通过按钮,调用下面 的代码,实现设置。
void CGkbc8Dlg::OnTest()
{
DEVMODE DevMode;
//颜色深度
if (m_ctrlBitsPerPixel.GetCurSel() == 0)
{
DevMode.dmBitsPerPel = 16;
}
else if (m_ctrlBitsPerPixel.GetCurSel() == 1)
{
DevMode.dmBitsPerPel = 32;
}
//分辨率
if (m_ctrlPixels.GetCurSel() == 0)
{
DevMode.dmPelsWidth = 800;
DevMode.dmPelsHeight = 600;
}
else if (m_ctrlPixels.GetCurSel() == 1)
{
DevMode.dmPelsWidth = 1024;
DevMode.dmPelsHeight = 768;
}
//刷新率
if (m_ctrlDispalyFrequencry.GetCurSel() == 0)
{
DevMode.dmDisplayFrequency = 60;
}
else if (m_ctrlDispalyFrequencry.GetCurSel() == 1)
{
DevMode.dmDisplayFrequency = 75;
}
DevMode.dmSize = sizeof(DEVMODE);
DevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT |
DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
//设置显示属性
LONG nResult = (&DevMode, 0);
if (nResult == DISP_CHANGE_SUCCESSFUL)
{
//用新的设置参数更新注册表
ChangeDisplaySettings(&DevMode, CDS_UPDATEREGISTRY);
AfxMessageBox(_T("设置显示属性成功。"));
}
else
{
//恢复默认设置
ChangeDisplaySettings(NULL, 0);
AfxMessageBox(_T("设置显示属性失败。"));
}
}
复制代码
(, 下载次数: 0)
上传
点击文件名下载附件
[MFC408]1[/MFC408]
[weixinlianxi]1[/weixinlianxi]
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4