标签:
windows下多屏支持一个简单的思路就是找到显示器的区域(EnumDisplayMonitors),并把相应的窗口移动到目标区域(windows API: MoveWindow)。下面是一个简单的查找显示区域方法,gRects为查找到的显示区域,gMCount为查找到的个数。
1 unit EnumMonitor; 2 3 interface 4 uses 5 MultiMon, windows; 6 const 7 MONITOR_MAX_COUNT = 10; //显示器个数上限 8 9 var 10 //显示区域 11 gRects: array[0..MONITOR_MAX_COUNT - 1] of TRect; 12 //查找到的显示器个数 13 gMCount: Integer = 0; 14 15 //刷新显示器信息 16 procedure RefreshMontor; 17 18 implementation 19 20 var 21 isFirst: Boolean = True; //是否是第一个,查找时用到 22 23 function EnumMon(AMonitor: HMONITOR; ADC: HDC; ARect: PRect; AParam: LPARAM): Boolean; stdcall; 24 var 25 info: MONITORINFO; 26 begin 27 Result := True; 28 //如果显示器个数超过预设个数,停止查找 29 if gMCount >= MONITOR_MAX_COUNT then 30 begin 31 Result := false; 32 Exit; 33 end; 34 35 info.cbSize := SizeOf(MONITORINFO); 36 GetMonitorInfo(AMonitor, @info); 37 //如果是主显示器,判断是不是第一次查找,如果是第二次,则结束查找 38 if(info.dwFlags = MONITORINFOF_PRIMARY)then 39 begin 40 if isFirst then 41 begin 42 isFirst := false; 43 gMCount := 1; 44 gRects[0] := info.rcMonitor; 45 Result := True; 46 Exit; 47 end 48 else begin 49 //标志复位 50 isFirst := true; 51 Result := false; 52 end 53 end; 54 55 gRects[gMCount] := info.rcMonitor; 56 Inc(gMCount); 57 end; 58 59 procedure RefreshMontor; 60 begin 61 gMCount := 0; 62 isFirst := true; 63 FillChar(gRects, SizeOf(gRects), 0); 64 EnumDisplayMonitors(0, nil, EnumMon, 0); 65 end; 66 67 initialization 68 RefreshMontor; 69 70 finalization 71 gMCount := 0; 72 FillChar(gRects, SizeOf(gRects), 0); 73 end.
标签:
原文地址:http://www.cnblogs.com/btxz/p/4206092.html