导航:
论坛 -> DELPHI技术
斑竹:liumazi,sephil
作者:
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.
此帖子包含附件: 大小: 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!!!!
----------------------------------------------
-
作者:
2021/12/2 8:51:43
2楼:
马上测试, 谢谢大神, 祝你双12抢到3080ti
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
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最强. 写自己的代码, 让别人去运行.
作者:
2021/12/2 9:00:54
4楼:
经过测试, 数据仍然不对, 120% 150% 抓不到.
此帖子包含附件: 大小: 32.6K
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
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.
此帖子包含附件: 大小: 220.1K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
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