特定显示器调整主副屏、方向、位置
2016-12-27 10:09
148 查看
inline char* UnicodeToAnsi(const wchar_t* szStr)
{
int nLen = WideCharToMultiByte(CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL);
if (nLen == 0){
return NULL;
}
char* pResult = new char[nLen];
WideCharToMultiByte(CP_ACP, 0, szStr, -1, pResult, nLen, NULL, NULL);
return pResult;
}
extern “C” __declspec(dllexport) bool ToSetPrimaryDisPlay(){
//获取到特定名称的显示器,在这里MONITOR\IMR00是特定的显示器硬件名称
if (strstr(UnicodeToAnsi(DisPlay_Info.DeviceID), “MONITOR\IMR00”) != NULL || strstr(UnicodeToAnsi(DisPlay_Info.DeviceID), “MONITOR\IVR00”) != NULL)
{
//枚举显示器属性,
EnumDisplaySettings(DisplayDevice.DeviceName, ENUM_CURRENT_SETTINGS, &deviceMode);
//以下标识符,代表本次操作更新注册表;
DWORD dwFlags = CDS_UPDATEREGISTRY;
}
{
int nLen = WideCharToMultiByte(CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL);
if (nLen == 0){
return NULL;
}
char* pResult = new char[nLen];
WideCharToMultiByte(CP_ACP, 0, szStr, -1, pResult, nLen, NULL, NULL);
return pResult;
}
extern “C” __declspec(dllexport) bool ToSetPrimaryDisPlay(){
DEVMODE deviceMode; deviceMode.dmSize = sizeof(DEVMODE); deviceMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_POSITION | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS; DISPLAY_DEVICE DisplayDevice; DISPLAY_DEVICE DisPlay_Info; ZeroMemory(&DisplayDevice, sizeof(DISPLAY_DEVICE)); DisplayDevice.cb = sizeof(DisplayDevice); ZeroMemory(&DisPlay_Info, sizeof(DISPLAY_DEVICE)); DisPlay_Info.cb = sizeof(DisPlay_Info); int old_Coord_X = 0; int old_Coord_Y = 0; SetDisplayConfig(0, NULL, 0, NULL, (SDC_APPLY | SDC_TOPOLOGY_EXTEND)); for (int i = 0; EnumDisplayDevices(NULL, i, &DisplayDevice, 0); i++) { //EnumDisplayDevices函数是用来枚举显示设备的,第一个调用会得到所有显示器, //将第一次枚举得到的显示器名字作为参数再传入EnumDisplayDevices,将会得到 //显示器的硬件名称 EnumDisplayDevices(DisplayDevice.DeviceName, 0, &DisPlay_Info, 0);
//获取到特定名称的显示器,在这里MONITOR\IMR00是特定的显示器硬件名称
if (strstr(UnicodeToAnsi(DisPlay_Info.DeviceID), “MONITOR\IMR00”) != NULL || strstr(UnicodeToAnsi(DisPlay_Info.DeviceID), “MONITOR\IVR00”) != NULL)
{
//枚举显示器属性,
EnumDisplaySettings(DisplayDevice.DeviceName, ENUM_CURRENT_SETTINGS, &deviceMode);
//以下标识符,代表本次操作更新注册表;
DWORD dwFlags = CDS_UPDATEREGISTRY;
//调整顺序按照调整主副屏、调整横竖屏、调整位置的操作进行, //判断特定显示器是否为主显示器; if (DisplayDevice.StateFlags &DISPLAY_DEVICE_PRIMARY_DEVICE){ cout << "需要调整主副屏" << endl; old_Coord_X = deviceMode.dmPosition.x; old_Coord_Y = deviceMode.dmPosition.y; deviceMode.dmPosition.x = -1920; deviceMode.dmPosition.y = 0; if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettingsEx(DisplayDevice.DeviceName, &deviceMode, NULL, dwFlags, NULL)){ //return false; cout << "设置主副屏失败" << endl; } } //判断特定显示器是否需要调整方向 if (deviceMode.dmDisplayOrientation != DMDO_90){ cout << "需要调整横竖屏" << endl; deviceMode.dmDisplayOrientation = DMDO_90; if (deviceMode.dmPelsHeight != 1080){ int temp = deviceMode.dmPelsHeight; deviceMode.dmPelsHeight = deviceMode.dmPelsWidth; deviceMode.dmPelsWidth = temp; } if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettingsEx(DisplayDevice.DeviceName, &deviceMode, NULL, CDS_UPDATEREGISTRY, NULL)){ cout << "设置横竖屏失败" << endl; } } //判断特定显示器是否需要调整位置 if (deviceMode.dmPosition.x < 0){ cout << "需要调整位置" << endl; deviceMode.dmPosition.x = GetSystemMetrics(SM_CXSCREEN); deviceMode.dmPosition.y = 0; if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettingsEx(DisplayDevice.DeviceName, &deviceMode, NULL, CDS_UPDATEREGISTRY, NULL)){ //ChangeDisplaySettingsEx(0, 0, 0, 0, 0); cout << "移动屏幕失败" << endl; } } } } return true;
}
相关文章推荐
- 行内元素垂直方向位置调整的一些感悟和困惑
- view大小、方向、位置调整函数小结
- Android 程式开发:(七)适应屏幕的方向 —— 7.3重新调整尺寸和位置
- 根据点击的位置调整精灵方向(弧度)
- google map 定位当前位置和根据手机的方向调整在地图的方向
- UIView设置为自动适配屏幕时,当用户旋转设备的时候,会调用layoutSubviews方法,我们只需重写 这个方法,然后判断用户屏幕的方向。在调整每个空间的位置即可。
- 调整TiddlyPedia图标的位置。
- 水晶报表动态调整字段位置
- iOS学习笔记——输入法切换时动态调整UITextField的位置
- Android 拖动控件方法(利用onTouch事件,动态调整控件位置)
- Cell调整separaLine的位置
- 根据显示器分辨率进行的调整的Javascript脚本
- js浮动广告框(可根据屏幕大小自动调整位置)
- 在文件的特定位置追加内容和读取文件特定内容
- 调整leftBarButtonItem的位置
- 调整ViewState的位置,让你的asp.net页面对搜索引擎更友好
- frame框架怎么实现读取某个网页的特定位置
- Visual Stdio的解决方案资源管理器位置调整
- 成功,不是你所站的位置,而是你要去的方向
- Lucene/Solr搜索引擎开发笔记 - 写作方向调整