i trying top left x,y , bottom right x,y. , calculat width , height of displays.
my secondary monitor 1920x1080 seen in display settings screenshot:
i getting monitor dimensions in 2 ways. code below js-ctypes simplified out error checking , other ctypes stuff , tried make c. winapi issue not ctypes hence didn't tag topic 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 giving me rect of following:
_rect(-1920, -1080, -640, -360)
doing right - left gives 1280 doing bottom - top gives 720
the dimensions wrong. should have been width of 1920 , height of 1080.
i try second method:
hdcscreen = createdc(lpszdriver, lpszdevice, null, null); nwidth = getdevicecaps(hdcscreen, horzres); nheight = getdevicecaps(hdcscreen, vertres);
this gives me same thing, width of 1280 , height of 720. mind boggled! please me 1920x1080.
this same method gives me correct dimensions primary monitor, confused.
edit
i tried third method, , 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 following:
_rect(0, 0, 1280, 1024) _rect(-1920, -1080, -640, -360)
the first 1 primary monitor , see doing bottom - top gives 1280 , right - left gives 1024 correct primary monitor 1280 x 1024.
but second monitor again -360 - -1080 720 height , -640 - -1920 1280 width. please me figure out what's here. using take screenshots of monitors , second ones coming out clipped.
in non-dpi aware app 32bit firefox on win8.1 64bit) able proper dimensions using enumdisplaysettings
using display_device struct of size 220.
js-ctypes:
// start - monitor resolutions var idevnum = -1; while (true) { idevnum++; var lpdisplaydevice = ostypes.type.display_device(); lpdisplaydevice.cb = ostypes.type.display_device.size; var rez_enumdisplaydevices = ostypes.api('enumdisplaydevices')(null, idevnum, lpdisplaydevice.address(), 0); //console.info('rez_enumdisplaydevices:', rez_enumdisplaydevices.tostring(), uneval(rez_enumdisplaydevices), cutils.jscgetdeepest(rez_enumdisplaydevices)); if (cutils.jscequal(rez_enumdisplaydevices, 0)) { // ctypes.winlasterror != 0 // idevnum greater largest device index. break; } console.info('lpdisplaydevice.devicename:', lpdisplaydevice.devicename.readstring()); // "\\.\display1" till "\\.\display4" if (lpdisplaydevice.stateflags & ostypes.const.display_device_attached_to_desktop) { console.log('is monitor'); var dm = ostypes.type.devmode(); // sizeof_devmode = 148 console.info('dm.size:', ostypes.type.devmode.size); //dm.dmfields = ostypes.const.dm_pelswidth; //dm.dmsize = ostypes.type.devmode.size; console.log('idevnum:', idevnum, lpdisplaydevice.devicename.readstring()); var rez_enumdisplaysettings = ostypes.api('enumdisplaysettings')(lpdisplaydevice.devicename, ostypes.const.enum_current_settings, dm.address()); //console.info('rez_enumdisplaysettings:', rez_enumdisplaysettings.tostring(), uneval(rez_enumdisplaysettings), cutils.jscgetdeepest(rez_enumdisplaysettings)); //console.info('dm:', dm.tostring()); collmoninfos.push({ x: parseint(cutils.jscgetdeepest(dm.u.dmposition.x)), y: parseint(cutils.jscgetdeepest(dm.u.dmposition.y)), w: parseint(cutils.jscgetdeepest(dm.dmpelswidth)), h: parseint(cutils.jscgetdeepest(dm.dmpelsheight)), screenshot: null, // winnt, each collmoninfos entry has screenshot data otherinfo: { nbpp: parseint(cutils.jscgetdeepest(dm.dmbitsperpel)), lpszdriver: null, lpszdevice: lpdisplaydevice.devicename } }); } } // end - monitor resolutions
Comments
Post a Comment