What's the difference between WindowFromPhysicalPoint and WindowFromPoint?
WindowFromPhysicalPoint
is new with Vista. Its documentation is almost identical to WindowFromPoint
. What's the difference? Both seem to take an absolute point 开发者_StackOverflow社区(offset from screen origin) and return the topmost (Z order) HWND
that contains the point.
http://msdn.microsoft.com/en-us/library/ms633533(VS.85).aspx
Windows Vista introduces the concept of physical coordinates. Desktop Window Manager (DWM) scales non-dots per inch (dpi) aware windows when the display is high dpi. The window seen on the screen corresponds to the physical coordinates. The application continues to work in logical space. Therefore, the application's view of the window is different from that which appears on the screen. For scaled windows, logical and physical coordinates are different.
WindowFromPhysicalPoint
operates in physical
screen coordinates, while WindowFromPoint
works with logical
ones. To understand the different read this page.
TL;DR; version would be:
Suppose you design a dialog box with a button at coordinates (100, 48). When this dialog box is displayed at the default 96 dpi, the button is located at physical coordinates of (100, 48). At 120 dpi, it is located at physical coordinates of (125, 60). But the logical coordinates are the same at any dpi setting: (100, 48).
So unless you design your app to be DPI aware I would stick with logical
coordinates, since most APIs and window messages operate in logical
space. Another reason to use logical
coordinates is to make your app backward compatible with Windows XP.
精彩评论