Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2644582
  • 博文数量: 416
  • 博客积分: 10220
  • 博客等级: 上将
  • 技术积分: 4193
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-15 09:47
文章分类

全部博文(416)

文章存档

2022年(1)

2021年(1)

2020年(1)

2019年(5)

2018年(7)

2017年(6)

2016年(7)

2015年(11)

2014年(1)

2012年(5)

2011年(7)

2010年(35)

2009年(64)

2008年(48)

2007年(177)

2006年(40)

我的朋友

分类: C/C++

2010-03-22 14:33:36

测试代码:

 LPRECT prc = new RECT;
 HMONITOR hMonitor;
 MONITORINFO info;
 hMonitor = MonitorFromRect(prc, MONITOR_DEFAULTTONEAREST);
 
 memset(&info, 0, sizeof(MONITORINFO));
 info.cbSize = sizeof(MONITORINFO);
 BOOL b = GetMonitorInfo(
  hMonitor,  // handle to display monitor
  &info  // display monitor information
  );
 printf("w = %d, \n", GetLastError() );
 RECT rr;
 SystemParametersInfo(SPI_GETWORKAREA, 0, &rr, 0);
 // Fill list of rects
 CRect r = info.rcMonitor;

/*************************/
下面是msdn中的
#include
#include "multimon.h"   
#define MONITOR_CENTER     0x0001        // center rect to monitor
#define MONITOR_CLIP     0x0000        // clip rect to monitor
#define MONITOR_WORKAREA 0x0002        // use monitor work area
#define MONITOR_AREA     0x0000        // use monitor entire area
//
//  ClipOrCenterRectToMonitor
//
//  The most common problem apps have when running on a
//  multimonitor system is that they "clip" or "pin" windows
//  based on the SM_CXSCREEN and SM_CYSCREEN system metrics.
//  Because of app compatibility reasons these system metrics
//  return the size of the primary monitor.
//
//  This shows how you use the multi-monitor functions
//  to do the same thing.
//
void ClipOrCenterRectToMonitor(LPRECT prc, UINT flags)
{
 HMONITOR hMonitor;
 MONITORINFO mi;
 RECT        rc;
 int         w = prc->right  - prc->left;
 int         h = prc->bottom - prc->top;
 //
 // get the nearest monitor to the passed rect.
 //
 hMonitor = MonitorFromRect(prc, MONITOR_DEFAULTTONEAREST);
 //
 // get the work area or entire monitor rect.
 //
 mi.cbSize = sizeof(mi);
 GetMonitorInfo(hMonitor, &mi);
 if (flags & MONITOR_WORKAREA)
  rc = mi.rcWork;
 else
  rc = mi.rcMonitor;
 //
 // center or clip the passed rect to the monitor rect
 //
 if (flags & MONITOR_CENTER)
 {
  prc->left   = rc.left + (rc.right  - rc.left - w) / 2;
  prc->top    = rc.top  + (rc.bottom - rc.top  - h) / 2;
  prc->right  = prc->left + w;
  prc->bottom = prc->top  + h;
 }
 else
 {
  prc->left   = max(rc.left, min(rc.right-w,  prc->left));
  prc->top    = max(rc.top,  min(rc.bottom-h, prc->top));
  prc->right  = prc->left + w;
  prc->bottom = prc->top  + h;
 }
}
void ClipOrCenterWindowToMonitor(HWND hwnd, UINT flags)
{
 RECT rc;
 GetWindowRect(hwnd, &rc);
 ClipOrCenterRectToMonitor(&rc, flags);
 SetWindowPos(hwnd, NULL, rc.left, rc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}
阅读(1457) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-03-22 14:34:41

Windows系统下的多显示器模式开发日记 : http://www.cnblogs.com/wuchang/archive/2006/06/20/430766.html