这不是个确定的值, 它和设备的分辨率相关.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  mmW,mmH: Integer;
  pixW,pixH: Integer;
  pm: Double;
begin
  {以毫米为单位获取屏幕尺寸}
  mmW := GetDeviceCaps(Canvas.Handle, HORZSIZE);
  mmH := GetDeviceCaps(Canvas.Handle, VERTSIZE);
  ShowMessageFmt('屏幕宽: %d 毫米; 屏幕高: %d 毫米', [mmW, mmH]);
  {屏幕宽: 320 毫米; 屏幕高: 240 毫米}


  {以像素为单位获取屏幕尺寸}
  pixW := GetDeviceCaps(Canvas.Handle, HORZRES);
  pixH := GetDeviceCaps(Canvas.Handle, VERTRES);
  ShowMessageFmt('屏幕宽: %d 像素; 屏幕高: %d 像素', [pixW, pixH]);
  {屏幕宽: 1024 像素; 屏幕高: 768 像素}


  {当前状态下, 1 毫米等于多少像素?}
  ShowMessage(FloatToStr(pixW / mmW)); {3.2}
  ShowMessage(FloatToStr(pixH / mmH)); {3.2}

  {一步获取}
  pm := GetDeviceCaps(Canvas.Handle, HORZRES) / GetDeviceCaps(Canvas.Handle, HORZSIZE);
  ShowMessage(FloatToStr(pm)); {3.2}
end;

end.

posted on 2008-06-03 22:55  万一  阅读(15308)  评论(1编辑  收藏  举报