ChangeDisplaySettings可以用于设置显示属性。
上位机MFC如何设置显示属性
如上图,我们可以在界面上准备三个组合框,
关联控件变量后,初始化它们
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("设置显示属性失败。"));
- }
- }
复制代码
上位机VC MFC程序开发精典实例大全源码与视频讲解配套下载408例 经历1年的编程与录制点击进入查看
如果您认可,可联系功能定制! 如果您着急,充值会员可直接联系发您资料!
|