473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Logical Millimeter vs Real Millimeter

Hi, now that in .NET everything is on millimeter, I was wondering how
can one convert Pixel to Millimeter and any user's screen/monitor. I
saw the following code on how to convert pixel to millimeter. It's
done on pascal/delphi, but can be very easily read & converted to VB
..NET.

However my question is what is the difference between "real"
millimeters and "logical" millimeters?

The source of the code is in the following thread:
http://groups.google.com.ph/groups?h...rs%26spell%3D1

It's way back 1996, is it still correct & accurate?

Thanks,
Henry

======================================

procedure PixelsPerMM(canvas:TCanvas; var x,y:real);
procedure PixelsPerLogicalMM(canvas:TCanvas; var x,y:real);

implementation

procedure PixelsPerMM(canvas:TCanvas; var x,y:real);
var
h:HDC;
hres,vres,hsiz,vsiz:integer;
begin
h:=canvas.handle;
hres := GetDeviceCaps(h,HORZRES); {display width in pixels}
vres := GetDeviceCaps(h,VERTRES); {display height in pixels}
hsiz := GetDeviceCaps(h,HORZSIZE); {display width in mm}
vsiz := GetDeviceCaps(h,VERTSIZE); {display height in mm}
x := hres/hsiz;
y := vres/vsiz;
end;

procedure PixelsPerLogicalMM(canvas:TCanvas; var x,y:real);
var
h:hdc;
logpx,logpy:integer;
begin
h:=canvas.handle;
logpx := GetDeviceCaps(h,LOGPIXELSX); {pixels / logical x inch}
logpy := GetDeviceCaps(h,LOGPIXELSY); {pixels / logical y inch}
x := logpx / 25.4;
y := logpy / 25.4;
end;

end.

//ns
Nov 20 '05 #1
5 2703
Hi Henry,

Well saved

I hope this helps

Cor

\\\By Fergus Cooney
A Form's width is in pixels, as you've found. Each Form (actually Control)
has a drawing surface controlled by a Graphics object. This has a property
DpiX which is Dots-Per-Inch-Horizontal, and a corresponding DpiY.

try this:
im g As Graphics
g = SomeForm.CreateGraphics
MsgBox ("DpiX " & g.DpiX & vbCrLf _
"Width (mm) " & SomeForm.Width & vbCrLf _
"Width (inches) = " & SomeForm.Width / g.DpiX)
//
Nov 20 '05 #2
* "Cor Ligthert" <no**********@planet.nl> scripsit:
\\\By Fergus Cooney
A Form's width is in pixels, as you've found. Each Form (actually Control)
has a drawing surface controlled by a Graphics object. This has a property
DpiX which is Dots-Per-Inch-Horizontal, and a corresponding DpiY.

try this:
im g As Graphics
g = SomeForm.CreateGraphics
MsgBox ("DpiX " & g.DpiX & vbCrLf _
"Width (mm) " & SomeForm.Width & vbCrLf _
"Width (inches) = " & SomeForm.Width / g.DpiX)


\\\
g.Dispose()
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
> * "Cor Ligthert" <no**********@planet.nl> scripsit:
\\\By Fergus Cooney
A Form's width is in pixels, as you've found. Each Form (actually Control) has a drawing surface controlled by a Graphics object. This has a property DpiX which is Dots-Per-Inch-Horizontal, and a corresponding DpiY.

try this:
im g As Graphics
g = SomeForm.CreateGraphics
MsgBox ("DpiX " & g.DpiX & vbCrLf _
"Width (mm) " & SomeForm.Width & vbCrLf _
"Width (inches) = " & SomeForm.Width / g.DpiX)


\\\
g.Dispose()
///

That Fergus even now he get a message from you. I changed it in his code, I
think he will agree that.

:-)

Cor
Nov 20 '05 #4
> try this:
im g As Graphics
g = SomeForm.CreateGraphics
MsgBox ("DpiX " & g.DpiX & vbCrLf _
"Width (mm) " & SomeForm.Width & vbCrLf _
"Width (inches) = " & SomeForm.Width / g.DpiX)
//


I see what your getting at, by using DPIX & DPIY, one can compute for
mm, inches etc.

There must be a typo here:
"Width (mm) " & SomeForm.Width & vbCrLf

SomeForm.Width returns pixels, as you said.
but I get what you mean. Thanks again!!! :)

Henry
Nov 20 '05 #5
u can't. metric already converted. to microsoft.net it had built in
function, i have read book by petzold .
regards

Henry Wu wrote:
Hi, now that in .NET everything is on millimeter, I was wondering how
can one convert Pixel to Millimeter and any user's screen/monitor. I
saw the following code on how to convert pixel to millimeter. It's
done on pascal/delphi, but can be very easily read & converted to VB
.NET.

However my question is what is the difference between "real"
millimeters and "logical" millimeters?

The source of the code is in the following thread:
http://groups.google.com.ph/groups?h...rs%26spell%3D1

It's way back 1996, is it still correct & accurate?

Thanks,
Henry

======================================

procedure PixelsPerMM(canvas:TCanvas; var x,y:real);
procedure PixelsPerLogicalMM(canvas:TCanvas; var x,y:real);

implementation

procedure PixelsPerMM(canvas:TCanvas; var x,y:real);
var
h:HDC;
hres,vres,hsiz,vsiz:integer;
begin
h:=canvas.handle;
hres := GetDeviceCaps(h,HORZRES); {display width in pixels}
vres := GetDeviceCaps(h,VERTRES); {display height in pixels}
hsiz := GetDeviceCaps(h,HORZSIZE); {display width in mm}
vsiz := GetDeviceCaps(h,VERTSIZE); {display height in mm}
x := hres/hsiz;
y := vres/vsiz;
end;

procedure PixelsPerLogicalMM(canvas:TCanvas; var x,y:real);
var
h:hdc;
logpx,logpy:integer;
begin
h:=canvas.handle;
logpx := GetDeviceCaps(h,LOGPIXELSX); {pixels / logical x inch}
logpy := GetDeviceCaps(h,LOGPIXELSY); {pixels / logical y inch}
x := logpx / 25.4;
y := logpy / 25.4;
end;

end.

//ns


Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
7
by: Charles Crume | last post by:
Hello all; I have used dBASE, and other computer languages/databases, for years. They all have a logical field type. However, the version of MySQL used by the ISP hosting my site does not...
34
by: sam | last post by:
Please look at the code below #include <stdio.h> int expr(char str, int i){ printf("%s \n",str); return i; }
80
by: Christopher Benson-Manica | last post by:
Of course one can get the effect with appropriate use of existing operators, but a ^^ operator would make for nice symmetry (as well as useful to me in something I'm working on). Am I the only one...
3
by: serge | last post by:
How do I determine which method I should use if I want to optimize the performance of a database. I took Northwind's database to run my example. My query is I want to retrieve the Employees'...
8
by: FuzzyLogik | last post by:
I am trying to make a logical link list, <ul> <li></li> </ul> But my sections have headers and footers. How do I do this? Example:
9
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T');...
0
by: Roald | last post by:
I am working on an application that needs to implement logical deletes instead of removing the records permanently. The logical delete works by setting 3 fields (deleted flag, date and user). I...
2
by: dbtwo | last post by:
Until today I always thought as long as you see a lot of logical reads as compared to physical reads, then you're good. But it looks like it isn't so. But doesn't logical read mean it's being read...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.