真正需要DPI意识吗?

编程入门 行业动态 更新时间:2024-10-28 03:27:44
本文介绍了真正需要DPI意识吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在学习如何使用GDI/GDI +绘制GUI,我发现了这个 msdn.microsoft/zh-cn/library/windows/desktop/dd756596(v = vs.85).aspx#step_2__declare_that_the_application_is_dpi-aware 是否每个应用程序都进行了该计算,以便可以正确显示或显示什么?

I am learning how to draw GUI's with GDI/GDI+, i found this msdn.microsoft/en-us/library/windows/desktop/dd756596(v=vs.85).aspx#step_2__declare_that_the_application_is_dpi-aware Does every application do that calculation so it can be displayed properly or what ?

有人可以解释如何计算窗口上的按钮,图像和所有控件的客户端坐标,以便它们在不同分辨率下具有相同的对齐方式吗?

Can someone explain how to calculate client coordinates of buttons,images and all controls on your window so they have the same align on different resolutions ?

谢谢.

推荐答案

对于GDI,您可以将 GetDeviceCaps 函数与 LOGPIXELSX 和 LOGPIXELSY 一起使用找到您的DPI,并使用这些值来缩放尺寸:

With GDI, you can use GetDeviceCaps function with LOGPIXELSX and LOGPIXELSY to find your DPI, and use these values to scale your sizes:

HDC hdc = GetDC(hwnd); int ppix = GetDeviceCaps(hdc, LOGPIXELSX); int ppiy = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(hdc); // for a control that is 1.5 inches wide and 0.5 inches high. int ctrl_width = int(1.5 * ppix + 0.5); int ctrl_height = int(0.5 * ppiy + 0.5); // for a button that conforms to Microsoft's UI guidelines of 75x23 @ 96dpi. int btn_width = (75 * ppix + 48) / 96; int btn_height = (23 * ppiy + 48) / 96;

GDI +使这一过程变得更加简单:

GDI+ makes this considerably simpler:

Graphics g; g.SetPageUnit(UnitInch); // now you can specify draw coordinates in inches // and it'll figure out DPI for you.

请注意,GDI +解决方案只会影响GDI +绘图调用,而不会影响GDI调用或控件坐标.

Do note that the GDI+ solution will only affect GDI+ draw calls—not GDI calls or coordinates of controls.

更多推荐

真正需要DPI意识吗?

本文发布于:2023-11-15 23:08:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598773.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意识   DPI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!