多屏显示器开启与关闭

// this is only necessary if the app is supporting win95
#if !defined(COMPILE_MULTIMON_STUBS) && (WINVER < 0x0500)
//
// this needs to be here so that we get the wrapper stubs that deal with win95 platforms
#define COMPILE_MULTIMON_STUBS
#include "multimon.h"
//
#endif // !defined(COMPILE_MULTIMON_STUBS) && (WINVER < 0x0500)

void DetachDisplay()
{
 BOOL            FoundSecondaryDisp = FALSE;
 DWORD           DispNum = 0;
 DISPLAY_DEVICE  DisplayDevice;
 LONG            Result;
 TCHAR           szTemp[200];
 int             i = 0;
 DEVMODE   defaultMode;

 // initialize DisplayDevice
 ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
 DisplayDevice.cb = sizeof(DisplayDevice);

 // get all display devices
 while (EnumDisplayDevices(NULL, DispNum, &DisplayDevice, 0))
 {
  ZeroMemory(&defaultMode, sizeof(DEVMODE));
  defaultMode.dmSize = sizeof(DEVMODE);
  if ( !EnumDisplaySettings((LPSTR)DisplayDevice.DeviceName, ENUM_REGISTRY_SETTINGS, &defaultMode) )
   OutputDebugString("Store default failed/n");

  if ((DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) &&
   !(DisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE))
  {
   DEVMODE    DevMode;
   ZeroMemory(&DevMode, sizeof(DevMode));
   DevMode.dmSize = sizeof(DevMode);
   DevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_POSITION
    | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ;
   Result = ChangeDisplaySettingsEx((LPSTR)DisplayDevice.DeviceName, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL);
   Result = ChangeDisplaySettingsEx((LPSTR)DisplayDevice.DeviceName, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL);

   //The code below shows how to re-attach the secondary displays to the desktop

   //ChangeDisplaySettingsEx((LPSTR)DisplayDevice.DeviceName, &defaultMode, NULL, CDS_UPDATEREGISTRY, NULL);
   //ChangeDisplaySettingsEx((LPSTR)DisplayDevice.DeviceName, &defaultMode, NULL, CDS_UPDATEREGISTRY, NULL);

  }

  // Reinit DisplayDevice just to be extra clean

  ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
  DisplayDevice.cb = sizeof(DisplayDevice);
  DispNum++;
 } // end while for all display devices
}; 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值