├── Cpp ├── CMakeLists.txt └── Screen-Resolution │ ├── CMakeLists.txt │ ├── Screen-Resolution.cpp │ ├── Screen-Resolution.h │ └── res │ ├── logo.ico │ └── logo.rc ├── LICENSE └── README.md /Cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | project ("Screen-Resolution") 3 | add_subdirectory ("Screen-Resolution") 4 | set (Screen-Resolution_VERSION_MAJOR 1) 5 | set (Screen-Resolution_VERSION_MINOR 0) -------------------------------------------------------------------------------- /Cpp/Screen-Resolution/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | add_executable (Screen-Resolution "Screen-Resolution.cpp" "Screen-Resolution.h" "res/logo.rc") 3 | -------------------------------------------------------------------------------- /Cpp/Screen-Resolution/Screen-Resolution.cpp: -------------------------------------------------------------------------------- 1 | #include "Screen-Resolution.h" 2 | 3 | void init_console() 4 | { 5 | SetConsoleTitle("Screen-Resolution v0.1.2 by Hui-Shao"); 6 | std::cout << "\nIniting..." << std::endl; 7 | system("mode con cols=90 lines=30"); 8 | system("color 9f"); 9 | std::cout << " " << std::endl; 10 | } 11 | 12 | void set_resolution(int width, int height) 13 | { 14 | //定义DEVMODE结构体变量 15 | DEVMODE NewDevMode; 16 | 17 | //EnumDisplaySettings函数得到显示设备的一个图形模式设备,通过对该函数一系列的调用可以得到显示设备所有的图形模式信息。 18 | EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &NewDevMode); 19 | 20 | std::cout << "Current: " << NewDevMode.dmPelsWidth << "x" << NewDevMode.dmPelsHeight << " " << NewDevMode.dmDisplayFrequency << "Hz\n" << std::endl; 21 | 22 | //修改下DEVMODE相关成员变量的值 23 | NewDevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; 24 | NewDevMode.dmPelsWidth = width; 25 | NewDevMode.dmPelsHeight = height; 26 | NewDevMode.dmDisplayFixedOutput = 0; 27 | std::cout << "Target: " << NewDevMode.dmPelsWidth << "x" << NewDevMode.dmPelsHeight << std::endl; 28 | ChangeDisplaySettings(&NewDevMode, 0); 29 | std::cout << "\nSetting done." << std::endl; 30 | } 31 | 32 | int main(int argc, char** argv) 33 | { 34 | init_console(); 35 | int w, h; 36 | if (argc == 3) 37 | { 38 | w = atoi(argv[1]); 39 | h = atoi(argv[2]); 40 | set_resolution(w, h); 41 | } 42 | else 43 | { 44 | system("color cf"); 45 | std::cout << "Invalid arguments, have nothing to do...\nUsage: [Width] [Height]" << std::endl; 46 | } 47 | std::cout << "\nPress any key to exit..." << std::endl; 48 | system("pause>nul"); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /Cpp/Screen-Resolution/Screen-Resolution.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | -------------------------------------------------------------------------------- /Cpp/Screen-Resolution/res/logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hui-shao/Screen-Resolution/17e7af75eb776348e75738948ce1207e60ed11d7/Cpp/Screen-Resolution/res/logo.ico -------------------------------------------------------------------------------- /Cpp/Screen-Resolution/res/logo.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON DISCARDABLE "logo.ico" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Hui-Shao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Screen-Resolution / 屏幕分辨率设置 2 | 3 | A program based on C++ to customize screen resolution. 4 | 5 | 一个基于C++的用于调整Windows系统分辨率的小程序 6 |

7 | 8 | 9 | 10 | 11 |

12 | 13 | ### 主要功能 14 | 15 | 接受传入参数,并将传入的参数值设置为分辨率。要求传入参数在“当前系统所支持的分辨率”列表内 16 | 17 | ``` 18 | Usage: [Width] [Height] 19 | ``` 20 | 21 | 示例: 22 | 23 | ```powershell 24 | Screen-Resolution.exe 1920 1080 25 | ``` 26 | 27 | ### 使用实例 28 | 29 | - 可以设置为快捷方式放置在桌面 30 | - 可以加入开机自启,实现自动调整分辨率 31 | 32 | 操作步骤如下: 33 | 34 | 1. `右键-新建快捷方式`,填写程序路径, 并在结尾加上传入参数,例如:`F:\Screen-Resolution.exe 1920 1080` 35 | 2. 设置开机自启。按下 `Win + R` 打开“运行”,输入 `shell:startup` 并执行,这将会打开 “启动” 文件夹。将快捷方式复制进刚才打开的目录里即可。 36 | 37 | ### 分支说明 38 | 39 | 该分支(master)基于C++进行开发, 原有的Python版本迁移至python分支(已弃用) --------------------------------------------------------------------------------