Reputation: 11588
Optional background information
A while ago I asked this question which specifically talks about text sizes and DLUs, and was made without me realizing what each DPI awareness actually meant. It never went anywhere, however. It's most likely my fault for not writing a clear question by asking about my implementation-specific problem rather than the general problem that comes out of it ("xX Problem"?).
I asked that question because I was writing a dynamic GUI layout engine — one that could handle changes to control presence and visibility — and needed to know which window the base units would be relative to. At the time, I decided that coordinates should be based on the parent and sizes should be based on the child, but now I realize that'll cause problems if the child's DPI is larger than the parent's.
Of course, this type of thing extends beyond just DLU calculation. For instance, a window that draws pictures on both vertical halves will have to worry about the per-monitor DPI changing right down the middle. So allow me to ask the general, unambiguous question.
The actual question
Today I found these two MSDN articles:
After reading them, I now understand this much about system DPI awarenesses:
PROCESS_SYSTEM_DPI_AWARE
SetProcessDPIAware()
PROCESS_DPI_UNAWARE
PROCESS_SYSTEM_DPI_AWARE
except the DPI is fixed at 96PROCESS_PER_MONITOR_DPI_AWARE
WM_DPICHANGED
is sentWhat I would like to know is:
In the case of PROCESS_PER_MONITOR_DPI_AWARE
, is the DPI of all child (NOT owned) windows of a window the same as that of the parent window?
Note the superlative: the part about the DPI not changing for the life of the program means that the answer is "yes" for the other two awareness values.
Or as another example, let's say I have a 300px-wide window with two controls, both 100px wide, at opposite edges. If I drag that window between two monitors with different DPIs such that one of the controls is on one monitor and the other control is on the other, and then query their DPI (using GetDC()
and GetDeviceCaps()
), will they be the same?
If the answer is yes, then I will not need to worry about converting coordinates between parent windows and child windows.
If the answer is no, then the next question would be is WM_DPICHANGED
sent to child windows, or only to toplevels? Because I would still need a way to know when the DPI of the children changed, so I can at least try to rearrange it to look correct (which I have not yet figured out how to do, and which is another question entirely, but which I assume should just be MulDiv()
).
Thanks.
Upvotes: 3
Views: 1025
Reputation: 612954
When the system decides that the majority of the window has crossed over onto the other monitor, the top level window is sent WM_DPICHANGED
and the entire window is expected to be resized for the new DPI.
In other words, the system does not attempt to have windows with mixed DPI.
Upvotes: 3