這不是個確定的值, 它和設備的分辨率相關.
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.