DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: david666
今日帖子: 42
在线用户: 16
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/12/1 22:57:57
标题:
Delphi: How get the "MSWindows Display Scale on changing" DPI, SCALE, RESOLUTION easy way! 浏览:1577
加入我的收藏
楼主: Scenary:
-- MSWindows 10 21H2
-- RAD 11 Alexandria
-- VCL project 32/64bits
-- Display FULLHD 24"
by Emailx45

...
type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure FormBeforeMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
    procedure FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
  protected
    procedure WMDisplayChange(var Message: TWMDisplayChange); message WM_DISPLAYCHANGE;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

...

procedure TForm1.WMDisplayChange(var Message: TWMDisplayChange);
begin
  Memo1.Text := Format('The screen resolution has changed to %d×%d×%d.', [message.Width, message.Height, message.BitsPerPixel]);
  //
  Memo1.Lines.Add('GetDpiForSystem: ' + GetDpiForSystem.ToString);
  Memo1.Lines.Add('GetDpiForDesigner: ' + GetDPIForDesigner.ToString);
  Memo1.Lines.Add('GetDpiForWindow: ' + GetDpiForWindow(Self.Handle).ToString);
  //
  Memo1.Lines.Add('USER_DEFAULT_SCREEN_DPI: ' + USER_DEFAULT_SCREEN_DPI.ToString);
  //
  Memo1.Lines.Add('Scale: ' + ROUND(GetDpiForWindow(Self.Handle) / USER_DEFAULT_SCREEN_DPI * 100.0).ToString);
end;

end.
此帖子包含附件:
PNG 图像
大小:76.4K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 janker (janker) ★☆☆☆☆ -
盒子活跃会员
2021/12/1 23:30:36
1楼: thanks!!!!
----------------------------------------------
-
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/2 8:51:43
2楼: 马上测试,  谢谢大神, 祝你双12抢到3080ti
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/2 8:52:34
3楼:    procedure FormBeforeMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
    procedure FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);

这些方法为什么没实现?
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/2 9:00:54
4楼: 经过测试, 数据仍然不对,  120%  150% 抓不到.
此帖子包含附件:
PNG 图像
大小:32.6K
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/12/2 11:59:01
5楼: Here, it works as expected!  but in RAD 10.3.x maybe not (BUG), in RAD 10.4 Embarcadero say that was fixed!
----------

on Form-Base it is, but just call 
...
TMonitorDpiChangedEvent = procedure(Sender: TObject; OldDPI: Integer; NewDPI: Integer) of object;
...

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure FormBeforeMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
    procedure FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
  private
    { Private declarations }
  public
    procedure WMDisplayChange(var Message: TWMDisplayChange); message WM_DISPLAYCHANGE;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
begin
  Memo1.Lines.Add('hello world - AfterMonitorDpiChanged');
end;

procedure TForm1.FormBeforeMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
begin
  Memo1.Lines.Add('hello world - BeforeMonitorDpiChanged');
end;

procedure TForm1.WMDisplayChange(var Message: TWMDisplayChange);
begin
  Memo1.Lines.Add(Format('The screen resolution has changed to %d×%d×%d.', [message.Width, message.Height, message.BitsPerPixel]));
  //
  Memo1.Lines.Add('GetDpiForSystem: ' + GetDpiForSystem.ToString);
  Memo1.Lines.Add('GetDpiForDesigner: ' + GetDPIForDesigner.ToString);
  Memo1.Lines.Add('GetDpiForWindow: ' + GetDpiForWindow(Self.Handle).ToString);
  //
  Memo1.Lines.Add('USER_DEFAULT_SCREEN_DPI: ' + USER_DEFAULT_SCREEN_DPI.ToString);
  //
  Memo1.Lines.Add('Scale: ' + ROUND(GetDpiForWindow(Self.Handle) / USER_DEFAULT_SCREEN_DPI * 100.0).ToString);
end;

end.
此帖子包含附件:
PNG 图像
大小:220.1K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/12/2 12:01:13
6楼: Memo1
hello world - BeforeMonitorDpiChanged
hello world - AfterMonitorDpiChanged
The screen resolution has changed to 1920×1080×32.
GetDpiForSystem: 96
GetDpiForDesigner: 120
GetDpiForWindow: 120
USER_DEFAULT_SCREEN_DPI: 96
Scale: 125
hello world - BeforeMonitorDpiChanged
hello world - AfterMonitorDpiChanged
The screen resolution has changed to 1920×1080×32.
GetDpiForSystem: 96
GetDpiForDesigner: 144
GetDpiForWindow: 144
USER_DEFAULT_SCREEN_DPI: 96
Scale: 150
hello world - BeforeMonitorDpiChanged
hello world - AfterMonitorDpiChanged
The screen resolution has changed to 1920×1080×32.
GetDpiForSystem: 96
GetDpiForDesigner: 168
GetDpiForWindow: 168
USER_DEFAULT_SCREEN_DPI: 96
Scale: 175
hello world - BeforeMonitorDpiChanged
hello world - AfterMonitorDpiChanged
The screen resolution has changed to 1920×1080×32.
GetDpiForSystem: 96
GetDpiForDesigner: 96
GetDpiForWindow: 96
USER_DEFAULT_SCREEN_DPI: 96
Scale: 100
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行101.5625毫秒 RSS