设置"将windows桌面扩展到该监视器上"

http://support.microsoft.com/kb/308216

 

BOOL AddUnattachedDisplayDeviceToDesktop()
{
DWORD DispNum = 0;
DISPLAY_DEVICE DisplayDevice;
DEVMODE defaultMode;
HDC hdc;
int nWidth;
BOOL bFoundSecondary = FALSE;

hdc = GetDC(0);
nWidth = GetDeviceCaps(hdc,HORZRES);
ReleaseDC(0,hdc);

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

// Get display devices.
while ((EnumDisplayDevices(NULL, DispNum, &DisplayDevice, 0)) &&
(bFoundSecondary == FALSE))
{
ZeroMemory(&defaultMode, sizeof(DEVMODE));
defaultMode.dmSize = sizeof(DEVMODE);
if (!EnumDisplaySettings((LPSTR)DisplayDevice.DeviceName,
ENUM_REGISTRY_SETTINGS, &defaultMode))
return FALSE; // Store default failed

if (!(DisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE))
{
//Found the first secondary device.
bFoundSecondary = TRUE;
defaultMode.dmPosition.x += nWidth;
defaultMode.dmFields = DM_POSITION;
ChangeDisplaySettingsEx((LPSTR)DisplayDevice.DeviceName,
&defaultMode, NULL, CDS_NORESET|CDS_UPDATEREGISTRY, NULL);

// A second call to ChangeDisplaySettings updates the monitor.
ChangeDisplaySettings(NULL, 0);
}

// Reinitialize DisplayDevice.
ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
DisplayDevice.cb = sizeof(DisplayDevice);
DispNum++;
} // End while the display devices.
return TRUE;
}

//========================================
ChangeDisplaySettingsEx 中的 CDS_NORESET 改为CDS_RESET 可以不用 ChangeDisplaySettings(NULL, 0);

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值