Change Screen Resolution in Windows using C++
主要使用 Windows API
ChangeDisplaySettings
及
EnumDisplaySettings
首先使用 EnumDisplaySettings 取得目前的螢幕設定值
然後修改解析度的寬高
最後使用 ChangeDisplaySettings 更新螢幕設定值
=== 程式範例
#include "windows.h"
#include <string>
#include <iostream>
int main(int argc, char* argv[])
{
if (argc == 3)
{
try
{
unsigned long width = std::stoul(argv[1]);
unsigned long height = std::stoul(argv[2]);
DEVMODE *dm = new DEVMODE();
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, dm);
dm->dmPelsWidth = width;
dm->dmPelsHeight = height;
ChangeDisplaySettings(dm, CDS_UPDATEREGISTRY);
}
catch (std::invalid_argument e)
{
std::cout << e.what() << std::endl;
}
}
return 0;
}
=== 資料來源
How to change screen resolution using QT, OpenGL, C++, and Linux?
http://stackoverflow.com/questions/11387724/how-to-change-screen-resolution-using-qt-opengl-c-and-linux
How to change screen resolution in Windows using Qt
http://eastfist.com/qt_tutorials/how-to-change-screen-resolution-in-windows-using-qt/
ChangeDisplaySettings function
https://msdn.microsoft.com/en-us/library/dd183411(VS.85).aspx
沒有留言:
張貼留言