c# - How to create a scaling and size-changing Per-Monitor DPI-aware application that is backwards compatable with Windows 7? -
i'm new wpf (and dpi-awareness apis) , writing application running in windows 7, 8.1, , 10. use multiple monitors different per-monitor dpi settings, , interested in making application compatible possible across desktop configurations.
i know possible add manifest wpf application, uncomment section dpi awareness, , set true/pm
. allows program per-monitor dpi-aware in windows 8.1 , 10 (thus looking clean , sharp on various monitors), run system-aware in windows 7.
but can 1 step better? microsoft provides neat tutorial here shows how create per-monitor dpi-aware wpf application. create new object in c++ replace <window>
uses windows 8.1 apis not detect dpi change between monitors, re-size application @ runtime, matching change in dpi. end result not app per-dpi aware , sharp looking, when switching between large , small monitors of various sizes, app looks user change same physical size (in inches or centimeters) on screen.
the downside microsoft's win32 code is not backwards compatible windows 7. trying run in 7 results in application crashing.
i've gone through this article on dr.dobbs , this 1 kenny karr don't understand apis enough make things work.
does know of way similar microsoft's code, in windows 8.1 , newer, application per-monitor aware change size when moving between monitors, runs system-aware in windows 7?
i haven't looked @ code, guess crash caused because of missing native methods in win 7. way fix modify native methods wrapper, example (pseudo code):
public int getdpiofmonitor(intptr monitorhandle) { if (enviroment.osversion >= "6.2") // win 8 , above { return nativemethods.pinvoke.getmonitordpi(monitorhandle); } else return systemdpi; }
this way don't crash under 7, because not calling missing native methods.
Comments
Post a Comment