Jump to content
Sign in to follow this  
redfire

How do i get Country TLD and Flag

Recommended Posts

redfire

Hi everyone,

How do i get the country 2 letter TLD and Flag in Auto IT?

For instance , i am developing an application that would get the country as Brazil, it gets the 2 letter TLD as BR and then it shows the country flag. How is this possible in Auto IT? what must be done? Are there functions i should follow? pls let me know.

Share this post


Link to post
Share on other sites
water

You need something to determine the country.

You could start with macro @OSLang


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
michaelslamet

To determine the country, you could first check it's public ip address, then find the geographics location using this:

>GeoIP database parsing examples by guinness

Dont forget we need IpToCountry.csv that can be downloaded here

To determine the user's public ip address, you can use this snippet (also by guinness):

; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
; #FUNCTION# =========================================================================================================
; Name...........: _GetIP_Chicken
; Description ...: Retrieves the Public IP Address of a Network/Computer.
; Syntax.........: _GetIP_Chicken()
; Parameters ....: None
; Requirement(s).: v3.3.2.0 or higher
; Return values .: Success - Returns Public IP Address.
;                  Failure - Returns -1 & sets @error = 1
; Author ........: guinness
; Example........; Yes
;=====================================================================================================================
Func _GetIP_Chicken()
    Local $aReturn, $bRead, $sRead
    $bRead = InetRead("http://www.ipchicken.com/")
    $sRead = BinaryToString($bRead)
    $aReturn = StringRegExp($sRead, '(?s)(?i)<b>(.*?)<br>', 3)
    If @error Then
        Return SetError(1, 0, -1)
    EndIf
    Return StringStripWS($aReturn[0], 8)
EndFunc   ;==>_GetIP_Chicken

Share this post


Link to post
Share on other sites
redfire

 

To determine the country, you could first check it's public ip address, then find the geographics location using this:

>GeoIP database parsing examples by guinness

Dont forget we need IpToCountry.csv that can be downloaded here

To determine the user's public ip address, you can use this snippet (also by guinness):

; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
; #FUNCTION# =========================================================================================================
; Name...........: _GetIP_Chicken
; Description ...: Retrieves the Public IP Address of a Network/Computer.
; Syntax.........: _GetIP_Chicken()
; Parameters ....: None
; Requirement(s).: v3.3.2.0 or higher
; Return values .: Success - Returns Public IP Address.
;                  Failure - Returns -1 & sets @error = 1
; Author ........: guinness
; Example........; Yes
;=====================================================================================================================
Func _GetIP_Chicken()
    Local $aReturn, $bRead, $sRead
    $bRead = InetRead("http://www.ipchicken.com/")
    $sRead = BinaryToString($bRead)
    $aReturn = StringRegExp($sRead, '(?s)(?i)<b>(.*?)<br>', 3)
    If @error Then
        Return SetError(1, 0, -1)
    EndIf
    Return StringStripWS($aReturn[0], 8)
EndFunc   ;==>_GetIP_Chicken

What i mean is, My country is Brazil. the code returns something like BR. thats what  i mean. for the ip. this _GetIP() doesnt it return the public ip of the computer?

Share this post


Link to post
Share on other sites
water

How do you determine that your country is Brazil?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
guinness

You can use _GetIP() in Inet.au3 as that IPChicken is badly coded.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
michaelslamet

You can use _GetIP() in Inet.au3 as that IPChicken is badly coded.

 

@Guinness:

How is that IPChicken snippet badly coded?

I'm using it on some of my scripts and it never failed me, and I dont plan to change it o:)

Share this post


Link to post
Share on other sites
guinness

#include <Constants.au3>

Local $sPublicIP = _GetIP_IPChicken()
MsgBox($MB_SYSTEMMODAL, "", "Your external IP address is: " & $sPublicIP)

; #FUNCTION# ====================================================================================================================
; Author ........: guinness
; ===============================================================================================================================
Func _GetIP_IPChicken()
    Local Const $IP_URL = "http://ipchicken.com/"
    Local $aReturn = StringRegExp(BinaryToString(InetRead($IP_URL)), "[\d\.]{7,15}", 3), $sReturn = ""
    If @error = 0 Then
        $sReturn = $aReturn[0]
    EndIf
    If $sReturn == "" Then Return SetError(1, 0, -1)
    Return $sReturn
EndFunc   ;==>_GetIP_IPChicken


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
guinness

@Guinness:

How is that IPChicken snippet badly coded?

I'm using it on some of my scripts and it never failed me, and I dont plan to change it o:)

Use _GetIP() because IPChicken isn't intended for automation, whereas the sites in _GetIP() are.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
michaelslamet

If I'm not wrong, the main different is at the RegEx pattern:

previous one: (?s)(?i)<b>(.*?)<br>

new one: [d.]{7,15}

I can see why the new one will give better result

Is that correct?

Share this post


Link to post
Share on other sites
michaelslamet

Use _GetIP() because IPChicken isn't intended for automation, whereas the sites in _GetIP() are.

 

Noted with thanks, guinness.

I am not remember why I'm using IPChicken instead of _GetIP(), but if i'm not wrong, _GetIP() sometime return the local ip address ?

Share this post


Link to post
Share on other sites
guinness

I guess the OP is wanting to use the ISO 3166 code? If so look at using images from http://icondrawer.com/free.php (notice the license please) and then look at _GetOSLanguage() in my signature.

You will basically need to use some logical thinking and create your own user defined function.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
trancexx

It doesn't have to be super complicated but it really isn't possible to determine what you really want based on your input. I will imagine you want something like this:

#include "GIFAnimation.au3"
#include <GUIConstantsEx.au3>

Global $sCountry = "Portugal"
Global Const $sFormat = "http://flagpedia.net/data/flags/normal/%s.png"
Global $sTLD

Global $hGui = GUICreate("National flags", 500, 350)
Global $hInput = GUICtrlCreateInput($sCountry, 20, 30, 150, 30)
GUICtrlSetFont($hInput, 0)
Global $hButton = GUICtrlCreateButton("&Show national flag", 200, 30, 140, 30)
GUICtrlSetFont($hButton, 0)
Global $hLabel = GUICtrlCreateLabel("", 20, 180, 70, 30)
GUICtrlSetFont($hLabel, 0, 600)
GUICtrlSetColor($hLabel, 0x0000FF)
GUICtrlSetTip($hLabel, "Top-level Domain")
Global $hPic = GUICtrlCreatePic("", 112, 110, 275, 183)
GUICtrlSetState($hButton, $GUI_FOCUS)

GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $sTLD = GetCountryTLD(GUICtrlRead($hInput))
            If $sTLD Then
                SetNationalFlag($hPic, $sTLD)
                GUICtrlSetData($hLabel, "." & $sTLD)
            EndIf
    EndSwitch
WEnd

Func SetNationalFlag($hControl, $sMoniker)
    Local $vData = InetRead(StringFormat($sFormat, StringLower($sMoniker)), 16)
    If $vData Then
        _GUICtrlSetGIF($hControl, $vData)
        GUICtrlSetState($hControl, $GUI_SHOW)
    Else
        GUICtrlSetState($hControl, $GUI_HIDE)
    EndIf
EndFunc

Func GetCountryTLD($sCountry)
    Local Enum $GEO_NATION = 0x0001, $GEO_LATITUDE, $GEO_LONGITUDE, $GEO_ISO2, $GEO_ISO3, $GEO_RFC1766, $GEO_LCID, $GEO_FRIENDLYNAME, $GEO_OFFICIALNAME, $GEO_TIMEZONES, $GEO_OFFICIALLANGUAGES, $GEO_ISO_UN_NUMBER, $GEO_PARENT
    Local $sTLD, $aCall
    For $iGEOId = 0 To 0xFFFF
        $aCall = DllCall("kernel32.dll", "int", "GetGeoInfoW", "long", $iGEOId, "int", $GEO_FRIENDLYNAME, "wstr", "", "int", 65536, "word", 0)
        If @error Then Return $sTLD
        If $aCall[3] = $sCountry Then
            $aCall = DllCall("kernel32.dll", "int", "GetGeoInfoW", "long", $iGEOId, "int", $GEO_ISO2, "wstr", "", "int", 65536, "word", 0)
            If @error Then Return $sTLD
            $sTLD = $aCall[3]
            ExitLoop
        EndIf
    Next
    Return $sTLD
EndFunc
 

Or this variation of the same thing:

#include "GIFAnimation.au3"
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>

Global $sCountry = "Portugal"
Global Const $sFormat = "http://flagpedia.net/data/flags/normal/%s.png"
Global $sTLD

Global $hGui = GUICreate("National flags", 500, 350)

Global $hInput = GUICtrlCreateInput($sCountry, 20, 30, 160, 30)
GUICtrlSetFont($hInput, 0)

Global $hComboBox = GUICtrlCreateCombo($sCountry, 20, 61, 160, 30, BitOR($WS_VSCROLL, $CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData($hComboBox, ListCountries())

Global $hButton = GUICtrlCreateButton("&Show national flag", 200, 30, 140, 30)
GUICtrlSetFont($hButton, 0)

Global $hLabel = GUICtrlCreateLabel("", 20, 180, 70, 30)
GUICtrlSetFont($hLabel, 0, 600)
GUICtrlSetColor($hLabel, 0x0000FF)
GUICtrlSetTip($hLabel, "Top-level Domain")

Global $hLabelNotAvailable = GUICtrlCreateLabel(@CRLF & @CRLF  & "  NOT AVAILABLE!", 112, 110, 275, 183)
GUICtrlSetFont($hLabelNotAvailable, 22, 600, -1, "Tahoma")
GUICtrlSetColor($hLabelNotAvailable, 0xAAAAAA)
GUICtrlSetBkColor($hLabelNotAvailable, 0xFFFFFF)
GUICtrlSetState($hLabelNotAvailable, $GUI_HIDE)

Global $hPic = GUICtrlCreatePic("", 112, 110, 275, 183)

GUICtrlSetState($hButton, $GUI_FOCUS)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            GUISetCursor(15, 1) ; WAIT
            $sTLD = GetCountryTLD(GUICtrlRead($hInput))
            SetNationalFlag($hPic, $sTLD, $hLabelNotAvailable)
            If $sTLD Then
                GUICtrlSetData($hLabel, "." & $sTLD)
            Else
                GUICtrlSetData($hLabel, "")
            EndIf
            GUISetCursor(-1, 0) ; restore default
        Case $hComboBox
            GUICtrlSetData($hInput, GUICtrlRead($hComboBox))
    EndSwitch
WEnd

Func SetNationalFlag($hPicControl, $sMoniker, $hLabelControl)
    Local $vData = InetRead(StringFormat($sFormat, StringLower($sMoniker)), 16)
    If $vData Then
        _GUICtrlSetGIF($hPicControl, $vData)
        GUICtrlSetState($hLabelControl, $GUI_HIDE)
        GUICtrlSetState($hPicControl, $GUI_SHOW)
    Else
        GUICtrlSetState($hPicControl, $GUI_HIDE)
        GUICtrlSetState($hLabelControl, $GUI_SHOW)
    EndIf
EndFunc

Func GetCountryTLD($sCountry)
    Local Enum $GEO_NATION = 0x0001, $GEO_LATITUDE, $GEO_LONGITUDE, $GEO_ISO2, $GEO_ISO3, $GEO_RFC1766, $GEO_LCID, $GEO_FRIENDLYNAME, $GEO_OFFICIALNAME, $GEO_TIMEZONES, $GEO_OFFICIALLANGUAGES, $GEO_ISO_UN_NUMBER, $GEO_PARENT
    Local $sTLD, $aCall
    For $iGEOId = 0 To 0xFFFF
        $aCall = DllCall("kernel32.dll", "int", "GetGeoInfoW", "long", $iGEOId, "int", $GEO_FRIENDLYNAME, "wstr", "", "int", 65536, "word", 0)
        If @error Then Return $sTLD
        If $aCall[3] = $sCountry Then
            $aCall = DllCall("kernel32.dll", "int", "GetGeoInfoW", "long", $iGEOId, "int", $GEO_ISO2, "wstr", "", "int", 65536, "word", 0)
            If @error Then Return $sTLD
            $sTLD = $aCall[3]
            ExitLoop
        EndIf
    Next
    Return $sTLD
EndFunc

Func ListCountries()
    Local Const $GEO_FRIENDLYNAME = 0x0008
    Local $sOut, $aCall
    For $iGEOId = 0 To 0xFFFF
        $aCall = DllCall("kernel32.dll", "int", "GetGeoInfoW", "long", $iGEOId, "int", $GEO_FRIENDLYNAME, "wstr", "", "int", 65536, "word", 0)
        If @error Then ExitLoop
        If $aCall[3] Then $sOut &= $aCall[3] & "|"
    Next
    Return StringTrimRight($sOut, 1)
EndFunc
You can find included GIFAnimation.au3 >here (it's link, follow it). Put that script in the same folder as the example before you run it, it's used to display the national flags without the need to download them to files.

In the example script you will also find GetCountryTLD function. Is that close to what you meant?

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
michaelslamet

Nice script, trancexx, like usual :thumbsup:

My boy like it a lot as his favorite book is a world altas with maps and country flag o:)

Share this post


Link to post
Share on other sites
trancexx

Nice script, trancexx, like usual :thumbsup:

 

My boy like it a lot as his favorite book is a world altas with maps and country flag o:)

Kisses to your young explorer from Dragana :* .


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
michaelslamet

Kisses to your young explorer from Dragana :* .

 

And to his father too? :idiot:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×