我正在学习如何使用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意识吗?
发布评论