I am trying to get the top left x,y and bottom right x,y. And calculat the width and height of displays.
My secondary monitor is 1920x1080 as seen in my display settings screenshot:
I am getting the monitor dimensions in two ways. The code below is js-ctypes but I simplified out all the error checking and other ctypes stuff and tried to make it look like c. But this is a winapi issue not ctypes hence I didn't tag the topic with it.
First approach:
cPoint = POINT();
GetCursorPos(&cPoint);
cMon = MonitorFromPoint(cPoint, MONITOR_DEFAULTTONEAREST);
cMonInfo = MONITORINFOEX();
cMonInfo.cbSize = MONITORINFOEX.size;
GetMonitorInfo(cMon, &cMonInfo);
lpszDriver = null;
lpszDevice = cMonInfo.szDevice;
xTopLeft = cMonInfo.rcMonitor.left;
yTopLeft = cMonInfo.rcMonitor.top;
nWidth = cMonInfo.rcMonitor.right - xTopLeft;
nHeight = cMonInfo.rcMonitor.bottom - yTopLeft;
This is giving me a rect of the following:
_RECT(-1920, -1080, -640, -360)
Doing right - left gives 1280 Doing bottom - top gives 720
The dimensions are definitely wrong. It should have been width of 1920 and height of 1080.
I then try the second method:
hdcScreen = CreateDC(lpszDriver, lpszDevice, null, null);
nWidth = GetDeviceCaps(hdcScreen, HORZRES);
nHeight = GetDeviceCaps(hdcScreen, VERTRES);
This gives me the same thing, width of 1280 and height of 720. My mind is boggled! How can I get 1920x1080?
This same method gives me correct dimensions for my primary monitor, so I am very confused.
EDIT
I just now tried a third method, and still same issues:
var jsMonitorEnumProc = function(hMonitor, hdcMonitor, lprcMonitor, dwData) {
xTopLeft = lprcMonitor.contents.left;
yTopLeft = lprcMonitor.contents.top;
nWidth = lprcMonitor.contents.right - xTopLeft;
nHeight = lprcMonitor.contents.bottom - yTopLeft;
return true;
}
EnumDisplayMonitors(null, null, jsMonitorEnumProc, 0);
This gives me rects of the following:
_RECT(0, 0, 1280, 1024)
_RECT(-1920, -1080, -640, -360)
The first one is my primary monitor and we see doing bottom - top gives 1280 and right - left gives 1024 which is correct my primary monitor is 1280 x 1024.
But the second monitor again is -360 - -1080 for 720 height and -640 - -1920 for 1280 width. I am using this to take screenshots of all the monitors and second ones is coming out clipped.