Created
August 12, 2017 15:13
-
-
Save renaudbedard/f85cc4eb8ee3ae6ec0852be91adefd11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void SetupDpiAwareness() | |
{ | |
bool success = false; | |
List<string> errorCauses = new List<string>(); | |
string successfulMethod = null; | |
try | |
{ | |
var result = DpiAwareness.SetProcessDpiAwareness(DpiAwareness.PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE); | |
if (result == DpiAwareness.HRESULT.E_ACCESSDENIED) | |
{ | |
Logger.Log("SetupDpiAwareness", "DPI-awareness enabled via manifest"); | |
return; | |
} | |
success = result == DpiAwareness.HRESULT.S_OK; | |
if (!success) | |
errorCauses.Add("SetProcessDpiAwareness => " + result.ToString()); | |
} | |
catch (Exception ex) | |
{ | |
errorCauses.Add("SetProcessDpiAwareness => " + ex.ToString()); | |
} | |
if (!success) | |
{ | |
try | |
{ | |
success = DpiAwareness.SetProcessDPIAware(); | |
if (!success) | |
errorCauses.Add("SetProcessDPIAware => false"); | |
} | |
catch (Exception ex) | |
{ | |
errorCauses.Add("SetProcessDPIAware => " + ex.ToString()); | |
} | |
if (success) | |
successfulMethod = "SetProcessDPIAware"; | |
} | |
else | |
successfulMethod = "SetProcessDpiAwareness"; | |
if (!success) | |
Logger.Log("SetupDpiAwareness", "Tried unsuccessfully to enable DPI-awareness\nCauses : " + string.Join(Environment.NewLine, errorCauses)); | |
else | |
{ | |
Logger.Log("SetupDpiAwareness", "Successfully enabled DPI-awareness using '" + successfulMethod + "'"); | |
if (errorCauses.Count > 0) | |
Logger.Log("SetupDpiAwareness", "Prior failing attempts : " + string.Join(Environment.NewLine, errorCauses)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment