Is there API or MFC function to know screen ratio(4:3, 16:10, 16:9)?
Isthere API or MFC function to know if it is wide monitor or normal monitor?
Thank you.
Printable View
Is there API or MFC function to know screen ratio(4:3, 16:10, 16:9)?
Isthere API or MFC function to know if it is wide monitor or normal monitor?
Thank you.
GetSystemMetrics
Retrieve the width and height of the screen, divide them to get the aspect ratio.
That'll only work if the screen is set to the proper resolution, it won't actually tell you the dimensions of the monitor itself?
You need to use the monitors built-in interface, or the video card driver to do that I thought?
He didn't ask for the monitor size, only the ratio.Quote:
Originally Posted by bderagon
Sorry, I responded too quick, he actually did request both. :)
Hello,
Best way may be to get the screen DC and use GetDeviceCaps to find the pixels (VERTRES, HORZRES) and pixels per inch (LOGPIXELSX, LOGPIXELSY) of X and Y direction. From these data, it is easy to calculate the aspect ratio.
Better still, GetDeviceCaps, when called with parameter HORZSIZE / VERTSIZE returns the entire width / height of physical screen.
Regards,Code:HDC hDC = ::GetDC(NULL);
int nWidth = GetDeviceCaps(hDC, HORZSIZE);
int nHeight = GetDeviceCaps(hDC, VERTSIZE);
CString sRatio;
sRatio.Format("Width to Height ratio is %d:%d", nWidth, nHeight);
pDC->TextOut(0, 0, sRatio);
::ReleaseDC(NULL, hDC);
Pravin.
Unexpectedly, GetDeviceCaps returns value which depends on resolution.
When I set resolution as 1920x1200 for my 24 inch wide monitor, it returns
520 mm x 325 mm. This value is actual size of 24 inch wide monitor.
But, when I set resolution as 1280x1024, it returns 412 mm x 330 mm.
Is MSDN wrong?
Is there any way to know physical size of monitor in mm or ratio, regardless of resolution?
Hello,
I have checked with various resolution settings. All the time, monitor aspect ratio was returned as 320:240. Are you sure that your monitor installation settings are correct?
I must admit that I have checked with the code snippet I had earlier posted and not using (VERTRES, HORZRES) and (LOGPIXELSX, LOGPIXELSY). But that also can be easily checked. I do not feel that it will yield a different answer.
Regards,
Pravin.
I used GetDeviceCaps(hDC, HORZSIZE) and I am sure it's return value depends on resolution.
Anyway thank you. I decided to use different method.