How to get the current resolution size of the 2nd monitor?

  • Thread starter Thread starter lucy
  • Start date Start date
L

lucy

Hi all,

I am having two monitor displays. I want to know the current resolution
(horizontal number of pixels x vertical number of pixels) of the second
monitor? How to do that?

If it is the primary display, I can easily get its current resolution using
the following apporach.

XRes= (double)GetSystemMetrics(SM_CXSCREEN);
YRes= (double)GetSystemMetrics(SM_CYSCREEN);

But how to do that for the second monitor?

Also, how to set the second monitor to a certain resolution? For example,
how to first enumerate its resolution list and pick an supported resolution
to switch the current resolution to that target resolution?

thanks a lot
 
Use EnumDisplayDevices to enumerate all active desktops, the use
EnumDisplaySettings(Ex) on desired desktop(s).

HTH,
calvin
 
lucy said:
Hi all,

I am having two monitor displays. I want to know the current resolution
(horizontal number of pixels x vertical number of pixels) of the second
monitor? How to do that?

If it is the primary display, I can easily get its current resolution using
the following apporach.

XRes= (double)GetSystemMetrics(SM_CXSCREEN);
YRes= (double)GetSystemMetrics(SM_CYSCREEN);

But how to do that for the second monitor?

Also, how to set the second monitor to a certain resolution? For example,
how to first enumerate its resolution list and pick an supported resolution
to switch the current resolution to that target resolution?

thanks a lot

Manually you can go to Start-->Settings-->Control Panel-->Display-->Settings
and you will see both of your monitors schematically represented by two
rectangles. Click on either of them and the actually resolution will be
displayed. I suspect you probably know it all and you are looking for a
command to do it programmatically? Yes?
 
Alternatively, you could find out the device context of your secondary monitor and call GetDeviceCaps(dc , HOZRES/VERTRES);

(with dc being the variable holding the handle to the dc, of course)
 
Back
Top