Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Important!!!

Status
Not open for further replies.

cimnik2999

Programmer
Oct 25, 2003
12
CA
How do i calculate TwipsPerPixlesX and Y? (a counterpart to the VB function would be nice)...

Thanxs
 
cimnik2999,

How about something along these lines?

Code:
function TwipsPerPixelX(Canvas : TCanvas) : Extended;
begin
  result :=  440 / GetDeviceCaps(Canvas.Handle, LOGPIXELSX);
end;

function TwipsPerPixelY(Canvas : TCanvas) : Extended;
begin
  result :=  440 / GetDeviceCaps(Canvas.Handle, LOGPIXELSY);
end;

procedure TForm1.ButtonClick(Sender: TObject);
begin
  ShowMessage( FloatToStr(TwipsPerPixelX(Form.Canvas)));
  ShowMessage( FloatToStr(TwipsPerPixelY(Form.Canvas)));
end;

Hope this helps...

-- Lance

 
but what about for the screen?
whats the screen's handle or would the above code posted still work accuratly?
 
First of all, name your questions properly, not.. IMPORTANT!!!
You can use some API to get the screen handle

hwnd = GetDesktopWindow(); // Get desktop handle
 
cimnik2999,

Since these functions need a canvas, you should be able to call them with something along these lines:

Code:
   extX := TwipsPerPixelX( Screen.ActiveForm.Canvas )
   extY := TwipsPerPixelY( Screen.ActiveForm.Canvas )

Assuming that extX and extY are Extended variables, this should give you the values appropriate for the form that currently has focus on the screen.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top