我正在学习如何使用 GDI/GDI+ 绘制 GUI,我发现了这个http://msdn.microsoft.com/en-us/library/windows/desktop/dd756596(v=vs.85).aspx#step_2__declare_that_the_application_is_dpi-aware http://msdn.microsoft.com/en-us/library/windows/desktop/dd756596(v=vs.85).aspx#step_2__declare_that_the_application_is_dpi-aware是否每个应用程序都会进行该计算以便可以正确显示还是什么?
有人可以解释如何计算窗口上按钮、图像和所有控件的客户端坐标,以便它们在不同的分辨率上具有相同的对齐方式吗?
提前致谢。
通过 GDI,您可以使用GetDeviceCaps
功能与LOGPIXELSX
and LOGPIXELSY
找到您的 DPI,并使用这些值来缩放您的尺寸:
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+ 使这变得相当简单:
Graphics g;
g.SetPageUnit(UnitInch);
// now you can specify draw coordinates in inches
// and it'll figure out DPI for you.
请注意,GDI+ 解决方案只会影响 GDI+ 绘制调用,而不影响 GDI 调用或控件坐标。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)