EnableIeDpi - Enable DPI for Shell.Explorer control

Post your working scripts, libraries and tools
tmplinshi
Posts: 1599
Joined: 01 Oct 2013, 14:57

EnableIeDpi - Enable DPI for Shell.Explorer control

23 Aug 2020, 12:49

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
User avatar
SKAN
Posts: 850
Joined: 29 Sep 2013, 16:58

Re: EnableIeDpi - Enable DPI for Shell.Explorer control

24 Aug 2020, 17:04

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   
---------------------------
gregster
Posts: 5352
Joined: 30 Sep 2013, 06:48

Re: EnableIeDpi - Enable DPI for Shell.Explorer control

24 Aug 2020, 19:34

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...
User avatar
kczx3
Posts: 1188
Joined: 06 Oct 2015, 21:39

Re: EnableIeDpi - Enable DPI for Shell.Explorer control

24 Aug 2020, 21:07

The meta tag should be inside the head tag.
tmplinshi
Posts: 1599
Joined: 01 Oct 2013, 14:57

Re: EnableIeDpi - Enable DPI for Shell.Explorer control

26 Aug 2020, 09:40

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.
User avatar
SKAN
Posts: 850
Joined: 29 Sep 2013, 16:58

Re: EnableIeDpi - Enable DPI for Shell.Explorer control

26 Aug 2020, 09:54

Works fine now :thumbup:
Thanks for sharing! :)

Return to “Scripts and Functions”

Who is online

Users browsing this forum: hotkeyguy, mcl and 23 guests