Is there API to know screen ratio?
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.
[169 byte] By [
tropicchs2] at [2007-11-20 11:37:06]

# 1 Re: Is there API to know screen ratio?
GetSystemMetrics
GCDEF at 2007-11-10 22:24:55 >

# 2 Re: Is there API to know screen ratio?
Retrieve the width and height of the screen, divide them to get the aspect ratio.
Marc G at 2007-11-10 22:26:01 >

# 3 Re: Is there API to know screen 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?
# 4 Re: Is there API to know screen 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.
GCDEF at 2007-11-10 22:27:54 >

# 5 Re: Is there API to know screen ratio?
Sorry, I responded too quick, he actually did request both. :)
# 6 Re: Is there API to know screen ratio?
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.
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);
Regards,
Pravin.
# 7 Re: Is there API to know screen ratio?
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?
# 8 Re: Is there API to know screen ratio?
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.
# 9 Re: Is there API to know screen ratio?
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.