Page 1 of 1

EnableIeDpi - Enable DPI for Shell.Explorer control

Posted: 23 Aug 2020, 12:49
by tmplinshi

Code: Select all

EnableIeDpi(bEnable := true, exeName := "")
{
	if (exeName = "")
		exeName := A_IsCompiled ? A_ScriptName : RegExReplace(A_AhkPath, ".*\\")

	keyName := "HKCU\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_96DPI_PIXEL"
	RegRead, v, %keyName%, %exeName%
	if (v != bEnable)
		RegWrite, REG_DWORD, %keyName%, %exeName%, %bEnable%
}
Example:

Code: Select all

Gui, Add, ActiveX, w400 h200 vwb, Shell.Explorer
Gui, Add, Checkbox, cBlue visEnabled gToggleDPI, Enable IE DPI
Gui, Show

wb.navigate("about:<!DOCTYPE html><meta http-equiv='X-UA-Compatible' content='IE=edge'>")
while wb.Busy
	sleep, 10
wb.document.write( HtmlCode() )

;if __IsIeDpiEnabled()
if (wb.document.parentWindow.devicePixelRatio > 1)
	GuiControl,, isEnabled, 1
Return

ToggleDPI:
	GuiControlGet, isEnabled
	EnableIeDpi(isEnabled)
	Reload
Return

GuiClose:
ExitApp

EnableIeDpi(bEnable := true, exeName := "")
{
	if (exeName = "")
		exeName := A_IsCompiled ? A_ScriptName : RegExReplace(A_AhkPath, ".*\\")

	keyName := "HKCU\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_96DPI_PIXEL"
	RegRead, v, %keyName%, %exeName%
	if (v != bEnable)
		RegWrite, REG_DWORD, %keyName%, %exeName%, %bEnable%
}

__IsIeDpiEnabled()
{
	keyName := "HKCU\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_96DPI_PIXEL"
	exeName := A_IsCompiled ? A_ScriptName : RegExReplace(A_AhkPath, ".*\\")
	RegRead, v, %keyName%, %exeName%
	Return (v = 1)
}

HtmlCode() {
	s =
	(
		<!DOCTYPE html>
		<html>
		    <head>
		    	<meta http-equiv="X-UA-Compatible" content="IE=edge">
		        <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
		        <style type="text/css">*{margin:5px;padding:0px;} body { overflow: hidden; }</style>
		    </head>
		        <form class="form-horizontal m">
		            <div class="form-group">
		                <label class="col-sm-2 control-label">Label 1:</label>
		                <div class="col-sm-4">
		                    <input class="form-control" readonly="true" value="Input 1">
		                </div>
		                <br>
		            </div>
		            <div class="form-group">
		                <label class="col-sm-2 control-label">Label 2:</label>
		                <div class="col-sm-4">
		                    <input class="form-control" readonly="true" value="Input 2">
		                </div>
		            </div>
		        </form>
		    </body>
		</html>
	)
	return s
}
Tested on Win10, IE 11

Re: EnableIeDpi - Enable DPI for Shell.Explorer control

Posted: 24 Aug 2020, 17:04
by SKAN
Hi @tmplinshi

I get the following error in IE 11 (Windows 8.1), script compiled or not.

Code: Select all

---------------------------
EnableIeDpi.exe
---------------------------
Error:  0x80020006 - Unknown name.

Specifically: devicePixelRatio

	Line#
--->	013: if (wb.document.parentWindow.devicePixelRatio > 1)  

Continue running the script?
---------------------------
Yes   No   
---------------------------

Re: EnableIeDpi - Enable DPI for Shell.Explorer control

Posted: 24 Aug 2020, 19:34
by gregster
SKAN wrote:
24 Aug 2020, 17:04
I get the following error in IE 11 (Windows 8.1), script compiled or not.
Just to make sure:
Afaik, it is not guaranteed that IE COM/ActiveX uses automatically IE 11, even if it is installed (it seems just the opposite), but some older "compatibility mode" instead.
There are a few posts about it on the forum, for example here by FanaticGuru: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=79908&p=347942#p347942

Iirc, I also edited my Win10 registry some time ago for this reason.

Edit:
There is also GeekDude's FixIE() function (see flyingDman's post): https://www.autohotkey.com/boards/viewtopic.php?f=76&t=79059&p=343883#p343861

Edit:
If I understand correctly, this - which is already used in the example - should have helped as well: <meta http-equiv="X-UA-Compatible" content="IE=edge"> :think: Ah, see below...

Re: EnableIeDpi - Enable DPI for Shell.Explorer control

Posted: 24 Aug 2020, 21:07
by kczx3
The meta tag should be inside the head tag.

Re: EnableIeDpi - Enable DPI for Shell.Explorer control

Posted: 26 Aug 2020, 09:40
by tmplinshi
Hi @SKAN, I've fixed it, by replacing wb.navigate("about:blank") to wb.navigate("about:<!DOCTYPE html><meta http-equiv='X-UA-Compatible' content='IE=edge'>"). FixIE() can also fix the error.

Thanks @kczx3, updated.

Re: EnableIeDpi - Enable DPI for Shell.Explorer control

Posted: 26 Aug 2020, 09:54
by SKAN
Works fine now :thumbup:
Thanks for sharing! :)