1/* 2 3Copyright 1993, 1998 The Open Group 4Copyright (C) Colin Harrison 2005-2008 5 6Permission to use, copy, modify, distribute, and sell this software and its 7documentation for any purpose is hereby granted without fee, provided that 8the above copyright notice appear in all copies and that both that 9copyright notice and this permission notice appear in supporting 10documentation. 11 12The above copyright notice and this permission notice shall be included 13in all copies or substantial portions of the Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 19OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21OTHER DEALINGS IN THE SOFTWARE. 22 23Except as contained in this notice, the name of The Open Group shall 24not be used in advertising or otherwise to promote the sale, use or 25other dealings in this Software without prior written authorization 26from The Open Group. 27 28*/ 29 30 31#include "win.h" 32#include "winmonitors.h" 33 34/* 35 * getMonitorInfo - callback function used to return information from the enumeration of monitors attached 36 */ 37 38static 39wBOOL CALLBACK getMonitorInfo(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM _data) 40{ 41 struct GetMonitorInfoData* data = (struct GetMonitorInfoData*)_data; 42 // only get data for monitor number specified in <data> 43 data->monitorNum++; 44 if (data->monitorNum == data->requestedMonitor) 45 { 46 data->bMonitorSpecifiedExists = TRUE; 47 data->monitorOffsetX = rect->left; 48 data->monitorOffsetY = rect->top; 49 data->monitorHeight = rect->bottom - rect->top; 50 data->monitorWidth = rect->right - rect->left; 51 return FALSE; 52 } 53 return TRUE; 54} 55 56typedef wBOOL (*ENUMDISPLAYMONITORSPROC)(HDC,LPCRECT,MONITORENUMPROC,LPARAM); 57ENUMDISPLAYMONITORSPROC _EnumDisplayMonitors; 58 59wBOOL CALLBACK getMonitorInfo(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM _data); 60 61Bool QueryMonitor(int index, struct GetMonitorInfoData *data) 62{ 63 /* Load EnumDisplayMonitors from DLL */ 64 HMODULE user32; 65 FARPROC func; 66 user32 = LoadLibrary("user32.dll"); 67 if (user32 == NULL) 68 { 69 winW32Error(2, "Could not open user32.dll"); 70 return FALSE; 71 } 72 func = GetProcAddress(user32, "EnumDisplayMonitors"); 73 if (func == NULL) 74 { 75 winW32Error(2, "Could not resolve EnumDisplayMonitors: "); 76 return FALSE; 77 } 78 _EnumDisplayMonitors = (ENUMDISPLAYMONITORSPROC)func; 79 80 /* prepare data */ 81 if (data == NULL) 82 return FALSE; 83 memset(data, 0, sizeof(*data)); 84 data->requestedMonitor = index; 85 86 /* query information */ 87 _EnumDisplayMonitors(NULL, NULL, getMonitorInfo, (LPARAM) data); 88 89 /* cleanup */ 90 FreeLibrary(user32); 91 return TRUE; 92} 93