-
October 23rd, 2007, 01:03 PM
#1
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.
-
October 23rd, 2007, 01:09 PM
#2
Re: Is there API to know screen ratio?
-
October 25th, 2007, 09:21 AM
#3
Re: Is there API to know screen ratio?
Retrieve the width and height of the screen, divide them to get the aspect ratio.
-
October 25th, 2007, 01:46 PM
#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?
-
October 25th, 2007, 02:09 PM
#5
Re: Is there API to know screen ratio?
Originally Posted by bderagon
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.
-
October 25th, 2007, 08:05 PM
#6
Re: Is there API to know screen ratio?
Sorry, I responded too quick, he actually did request both.
-
October 26th, 2007, 05:49 AM
#7
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.
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);
Regards,
Pravin.
-
October 26th, 2007, 01:49 PM
#8
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?
Last edited by tropicchs2; October 26th, 2007 at 02:40 PM.
-
October 30th, 2007, 02:19 AM
#9
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.
-
October 31st, 2007, 11:34 PM
#10
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|