DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: sprblck
今日帖子: 14
在线用户: 15
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/11/30 17:06:51
标题:
怎么样读到这个值? windows 浏览:2516
加入我的收藏
楼主: 谢谢大家.
此帖子包含附件:
PNG 图像
大小:35.2K
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 dbyoung (dbyoung) ★☆☆☆☆ -
普通会员
2021/11/30 17:24:57
1楼: Win10X64
此帖子包含附件:
PNG 图像
大小:28.3K
----------------------------------------------
武汉天气不好
作者:
男 lsuper (lsuper) ★☆☆☆☆ -
盒子活跃会员
2021/11/30 20:26:07
2楼: https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/dpi-related-apis-and-registry-settings
----------------------------------------------
-
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/11/30 21:46:08
3楼: @dbyoung

你这0表示什么?
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/11/30 21:54:35
4楼: @ lsuper 注册表都找不到。。
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/12/1 3:07:47
5楼: Win64 have keys to: 32 and 64bits then,

1) open Registry ... use REGEDIT command
2) find by "PerMonitorSettings" and found it
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 thinknet (thinknet) ★☆☆☆☆ -
盒子活跃会员
2021/12/1 9:42:57
6楼: uses Winapi.Windows;


Function GetDPIRate: Double;
Var
   DC: HDC;
Begin
   Try
      DC := GetDC(0);
      Result := GetDeviceCaps(DC, LOGPIXELSX) / 96;
      ReleaseDC(0, DC);
      If Result <= 0 Then
         Result := 1;
   Except
      Result := 1;
   End;
End;
----------------------------------------------
-
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/1 10:17:14
7楼: @thinknet

这代码过时了, win10下不行.
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/1 10:21:48
8楼: @emailx45
这数字完全不知道怎么弄.
此帖子包含附件:
PNG 图像
大小:58.8K
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 netrobo (netrobo) ★☆☆☆☆ -
盒子活跃会员
2021/12/1 11:14:21
9楼: Screen.PixelsPerInch
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/12/1 11:55:13
10楼: uses
  System.Win.Registry;

var
  MyRegistry: TRegistry;

procedure TForm1.Button1Click(Sender: TObject);
const
  MyKeyToFound: string = '\Control Panel\Desktop\PerMonitorSettings\';
begin
  try
    //
    // Computer\HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\<<THE NAME CHANGE IN EACH COMPUTER>>
    //
    if MyRegistry.KeyExists(MyKeyToFound) then
    begin
      if MyRegistry.OpenKey(MyKeyToFound, false) then
        MyRegistry.GetKeyNames(ListBox1.Items);
    end
    else
      ShowMessage('Key [' + MyKeyToFound + '] dont exist in your registry path. Try another...');
  finally
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyRegistry := TRegistry.Create;
  //
  MyRegistry.RootKey := HKEY_CURRENT_USER; // where start the works?
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  if not(MyRegistry = nil) then
  begin
    MyRegistry.CloseKey;
    //
    FreeAndNil(MyRegistry);
  end;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  if (ListBox1.ItemIndex > -1) then
  begin
    if MyRegistry.OpenKey(ListBox1.Items[ListBox1.ItemIndex], false) then
    begin
      Caption := MyRegistry.CurrentPath;
      //
      MyRegistry.GetValueNames(ListBox2.Items);
    end;
  end;
end;

procedure TForm1.ListBox2Click(Sender: TObject);
begin
  if (ListBox2.ItemIndex > -1) then
  begin
    ShowMessage(          { }
      Format('%s'#13#10'Value: %s'#13#10'Content: %s', [          { }
      ListBox1.Items[ListBox1.ItemIndex],          { }
      ListBox2.Items[ListBox2.ItemIndex],          { }
      MyRegistry.GetDataAsString(ListBox2.Items[ListBox2.ItemIndex]) { }
      ])          { }
      );
  end;
end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/1 13:51:00
11楼: 没一个正面回答啊. 现在2k显卡器默认缩放150%啊.
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/12/1 14:13:57
12楼: FULL HD = 1920x1080 = 100%
25% = factor (maybe the Display-Resolution Min-Max can changes this value)
...
(0 x 25)+ 100%
(1 x 25)+ 100%
(2 x 25)+ 100%
(3 x 25)+ 100%
(4 x 25)+ 100%
etc...
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/1 14:31:29
13楼: @emailx45 (emailx45)
有参考资料链接没?  比如300%  400%的8K呢?
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/12/1 14:42:58
14楼: I dont understand the translating... What is "Reference Material"?

And, what you needs (in fact) to do?
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/12/1 14:57:08
15楼: Windows supports up to 128,000,000 pixels combined.
128 million = Height x Width.

Yes, you will be able to display 10240x2880 with monitors side by side.


以下显示的是显示分辨率列表:

https://en.wikipedia.org/wiki/Graphics_display_resolution

https://zh.wikipedia.org/wiki/%E6%98%BE%E7%A4%BA%E5%88%86%E8%BE%A8%E7%8E%87%E5%88%97%E8%A1%A8
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/1 17:09:07
16楼: MyKeyToFound: string = '\Control Panel\Desktop\PerMonitorSettings\';

有些系统好像没这个注册表.. 烦.
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 2cc (2cc) ▲▲△△△ -
普通会员
2021/12/1 19:04:19
17楼: https://github.com/lihas/windows-DPI-scaling-sample
此帖子包含附件:
PNG 图像
大小:16.9K
----------------------------------------------
-
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/1 20:20:11
18楼: @ 2cc (2cc)
谢谢大哥, 还是你强。。
不过C语言我不懂啊。
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/12/1 22:59:32
19楼: here your answer:

Scale, DPI, Resolution in MSWindows Display on changing setting
http://bbs.2ccc.com/topic.asp?topicid=621633
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 thinknet (thinknet) ★☆☆☆☆ -
盒子活跃会员
2021/12/2 9:35:58
20楼: @Tuesday

虽然这段代码也是网上找的,但不知道你说的过时是什么意思,是不对还是不能取到数据,反正我在Win10上使用目前还没有发现任何问题。
----------------------------------------------
-
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/2 10:57:41
21楼: @thinknet
你把程序调起来, 然后不要退出,  改缩放后,  再读值就知道了, 它还是返回100%
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/12/2 12:35:54
22楼: MSWindow 10 21H2
-- RAD 11
---- VCL 32/64bits

RETURN IS ALWAYS = 1 = (result <= 0)
//----------

procedure TForm1.Button1Click(Sender: TObject);
  function GetDPIRate: Double;
  var
    DC: HDC;
  begin
    try
      try
        DC     := GetDC(0);
        Result := GetDeviceCaps(DC, LOGPIXELSX) / 96;
        //
      except
        Result := 1;
      end;
    finally
      ReleaseDC(0, DC);
    end;
    //
    if Result <= 0 then
      Result := 1;
  end;

begin
  ShowMessage(GetDPIRate.ToString);
end;


https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdevicecaps
GetDeviceCaps --> 32bits O.S. / Gdi32.dll
Return value
--- The return value specifies the value of the desired item.

Minimum supported client  Windows 2000 Professional [desktop apps only]
Minimum supported server  Windows 2000 Server [desktop apps only]
Target Platform  Windows
Header  wingdi.h (include Windows.h)
Library  Gdi32.lib
DLL  Gdi32.dll


Remarks
When nIndex is SHADEBLENDCAPS:

For a printer, GetDeviceCaps returns whatever the printer reports.
For a display device, all blending operations are available; besides SB_NONE, the only return values are SB_CONST_ALPHA and SB_PIXEL_ALPHA, which indicate whether these operations are accelerated.
On a multiple monitor system, if hdc is the desktop, GetDeviceCaps returns the capabilities of the primary monitor. If you want info for other monitors, you must use the multi-monitor APIs or CreateDC to get a HDC for the device context (DC) of a specific monitor.


When nIndex is BITSPIXEL and the device has 15bpp or 16bpp, the return value is 16.

LOGPIXELSX: Number of pixels per logical inch along the screen width. In a system with multiple display monitors, this value is the same for all monitors.

LOGPIXELSY: Number of pixels per logical inch along the screen height. In a system with multiple display monitors, this value is the same for all monitors.
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/2 13:50:06
23楼: @emailx45 
ShowMessage(GetDPIRate.ToString); 并没有什么用..
此帖子包含附件:
PNG 图像
大小:42.6K
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/2 21:12:18
24楼: 继续救命。。
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 dbyoung (dbyoung) ★☆☆☆☆ -
普通会员
2021/12/3 7:22:50
25楼: Delphi11源码:
此帖子包含附件:
PNG 图像
大小:45.2K
----------------------------------------------
武汉天气不好
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/3 19:39:16
26楼: @dbyoung 
复制不了啊。
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/6 17:43:19
27楼: @dbyoung 

function TForm1.GetPixelsPerInch: Integer;
Type
  TMONITOR_DPI_TYPE = (
    MDT_EFFECTIVE_DPI {= 0},
    MDT_ANGULAR_DPI   {= 1},
    MDT_RAW_DPI       {= 2},
    MDT_DEFAULT       {= MDT_EFFECTIVE_DPI });
var
  dpiX          : UINT;
  dpiY          : UINT;
  DC: HDC;
  ErrCode          : HResult;
  hShcore          : THandle;
  GetDpiForMonitor  : function(monitor: HMONITOR; dpiType: TMONITOR_DPI_TYPE; var dpi, dpiY: UINT): HRESULT; stdcall;
begin
  hShcore := GetModuleHandle('Shcore');
  If hShcore <> 0 then GetDpiForMonitor := GetProcAddress(hShcore,'GetDpiForMonitor');
  If @GetDpiForMonitor <> nil then
    ErrCode := GetDpiForMonitor(Monitor.Handle,MDT_EFFECTIVE_DPI,dpiX,dpiY);
  Result := 96;
  if (ErrCode = S_OK) AND Checkwin32Version(6,3) then begin
    if GetDpiForMonitor(Monitor.Handle,MDT_EFFECTIVE_DPI,dpiX,dpiY) = S_OK then
       Result := dpiX
  end;
end;

你的代码运行仍然有问题.
此帖子包含附件:
PNG 图像
大小:58.2K
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/7 9:15:16
28楼: 大神呢?  delphi没大神?
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 kngstr (KngStr) ▲▲▲▲△ -
普通会员
2021/12/7 12:32:25
29楼: 控件里的Scene.GetSceneScale,不就是这个值嘛?
或者 Form1.Handle.Scale。
----------------------------------------------
-
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/7 12:37:52
30楼: @kngstr (KngStr)
明显不是, 这问题似乎挺复杂, 没什么资料.
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 flcop (flcop) ▲▲▲▲△ -
普通会员
2021/12/7 14:30:38
31楼: 你的程序本身要DPI感知的才行,在项目配置Manifest里检查下,比如设成PerMonitorV2
----------------------------------------------
-
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/7 14:40:18
32楼: @flcop (flcop)

我不能让它感应啊, 感应了界面都自动变化了, 我失去控制能力. 
就是要自己读值, 自己来处理dpi, 怎么弄?
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 flcop (flcop) ▲▲▲▲△ -
普通会员
2021/12/7 16:06:22
33楼: 自己控制没必要,RTL已经帮你处理了大部分,你只要响应缩放就好了,如果你觉得某个Form可以支持高DPI了,可以手动控制(反向亦可),其他Form仍然保持不变
var
  LOldConntext: DPI_AWARENESS_CONTEXT;
begin
  LOldConntext := SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
  try
    { Form1 将以高DPI显示 }
    Form1 := TForm1.Create(Self);
    Form1.Show;
  finally
    if LOldConntext <> nil then
      SetThreadDpiAwarenessContext(LOldConntext);
  end;
end;
----------------------------------------------
-
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/7 16:18:26
34楼: @flcop (flcop)

不自己控制, 比如用户手工拉大缩小界面,  代码就恢复不了了.
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 kngstr (KngStr) ▲▲▲▲△ -
普通会员
2021/12/7 16:29:28
35楼: 呃,你禁用了感知的话,内部控件的这个肯定是不一样的。
话说,为啥不在delphi自己的基础上做调整?
我目前就是根据这个scale,然后对控件再做的调整
----------------------------------------------
-
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/7 17:32:41
36楼: @kngstr (KngStr)

 难道没办法取得这个值吗? 纯从技术角度, 求解决. 
不讲任何需求,  纯delphi, 直接获取这个值.
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 flcop (flcop) ▲▲▲▲△ -
普通会员
2021/12/7 19:54:51
37楼: 非要获取的话,可以用上面的变通下:
var
  LOldConntext: DPI_AWARENESS_CONTEXT;
begin
  LOldConntext := SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
  try
    // 这里取值,根据自己的实际情况来
     .. Screen.Monitors[0].PixelsPerInch ..
  finally
    if LOldConntext <> nil then
      SetThreadDpiAwarenessContext(LOldConntext);
  end;
end;
----------------------------------------------
-
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2021/12/8 9:41:26
38楼: @flcop (flcop)
非常感谢, 测试通过, 可以读到.
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行152.3438毫秒 RSS