Last active
February 18, 2017 07:20
-
-
Save Omochin/f764aaac14d4f2dfd902cc9b4a6084fd to your computer and use it in GitHub Desktop.
引数に2つの解像度を指定して切り替えるC++コード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <Windows.h> | |
int main(int argc, char* argv[]) { | |
if (argc != 6) | |
{ | |
printf("Please arguments: monitorNo width1 height1 width2 height2\n"); | |
getchar(); | |
return 0; | |
} | |
DWORD monitorNo = std::stoi(argv[1]); | |
DWORD width = std::stoi(argv[2]); | |
DWORD height = std::stoi(argv[3]); | |
DWORD width2 = std::stoi(argv[4]); | |
DWORD height2 = std::stoi(argv[5]); | |
DISPLAY_DEVICE device; | |
device.cb = sizeof(DISPLAY_DEVICE); | |
EnumDisplayDevices(NULL, monitorNo, &device, NULL); | |
DEVMODE checkMode; | |
EnumDisplaySettings(device.DeviceName, ENUM_CURRENT_SETTINGS, &checkMode); | |
if (checkMode.dmPelsWidth == width && checkMode.dmPelsHeight == height) | |
{ | |
width = width2; | |
height = height2; | |
} | |
DEVMODE submitMode = { 0 }; | |
submitMode.dmSize = sizeof(submitMode); | |
submitMode.dmPelsWidth = width; | |
submitMode.dmPelsHeight = height; | |
submitMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; | |
DWORD ret = ChangeDisplaySettingsEx(device.DeviceName, &submitMode, NULL, 0, NULL); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment