日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

关于获取多个屏幕分辨率以及进行一些设置

發(fā)布時間:2025/3/15 编程问答 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于获取多个屏幕分辨率以及进行一些设置 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Windows下提示顯示器信息主要通過兩個函數(shù)實(shí)現(xiàn)。一個是EnumDisplayDevices(), 另一個是EnumDisplayMonitors().
EnumDisplayDevices()枚舉所有顯示設(shè)備,而EnumDisplayMonitors枚舉的是所有顯示器。
顯示設(shè)備和顯示器不一樣,比如顯卡算顯示設(shè)備,但是不是顯示器。
EnumDisplayMonitors()還會枚舉出不可見的偽顯示器,如果只是想得到實(shí)際的顯示器數(shù)目的話可以用GetSystemMetrics(SM_CMONITORS),該函數(shù)不包括虛擬顯示器。
MonitorInfoex 和MonitorInfo 在這兩個結(jié)構(gòu)中保存著相應(yīng)顯示器的相關(guān)信息,如坐標(biāo)、是否為主顯示器等 GetMonitorInfo ( )  取得指定顯示器的相關(guān)信息,如物理顯示區(qū)大小等
MonitorFromPoint ( )  取得指定點(diǎn)所在的顯示器句柄
MonitorFromRect ( )  取得指定矩形所在的顯示器句柄
MonitorFromWindow( )  取得指定窗口所在的顯示器句柄
MonitorEnumProc( ) 當(dāng)應(yīng)用程序調(diào)用EnumDisplayMonitors ( )查詢顯示器個數(shù)時,系統(tǒng)自動為每一個顯示器調(diào)用一次該函數(shù)。應(yīng)用程序可以依此判斷顯示器的個數(shù)、位置及顯示區(qū)域的大小等信息
函數(shù)名:MonitorEnumProc()
輸入?yún)?shù):HMONITOR hMonitor ---顯示器句柄
????????? HDC hdcMonitor? ----顯示器DC句柄
???? ?? LPRECT lprcMonitor-----
???? ?? LPARAM dwData-----EnumDisplayMonitors傳來的數(shù)據(jù)
返回:bool
功能:若返回為真,EnumDisplayMonitors繼續(xù)枚舉,
????? 若返回為假,EnumDisplayMonitors停止枚舉,從而獲得顯示器信息
MonitorAdapter.h #include <atlstr.h> #include <vector> #include <WinDef.h> #include <tchar.h> using std::vector;using namespace std;#define MAX_MONITOR_NAME 256static std::vector<HMONITOR> g_hMonitorGroup; // 顯示器模式信息 typedef struct MonitorModeInfo_t {unsigned int m_nWidth; unsigned int m_nHeight;MonitorModeInfo_t(int nWidth, int nHeight) : m_nWidth(nWidth), m_nHeight(nHeight) {} }MonitorModeInfo;// 顯示器信息 struct MonitorInfo {TCHAR szDevice[MAX_MONITOR_NAME]; // 顯示器名稱std::vector<MonitorModeInfo> m_vecModeInfo; // 當(dāng)前名稱的顯示器支持的分辨率模式 };typedef std::vector<MonitorInfo> VEC_MONITORMODE_INFO; // 所有的顯示器信息 class MonitorAdapter { public:MonitorAdapter();~MonitorAdapter();// 回調(diào)函數(shù)static int CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdc,LPRECT lpRMonitor,LPARAM dwData);// 得到所有顯示器的名稱void GetAllMonitorName(VEC_MONITORMODE_INFO& m_vecMonitorListInfo);// 得到所有顯示器的模式void GetAllDisplayMode(VEC_MONITORMODE_INFO& m_vecMonitorListInfo);//得到屏幕當(dāng)前分辨率void GetCurrentReselotion(int& nWidth,int& nHeight,int& nFreq,int& nBits);//根據(jù)屏幕ID取獲取屏幕的對應(yīng)分辨率void GetCurrentReselotion(LPCWSTR lpszDeviceName, int& nWidth, int& nHeight, int& nFreq, int& nBits);//修改分辨率int ChangMonitorReselotion(HMONITOR hMonitor,const int nWidth,const int nHight,const int nFre,const int nColorBits); };
MonitorAdapter.cpp #include "stdafx.h" #include "MonitorAdapter.h"MonitorAdapter::MonitorAdapter(void) { }MonitorAdapter::~MonitorAdapter(void) { }int CALLBACK MonitorAdapter::MonitorEnumProc(HMONITOR hMonitor, HDC hdc,LPRECT lpRMonitor,LPARAM dwData) {g_hMonitorGroup.push_back(hMonitor);return 1; }// 得到所有顯示器的名稱 void MonitorAdapter::GetAllMonitorName(VEC_MONITORMODE_INFO& vecMonitorListInfo) {g_hMonitorGroup.clear();::EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, 0);//vector<HMONITOR>::iterator ithMoniter = g_hMonitorGroup.begin();for(int i = 0; i < g_hMonitorGroup.size();i++){MONITORINFOEX mixTemp;memset(&mixTemp, 0, sizeof(MONITORINFOEX));mixTemp.cbSize = sizeof(MONITORINFOEX);GetMonitorInfo(g_hMonitorGroup[i], &mixTemp);VEC_MONITORMODE_INFO::iterator itBeg = vecMonitorListInfo.begin();VEC_MONITORMODE_INFO::iterator itEnd = vecMonitorListInfo.end();for(; itBeg != itEnd; ++itBeg){if( 0 == _tcscmp(mixTemp.szDevice, itBeg->szDevice)){break;}}//沒有在列表中找到,則需要添加if (itBeg == itEnd) {MonitorInfo tmpMonitorInfo;_tcscpy_s(tmpMonitorInfo.szDevice, sizeof(tmpMonitorInfo.szDevice), mixTemp.szDevice);vecMonitorListInfo.push_back(tmpMonitorInfo);}} }// 得到所有顯示器的模式 void MonitorAdapter::GetAllDisplayMode(VEC_MONITORMODE_INFO& vecMonitorListInfo) {GetAllMonitorName(vecMonitorListInfo);bool bRetVal;DEVMODE devmode;VEC_MONITORMODE_INFO::iterator itBeg = vecMonitorListInfo.begin();VEC_MONITORMODE_INFO::iterator itEnd = vecMonitorListInfo.end();for (NULL; itBeg != itEnd; ++itBeg){int iMode = 0;do{bRetVal = ::EnumDisplaySettings(itBeg->szDevice, iMode, &devmode);iMode++;if (bRetVal){bool bFind = false;vector<MonitorModeInfo>::iterator itBeg_Mode = itBeg->m_vecModeInfo.begin();vector<MonitorModeInfo>::iterator itEnd_Mode = itBeg->m_vecModeInfo.end();for (NULL; itBeg_Mode != itEnd_Mode; ++itBeg_Mode){// 如果已經(jīng)在列表中找到,則結(jié)束本次循環(huán)if ((itBeg_Mode->m_nWidth == devmode.dmPelsWidth) && (itBeg_Mode->m_nHeight == devmode.dmPelsHeight)){bFind = true;break;}// 插入數(shù)據(jù)時,從 大到小排列 (按windows 分辨率設(shè)置,優(yōu)先比較 寬) if ((itBeg_Mode->m_nWidth < devmode.dmPelsWidth) ||((itBeg_Mode->m_nWidth == devmode.dmPelsWidth) && (itBeg_Mode->m_nHeight < devmode.dmPelsHeight))){ break;}}if(!bFind){if (itBeg_Mode == itEnd_Mode){itBeg->m_vecModeInfo.push_back(MonitorModeInfo(devmode.dmPelsWidth, devmode.dmPelsHeight)); }else{itBeg->m_vecModeInfo.insert(itBeg_Mode, MonitorModeInfo(devmode.dmPelsWidth, devmode.dmPelsHeight)); }}}}while (bRetVal); } }int MonitorAdapter::ChangMonitorReselotion(HMONITOR hMonitor,const int nWidth,const int nHight,const int nFre,const int nColorBits) {if ( NULL == hMonitor ){return -1;}MONITORINFOEX mi;mi.cbSize = sizeof(mi);GetMonitorInfo( hMonitor , &mi);DEVMODE DeviceMode;ZeroMemory(&DeviceMode, sizeof(DEVMODE));DeviceMode.dmSize = sizeof(DEVMODE); BOOL bFlag = TRUE;bFlag = EnumDisplaySettings(mi.szDevice, ENUM_CURRENT_SETTINGS, &DeviceMode);if ( bFlag != TRUE ){return -1;} if (DeviceMode.dmPelsWidth == nWidth && DeviceMode.dmPelsHeight == nHight ){return 0;}DeviceMode.dmDisplayFlags = 0;DeviceMode.dmPelsWidth= nWidth; DeviceMode.dmPelsHeight = nHight;DeviceMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY ;int nRet = ChangeDisplaySettingsEx(mi.szDevice, &DeviceMode, NULL, CDS_GLOBAL | CDS_NORESET | CDS_UPDATEREGISTRY, NULL);if (DISP_CHANGE_BADMODE == nRet){ChangeDisplaySettingsEx(mi.szDevice, &DeviceMode, NULL, CDS_GLOBAL | CDS_NORESET | CDS_UPDATEREGISTRY, NULL); }if ( DISP_CHANGE_SUCCESSFUL == nRet ){return 0;}return -1; }void MonitorAdapter::GetCurrentReselotion(int& nWidth,int& nHeight,int& nFreq,int& nBits) {DEVMODE DeviceMode;EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &DeviceMode);nWidth = DeviceMode.dmPelsWidth;nHeight = DeviceMode.dmPelsHeight;nFreq = DeviceMode.dmDisplayFrequency;nBits = DeviceMode.dmBitsPerPel; }void MonitorAdapter::GetCurrentReselotion(LPCWSTR lpszDeviceName, int& nWidth, int& nHeight, int& nFreq, int& nBits) {DEVMODE DeviceMode;EnumDisplaySettings(lpszDeviceName, ENUM_CURRENT_SETTINGS, &DeviceMode);nWidth = DeviceMode.dmPelsWidth;nHeight = DeviceMode.dmPelsHeight;nFreq = DeviceMode.dmDisplayFrequency;nBits = DeviceMode.dmBitsPerPel; }
test #include "stdafx.h" #include "MonitorAdapter.h"int _tmain(int argc, _TCHAR* argv[]) {MonitorAdapter m_monitorAdapter; //顯示器VEC_MONITORMODE_INFO vecMointorListInfo;m_monitorAdapter.GetAllDisplayMode(vecMointorListInfo);int nWidth = 0, nHeight = 0, nFreq = 0, nBits = 0;VEC_MONITORMODE_INFO::iterator itBeg = vecMointorListInfo.begin();for (int i = 0; i < vecMointorListInfo.size();i++){//得到當(dāng)前顯示器分辨率 刷新率 色位m_monitorAdapter.GetCurrentReselotion(itBeg->szDevice, nWidth, nHeight, nFreq, nBits);itBeg++;nWidth = 0, nHeight = 0, nFreq = 0, nBits = 0;}return 0; }

總結(jié)

以上是生活随笔為你收集整理的关于获取多个屏幕分辨率以及进行一些设置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。