Use ActiveX Control to Embed World Maps in AutoHotkey GUI

By Directly Loading a Map from into Your AutoHotkey Graphical User Interface (GUI) Pop-up Window, You Can Add Interactive Geographic Locations to All Your Apps

I have some good news and some bad news about using AutoHotkey tools to directly access Web data through the Internet. First the bad news. Since the AutoHotkey tools for downloading and reading Web pages use Internet Explore (built into Windows but no longer supported by Microsoft), Web providers can effectively block access by identifying that user browser. For the good news, you rarely need to use those sites blocking simple little personal apps such as my IPFind.ahk script. So many other sites support location data for IP addresses that I don’t have a problem keeping the script up and running.

For a quick glance at the geographic location of an IP address, insert an Web window into an AutoHotkey GUI. Hold the mouse cursor over a map and scroll in or out to zoom in or out.

Previously, I had repaired other issues caused by changes in the source Web page and converted the IPFind.ahk script to use a GUI window rather than a MsgBox command. This upgrade facilitated adding links to the app, see “Adding Web Links to the AutoHotkey IPFind.ahk Script,” as well as making the current insertion of interactive maps using the ActiveX GUI control possible. I fixed the IPFind.ahk script problems by switching to another source Web page and added an interactive map from

The Latest Blocking of IPFind.ahk

Recently, after reworking the RegEx in the IPFind.ahk script and reinstating its function, I soon discovered that it once again had lost all its function—returning no information at all. My usual approach provided me with what I thought would correct the problem, but to my surprise, nothing worked.

I could load a sample page into my Web browser and read the source code, but any change I made yielded no results. For some reason, the source code I directly downloaded did not match the source code in my regular browser. I only received a bunch of JavaScript without any of the good stuff.

As a test, I loaded the sample URL into the GUI browser I introduced last time “Build a Barebones Web Browser Using the AutoHotkey ActiveX GUI Control.” The Web site ran a “Prove you’re a human” test in the older ActiveX supported Windows browser. (It seems that the URLDownloadToFile command and other AutoHotkey Web download techniques use these same IE tools.) If I employed any of the AutoHotkey Web download methods or the ActiveX control, the Web site only sent me the blocking JavaScript code. If I used Google Chrome or another modern browser, I received the useful HTML code.

I can understand why Webmasters want to block the apps that scrape data from their sites. When bypassing the browser, AutoHotkey eliminates all opportunities for displaying advertising and engaging in other commercial activities. Using Web data without all the annoying extras effectively eliminates the site’s money-making devices. However, that’s not my problem. I make fair use of the data on a limited basis and the Webmasters are free to hinder my ability to take advantage of what they have made available on the Web.

Rather than attempting to defeat the new protections, I took the easy way out and switched to another site—accessing essentially the same information without all the obstacles. The old site doesn’t need to worry about me anymore (plus, they no longer get the free link from my app to their full Web page). I’ve moved on. I’ve also learned that any scriptwriter using the Web for source data must accept the fact that the script will need updates if and when the source page changes.

Add an Interactive Map

Once I figured out the URL for locating the right portion of the globe, I coded the expression for writing the address that loads a map into a browser:" . map1 . "&mlon=" . map2 
                          . "#map=5/" . Map1 . "/" . Map2

Note: The above line uses line continuation techniques to wrap lines of code for display purposes.

The variables map1 and map2 contain the URL longitude and latitude, respectively—drawn from the source Web page. The above ULR loads the page displaying the area surrounding the marked location set at scale number 5.

Next, AutoHotkey loads the URL into an ActiveX GUI control:

Gui Add, ActiveX, ys w200 h200 vWB%A_Index%, Shell.Explorer

Note that the variable name (vWB%A_Index%) concatenates the Loop index number to create a unique object name. The array element WhereIs[3] contains the URL formed in and returned from the function GetLocation(findip).

For a couple of reasons that I plan to explore in the future, I have deliberately avoided Google Maps. For now, see the code for the new IPFindMap.ahk script below:

  OldClipboard:= ClipboardAll
  Clipboard:= ""
  Send, ^c ;copies selected text
  ClipWait 0
  If ErrorLevel
      MsgBox, No Text Selected!
CountIP := 1
Next := 1
  FoundPos := RegExMatch(Clipboard, "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b" , ipaddress%CountIP%, Next)
  Next := FoundPos + StrLen(ipaddress%CountIP%)
  If FoundPos = 0
Gui, +AlwaysOnTop
If IPAddress1
    Loop, %CountIP%
       	CheckIP := ipaddress%A_Index%
       	WhereIs := GetLocation(CheckIP)

		WhereIs[1] := StrReplace(WhereIs[1],"Postal code","`rPostal code:`t")
		WhereIs[1] := StrReplace(WhereIs[1],"Region","`rRegion/State:")
		WhereIs[1] := StrReplace(WhereIs[1],"Country","`rCountry:`t`t")
		WhereIs[1] := StrReplace(WhereIs[1],"State:","State:`t")
		WhereIs[1] := StrReplace(WhereIs[1],"Continent","`rContinent:`t")
		WhereIs[1] := StrReplace(WhereIs[1],"Metro code","`rMetro code:`t")
		WhereIs[1] := StrReplace(WhereIs[1],"City","`rCity:`t`t")
		WhereIs[1] := StrReplace(WhereIs[1],"Coordinates","`rCordinates:`t")

		Gui, Add , Text, xm section, % CheckIP . WhereIs[1] 
		Gui Add, ActiveX, ys w200 h200 vWB%A_Index%, Shell.Explorer
		Gui, Add , Link, xs yp+120, % "<a href=""" . CheckIp . """>IP Data" . "</a>" 
		Gui, Add , Link, yp+15, % WhereIs[2] 
  WhereIs := "No IPs Found!"

Clipboard := OldClipboard

Gui, Add, Button,, Close
Gui, Show,,IP Locations


UrlDownloadToFile, % "" . findip, iplocate
	IPsearch := "" . findip
	whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	whr.Open("GET", IPsearch)
	  sleep 100
	version := whr.ResponseText
	RegExMatch(version, "s)Location</p>(.*?)Time</dt>", Location)
    FileRead, version2, iplocate
	RegExMatch(version, "Coordinates</dt><dd class=""col-8 text-monospace"">(.*?) \(lat\) / (.*?)\(long\)", Map)
	Map := Map1 . "/" . Map2
	MapLink := "<a href=""" . map1 . "&mlon=" . map2 . "#map=5/" . Map . """>Map" . "</a>"
	MapGet := "" . map1 . "&mlon=" . map2 . "#map=5/" . Map1 . "/" . Map2
	Location := RegExReplace(Location1,"<.+?>")
	Return [Location,MapLink,MapGet]


	Gui, Destroy

You can also find the IPFindMap.ahk script at the ComputorEdge Free AutoHotkey Scripts page.

Click the Follow button at the top of the sidebar on the right of this page for e-mail notification of new blogs. (If you’re reading this on a tablet or your phone, then you must scroll all the way to the end of the blog—pass any comments—to find the Follow button.)


This post was proofread by Grammarly
(Any other mistakes are all mine.)

(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free.)

Find my AutoHotkey books at ComputorEdge E-Books!

Find quick-start AutoHotkey classes at “Robotic Desktop Automation with AutoHotkey“!

3 thoughts on “Use ActiveX Control to Embed World Maps in AutoHotkey GUI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s