WorldWeather.bas
#4
11/24/2026
changed to MODELESS dialog; Jules Marchildon, Dale Yarker
fixed button on popup
added Borje Hagsten's EnableVisualStyles.bas code
made it theme aware
---
looks great on dark mode

Code:
' World Weather - PowerBASIC 10 for Windows
' Visual styles code: Borje Hagsten (public domain)
' Map outlines: simplified Natural Earth data, coordinates in tenths of a degree
#Compile Exe
#Dim All
#Include Once "WinUser.inc"
#Include Once "WinBase.inc"
#Include Once "WinGdi.inc"
#Include Once "WinReg.inc"

Declare Function DwmSetWindowAttribute Lib "Dwmapi.dll" Alias "DwmSetWindowAttribute" _
    (ByVal hwnd As Dword, ByVal dwAttribute As Dword, ByVal pvAttribute As Dword, _
    ByVal cbAttribute As Dword) As Long

Declare Function SetWindowTheme Lib "Uxtheme.dll" Alias "SetWindowTheme" _
    (ByVal hwnd As Dword, ByVal pszSubAppName As Dword, ByVal pszSubIdList As Dword) As Long

Declare Function UxSetPreferredAppMode SDecl (ByVal nMode As Long) As Long
Declare Function UxAllowDarkModeForWindow SDecl (ByVal hWnd As Dword, ByVal bAllow As Long) As Long

%ID_LIST       = 1001
%ID_MAP        = 1002
%ID_TEXT       = 1003
%ID_NEWS       = 1004
%ID_HISTORY    = 1005
%ID_YOUTUBE    = 1006
%ID_GEOGRAPHY  = 1007
%ID_MAPS       = 1008
%ID_CONFLICTS  = 1009
%ID_ECONOMY    = 1010
%ID_CLIMATE    = 1011
%ID_CULTURE    = 1012
%ID_NEWS_LIST  = 2001
%ID_NEWS_CLOSE = 2002
%ID_NEWS_LABEL = 2003
%MAX_COUNTRIES = 300
%MAX_NEWS      = 8

Type PolyPoint
    x As Single
    y As Single
End Type

Type PolyPoints
    n As Long
    xy(1 To 1024) As PolyPoint
End Type

Type AppTheme
    dark As Long
    highContrast As Long
    windowBg As Dword
    textBg As Dword
    textFg As Dword
    subText As Dword
    border As Dword
    listBg As Dword
    listText As Dword
    btnFace As Dword
    btnHover As Dword
    btnPressed As Dword
    btnBorder As Dword
    btnText As Dword
    btnFocus As Dword
    mapOcean As Dword
    mapGrid As Dword
    mapAxis As Dword
    mapLand As Dword
    mapLandEdge As Dword
    mapMarker As Dword
    mapMarkerFill As Dword
End Type

Global gN As Long
Global gName() As String
Global gCap() As String
Global gLat() As Single
Global gLon() As Single
Global gMinLat() As Single
Global gMaxLat() As Single
Global gMinLon() As Single
Global gMaxLon() As Single
Global gInfoText As String
Global gNewsN As Long
Global gNewsTitle() As String
Global gNewsLabel As String
Global gClosing As Long
Global ghActCtx As Long
Global gCookie As Long
Global ghShell32 As Long
Global gTheme As AppTheme
Global gThemeBusy As Long
Global ghUxTheme As Dword
Global gpSetPreferredAppMode As Dword
Global gpAllowDarkModeForWindow As Dword

Sub LoadCountries()
    Local i As Long, rec As String, n As Long

    n = DataCount
    If n > %MAX_COUNTRIES Then n = %MAX_COUNTRIES

    For i = 1 To n
        rec = Read$(i)
        gName(i) = Parse$(rec, "|", 1)
        gCap(i) = Parse$(rec, "|", 2)
        gLat(i) = Val(Parse$(rec, "|", 3))
        gLon(i) = Val(Parse$(rec, "|", 4))
        gMinLat(i) = Val(Parse$(rec, "|", 5))
        gMaxLat(i) = Val(Parse$(rec, "|", 6))
        gMinLon(i) = Val(Parse$(rec, "|", 7))
        gMaxLon(i) = Val(Parse$(rec, "|", 8))
    Next i

    gN = n

Data "Afghanistan|Kabul|34.519|69.181|29.32|38.49|60.53|75.16"
Data "Albania|Tirana|41.328|19.819|39.62|42.69|19.3|21.02"
Data "Algeria|Algiers|36.765|3.049|19.06|37.12|-8.68|12"
Data "Andorra|Andorra|42.5|1.516|41.5|43.5|0.52|2.52"
Data "Angola|Luanda|-8.836|13.232|-17.93|-5.86|11.64|24.08"
Data "Antigua and Barbuda|Saint John's|17.118|-61.85|16.12|18.12|-62.85|-60.85"
Data "Argentina|Buenos Aires|-34.601|-58.399|-52.35|-21.83|-73.42|-53.63"
Data "Armenia|Yerevan|40.183|44.512|38.74|41.25|43.58|46.51"
Data "Australia|Canberra|-35.283|149.129|-39.04|-10.67|113.34|153.57"
Data "Austria|Vienna|48.202|16.365|46.43|49.04|9.48|16.98"
Data "Azerbaijan|Baku|40.397|49.86|38.27|41.86|44.97|50.39"
Data "Bahamas|Nassau|25.083|-77.35|23.71|25.21|-78.41|-77.53"
Data "Bahrain|Manama|26.236|50.583|25.24|27.24|49.58|51.58"
Data "Bangladesh|Dhaka|23.725|90.407|20.67|26.45|88.08|92.67"
Data "Barbados|Bridgetown|13.102|-59.617|12.1|14.1|-60.62|-58.62"
Data "Belarus|Minsk|53.902|27.565|51.32|56.17|23.2|32.69"
Data "Belgium|Brussels|50.835|4.331|49.53|51.48|2.51|6.16"
Data "Belize|Belmopan|17.252|-88.767|15.89|18.5|-89.23|-88.11"
Data "Benin|Cotonou|6.402|2.518|6.14|12.24|0.77|3.8"
Data "Bhutan|Thimphu|27.473|89.639|26.72|28.3|88.81|92.1"
Data "Bolivia|Sucre|-19.041|-65.26|-22.87|-9.76|-69.59|-57.5"
Data "Bosnia and Herzegovina|Sarajevo|43.85|18.383|42.65|45.23|15.75|19.6"
Data "Botswana|Gaborone|-24.646|25.912|-26.83|-17.66|19.9|29.43"
Data "Brazil|Brasilia|-15.781|-47.918|-33.77|5.24|-73.99|-34.73"
Data "Brunei|Bandar Seri Begawan|4.883|114.933|4.01|5.45|114.2|115.45"
Data "Bulgaria|Sofia|42.685|23.315|41.23|44.23|22.38|28.56"
Data "Burkina Faso|Ouagadougou|12.372|-1.527|9.61|15.12|-5.47|2.18"
Data "Burundi|Bujumbura|-3.376|29.36|-4.5|-2.35|29.02|30.75"
Data "Cambodia|Phnom Penh|11.552|104.915|10.49|14.57|102.35|107.61"
Data "Cameroon|Yaounde|3.869|11.515|1.73|12.86|8.49|16.01"
Data "Canada|Ottawa|45.419|-75.702|41.68|71.92|-141|-55.68"
Data "Cape Verde|Praia|14.917|-23.517|13.92|15.92|-24.52|-22.52"
Data "Central African Republic|Bangui|4.367|18.558|2.27|11.14|14.46|27.37"
Data "Chad|Ndjamena|12.115|15.047|7.42|23.41|13.54|23.89"
Data "Chile|Santiago|-33.448|-70.669|-53.86|-17.58|-75.64|-66.99"
Data "China|Beijing|39.931|116.386|20.28|53.46|73.68|135.03"
Data "Colombia|Bogota|4.598|-74.085|-4.3|12.44|-78.99|-66.88"
Data "Comoros|Moroni|-11.704|43.24|-12.7|-10.7|42.24|44.24"
Data "Congo|Brazzaville|-4.257|15.283|-5.04|3.73|11.09|18.45"
Data "Costa Rica|San Jose|9.937|-84.086|8.22|11.22|-85.94|-82.55"
Data "Croatia|Zagreb|45.8|16|42.48|46.5|13.66|19.39"
Data "Cuba|Havana|23.134|-82.366|19.86|23.19|-84.97|-74.18"
Data "Cyprus|Nicosia|35.167|33.367|34.57|35.17|32.26|34"
Data "Czechia|Prague|50.085|14.464|48.56|51.12|12.24|18.85"
Data "Denmark|Kobenhavn|55.681|12.562|54.83|57.73|8.09|10.91"
Data "Djibouti|Djibouti|11.595|43.148|10.93|12.7|41.66|43.32"
Data "Dominica|Roseau|15.301|-61.387|14.3|16.3|-62.39|-60.39"
Data "Dominican Republic|Santo Domingo|18.472|-69.902|17.6|19.88|-71.95|-68.32"
Data "DR Congo|Kinshasa|-4.328|15.313|-13.26|5.26|12.18|31.17"
Data "Ecuador|Quito|-0.213|-78.502|-4.96|1.38|-80.97|-75.23"
Data "Egypt|Cairo|30.052|31.248|22|31.59|24.7|36.87"
Data "El Salvador|San Salvador|13.712|-89.205|13.15|14.42|-90.1|-87.72"
Data "Equatorial Guinea|Malabo|3.75|8.783|1.01|2.28|9.31|11.29"
Data "Eritrea|Asmara|15.333|38.933|12.46|18|36.32|43.08"
Data "Estonia|Tallinn|59.434|24.728|57.47|59.61|23.34|28.13"
Data "Eswatini|Mbabane|-26.317|31.133|-27.29|-25.66|30.68|32.07"
Data "Ethiopia|Addis Ababa|9.035|38.698|3.42|14.96|32.95|47.79"
Data "Fiji|Suva|-18.133|178.442|-18.29|-17.34|177.28|178.72"
Data "Finland|Helsinki|60.178|24.932|59.85|70.16|20.65|31.52"
Data "France|Paris|48.869|2.331|42.34|51.15|-4.59|8.1"
Data "Gabon|Libreville|0.385|9.458|-3.98|2.33|8.8|14.43"
Data "Gambia|Banjul|13.454|-16.592|13.13|13.88|-16.84|-13.85"
Data "Georgia|Tbilisi|41.727|44.789|41.06|43.55|39.95|46.64"
Data "Germany|Berlin|52.524|13.4|47.3|54.98|5.99|15.02"
Data "Ghana|Accra|5.552|-0.219|4.71|11.1|-3.24|1.06"
Data "Greece|Athens|37.985|23.731|36.41|41.83|20.15|26.6"
Data "Grenada|Saint George's|12.053|-61.742|11.05|13.05|-62.74|-60.74"
Data "Guatemala|Guatemala|14.623|-90.529|13.74|17.82|-92.23|-88.22"
Data "Guinea|Conakry|9.533|-13.682|7.31|12.59|-15.13|-7.83"
Data "Guinea-Bissau|Bissau|11.865|-15.598|11.04|12.63|-16.68|-13.7"
Data "Guyana|Georgetown|6.802|-58.167|1.27|8.37|-61.41|-56.54"
Data "Haiti|Port-au-Prince|18.543|-72.338|18.03|19.92|-74.46|-71.62"
Data "Honduras|Tegucigalpa|14.104|-87.219|12.98|16.01|-89.35|-83.15"
Data "Hungary|Budapest|47.502|19.081|45.76|48.62|16.2|22.71"
Data "Iceland|Reykjavik|64.15|-21.95|63.5|66.53|-24.33|-13.61"
Data "India|New Delhi|28.6|77.2|7.97|35.49|68.18|97.4"
Data "Indonesia|Jakarta|-6.172|106.827|-4.11|4.31|108.95|119"
Data "Iran|Tehran|35.674|51.422|25.08|39.71|44.11|63.32"
Data "Iraq|Baghdad|33.341|44.392|29.1|37.39|38.79|48.57"
Data "Ireland|Dublin|53.335|-6.251|51.67|55.13|-9.98|-6.03"
Data "Israel|Jerusalem|31.778|35.207|29.5|33.28|34.27|35.84"
Data "Italy|Rome|41.898|12.481|37.91|47.12|6.75|18.48"
Data "Ivory Coast|Yamoussoukro|6.818|-5.276|4.34|10.52|-8.6|-2.56"
Data "Jamaica|Kingston|17.977|-76.767|17.7|18.52|-78.34|-76.2"
Data "Japan|Tokyo|35.687|139.749|31.03|41.38|129.41|141.91"
Data "Jordan|Amman|31.952|35.931|29.2|33.38|34.92|39.2"
Data "Kazakhstan|Astana|51.181|71.428|40.66|55.39|46.47|87.36"
Data "Kenya|Nairobi|-1.281|36.815|-4.68|5.51|33.89|41.86"
Data "Kiribati|Tarawa|1.338|173.018|0.34|2.34|172.02|174.02"
Data "Kuwait|Kuwait City|29.372|47.976|28.53|30.06|46.57|48.42"
Data "Kyrgyzstan|Bishkek|42.875|74.583|39.28|43.3|69.46|80.26"
Data "Laos|Vientiane|17.967|102.6|13.88|22.46|100.12|107.56"
Data "Latvia|Riga|56.95|24.1|55.62|57.97|21.06|28.18"
Data "Lebanon|Beirut|33.874|35.508|33.09|34.64|35.13|36.61"
Data "Lesotho|Maseru|-29.317|27.483|-30.65|-28.65|27|29.33"
Data "Liberia|Monrovia|6.315|-10.8|4.36|8.54|-11.44|-7.54"
Data "Libya|Tripoli|32.892|13.18|19.58|33.14|9.32|25.16"
Data "Liechtenstein|Vaduz|47.134|9.517|46.13|48.13|8.52|10.52"
Data "Lithuania|Vilnius|54.683|25.317|53.91|56.37|21.06|26.59"
Data "Luxembourg|Luxembourg|49.612|6.13|49.44|50.13|5.67|6.24"
Data "Madagascar|Antananarivo|-18.915|47.515|-25.6|-12.04|43.25|50.48"
Data "Malawi|Lilongwe|-13.983|33.783|-16.8|-9.23|32.69|35.77"
Data "Malaysia|Kuala Lumpur|3.169|101.698|0.77|6.93|109.66|119.18"
Data "Maldives|Male|4.167|73.5|3.17|5.17|72.5|74.5"
Data "Mali|Bamako|12.652|-8.002|10.1|24.97|-12.17|4.27"
Data "Malta|Valletta|35.9|14.515|34.9|36.9|13.51|15.51"
Data "Marshall Islands|Majuro|7.103|171.38|6.1|8.1|170.38|172.38"
Data "Mauritania|Nouakchott|18.086|-15.975|14.62|27.4|-17.06|-4.92"
Data "Mauritius|Port Louis|-20.167|57.5|-21.17|-19.17|56.5|58.5"
Data "Mexico|Mexico City|19.444|-99.133|14.54|32.72|-117.13|-86.81"
Data "Micronesia|Palikir|6.917|158.15|5.92|7.92|157.15|159.15"
Data "Moldova|Chisinau|47.005|28.858|45.49|48.47|26.62|30.02"
Data "Monaco|Monaco|43.74|7.407|42.74|44.74|6.41|8.41"
Data "Mongolia|Ulaanbaatar|47.919|106.915|41.6|52.05|87.75|119.77"
Data "Montenegro|Podgorica|42.466|19.266|41.88|43.52|18.45|20.34"
Data "Morocco|Rabat|34.025|-6.836|21.42|35.76|-17.02|-1.12"
Data "Mozambique|Maputo|-25.953|32.587|-26.74|-10.32|30.18|40.78"
Data "Myanmar|Naypyidaw|19.769|96.117|9.93|28.34|92.3|101.18"
Data "Namibia|Windhoek|-22.57|17.084|-29.05|-16.94|11.73|25.08"
Data "Nauru|Yaren|-0.533|166.917|-1.53|0.47|165.92|167.92"
Data "Nepal|Kathmandu|27.719|85.315|26.4|30.42|80.09|88.17"
Data "Netherlands|Amsterdam|52.352|4.915|50.8|53.51|3.31|7.09"
Data "New Zealand|Wellington|-41.3|174.783|-46.64|-40.49|166.51|174.25"
Data "Nicaragua|Managua|12.155|-86.27|10.73|15.02|-87.67|-83.15"
Data "Niger|Niamey|13.519|2.115|11.66|23.47|0.3|15.9"
Data "Nigeria|Abuja|9.085|7.531|4.24|13.87|2.69|14.58"
Data "North Korea|Pyongyang|39.021|125.753|37.67|42.99|124.27|130.78"
Data "North Macedonia|Skopje|42|21.433|40.84|42.32|20.46|22.95"
Data "Norway|Oslo|59.919|10.748|58.08|71.19|4.99|31.29"
Data "Oman|Muscat|23.613|58.593|16.65|24.92|52|59.81"
Data "Pakistan|Islamabad|33.702|73.165|23.69|37.13|60.87|77.84"
Data "Palau|Melekeok|7.487|134.627|6.49|8.49|133.63|135.63"
Data "Palestine|Ramallah|31.9|35.204|31.35|32.53|34.93|35.55"
Data "Panama|Panama City|8.97|-79.535|7.22|9.61|-82.97|-77.24"
Data "Papua New Guinea|Port Moresby|-9.465|147.193|-10.65|-2.6|141|150.8"
Data "Paraguay|Asuncion|-25.294|-57.643|-27.55|-19.34|-62.69|-54.29"
Data "Peru|Lima|-12.046|-77.052|-18.35|-0.06|-81.41|-68.67"
Data "Philippines|Manila|14.606|120.98|12.54|18.51|119.88|124.18"
Data "Poland|Warsaw|52.252|20.998|49.03|54.85|14.07|24.03"
Data "Portugal|Lisbon|38.725|-9.147|36.84|42.28|-9.53|-6.39"
Data "Qatar|Doha|25.287|51.533|24.56|26.11|50.74|51.61"
Data "Romania|Bucharest|44.435|26.098|43.69|48.22|20.22|29.63"
Data "Russia|Moscow|55.754|37.614|41.15|77.7|27.29|180"
Data "Rwanda|Kigali|-1.952|30.059|-2.92|-1.13|29.02|30.82"
Data "Saint Kitts and Nevis|Basseterre|17.302|-62.717|16.3|18.3|-63.72|-61.72"
Data "Saint Lucia|Castries|14.002|-61|13|15|-62|-60"
Data "Saint Vincent and the Grenadines|Kingstown|13.148|-61.212|12.15|14.15|-62.21|-60.21"
Data "Samoa|Apia|-13.842|-171.739|-14.84|-12.84|-172.74|-170.74"
Data "San Marino|San Marino|43.936|12.442|42.94|44.94|11.44|13.44"
Data "Sao Tome and Principe|Sao Tome|0.333|6.733|-0.67|1.33|5.73|7.73"
Data "Saudi Arabia|Riyadh|24.643|46.771|16.35|32.16|34.63|55.67"
Data "Senegal|Dakar|14.718|-17.475|12.33|16.6|-17.62|-11.47"
Data "Serbia|Belgrade|44.821|20.466|42.25|46.17|18.83|22.99"
Data "Seychelles|Victoria|-4.617|55.45|-5.62|-3.62|54.45|56.45"
Data "Sierra Leone|Freetown|8.472|-13.236|6.79|10.05|-13.25|-10.23"
Data "Singapore|Singapore|1.295|103.854|0.29|2.29|102.85|104.85"
Data "Slovakia|Bratislava|48.15|17.117|47.76|49.57|16.88|22.56"
Data "Slovenia|Ljubljana|46.055|14.515|45.45|46.85|13.7|16.56"
Data "Solomon Islands|Honiara|-9.438|159.95|-8.54|-7.32|158.21|159.92"
Data "Somalia|Mogadishu|2.069|45.365|-1.68|12.02|40.98|51.13"
Data "South Africa|Bloemfontein|-29.12|26.23|-34.82|-22.09|16.34|32.83"
Data "South Korea|Seoul|37.568|126.998|34.39|38.61|126.12|129.47"
Data "South Sudan|Juba|7|30|3.51|12.25|23.89|35.3"
Data "Spain|Madrid|40.402|-3.685|35.95|43.75|-9.39|3.04"
Data "Sri Lanka|Colombo|6.932|79.858|5.97|9.82|79.7|81.79"
Data "Sudan|Khartoum|15.59|32.532|8.23|22|21.94|38.41"
Data "Suriname|Paramaribo|5.835|-55.167|1.82|6.03|-58.04|-53.96"
Data "Sweden|Stockholm|59.353|18.095|55.36|69.11|11.03|23.9"
Data "Switzerland|Bern|46.917|7.467|45.78|47.83|6.02|10.44"
Data "Syria|Damascus|33.502|36.298|32.31|37.23|35.7|42.35"
Data "Tajikistan|Dushanbe|38.56|68.774|36.74|40.96|67.44|74.98"
Data "Tanzania|Dar es Salaam|-6.798|39.266|-11.72|-0.95|29.34|40.32"
Data "Thailand|Bangkok|13.752|100.515|5.69|20.42|97.38|105.59"
Data "Timor-Leste|Dili|-8.559|125.579|-9.39|-8.27|124.97|127.34"
Data "Togo|Lome|6.134|1.221|5.93|11.02|-0.05|1.87"
Data "Tonga|Nukualofa|-21.139|-175.221|-22.14|-20.14|-176.22|-174.22"
Data "Trinidad and Tobago|Port-of-Spain|10.652|-61.517|10|10.89|-61.95|-60.9"
Data "Tunisia|Tunis|36.803|10.18|30.31|37.35|7.52|11.49"
Data "Turkiye|Ankara|39.929|32.862|35.82|42.04|26.17|44.79"
Data "Turkmenistan|Ashgabat|37.95|58.383|35.27|42.75|52.5|66.55"
Data "Tuvalu|Funafuti|-8.517|179.217|-9.52|-7.52|178.22|180.22"
Data "Uganda|Kampala|0.319|32.581|-1.44|4.25|29.58|35.04"
Data "Ukraine|Kiev|50.435|30.515|45.29|52.34|22.09|40.08"
Data "United Arab Emirates|Abu Dhabi|24.467|54.367|22.5|26.06|51.58|56.4"
Data "United Kingdom|London|51.502|-0.119|49.96|58.63|-6.15|1.68"
Data "United States|Washington, D.C.|38.901|-77.011|25.08|49.39|-124.69|-66.96"
Data "Uruguay|Montevideo|-34.856|-56.173|-34.95|-30.11|-58.43|-53.21"
Data "Uzbekistan|Tashkent|41.314|69.293|37.15|45.59|55.93|73.06"
Data "Vanuatu|Port Vila|-17.733|168.317|-15.74|-14.63|166.63|167.27"
Data "Vatican City|Vatican City|41.903|12.453|40.9|42.9|11.45|13.45"
Data "Venezuela|Caracas|10.503|-66.919|0.72|12.16|-73.31|-59.76"
Data "Vietnam|Hanoi|21.035|105.848|8.6|23.35|102.17|109.34"
Data "Yemen|Sanaa|15.357|44.205|12.59|19|42.6|53.11"
Data "Zambia|Lusaka|-15.415|28.281|-17.96|-8.24|21.89|33.49"
Data "Zimbabwe|Harare|-17.816|31.043|-22.27|-15.51|25.26|32.85"

End Sub

Function UrlEncode(s As String) As String
    Local i As Long, c As Long, Res As String
    For i = 1 To Len(s)
        c = Asc(Mid$(s, i, 1))
        If (c >= 48 And c <= 57) Or (c >= 65 And c <= 90) Or (c >= 97 And c <= 122) Or c = 45 Or c = 46 Or c = 95 Or c = 126 Then
            Res = Res & Chr$(c)
        ElseIf c = 32 Then
            Res = Res & "+"
        ElseIf c = 39 Then
            Res = Res & "%27"
        ElseIf c = 34 Then
            Res = Res & "%22"
        ElseIf c > 127 Then
            Select Case c
                Case 145, 146
                    Res = Res & "%27"
                Case 147, 148
                    Res = Res & "%22"
                Case 150, 151
                    Res = Res & "-"
                Case Else
                    Res = Res & "+"
            End Select
        Else
            Res = Res & "%" & Right$("0" & Hex$(c), 2)
        End If
    Next i
    Function = Res
End Function

Function DecodeXml(Txt As String) As String
    Local s As String
    s = Txt
    Replace "&amp;" With "&" In s
    Replace "&lt;" With "<" In s
    Replace "&gt;" With ">" In s
    Replace "&quot;" With Chr$(34) In s
    Replace "&apos;" With "'" In s
    Replace "&nbsp;" With " " In s
    Replace "'" With "'" In s
    Replace "&#x27;" With "'" In s
    Replace "’" With "'" In s
    Replace "‘" With "'" In s
    Replace "“" With Chr$(34) In s
    Replace "”" With Chr$(34) In s
    Function = s
End Function

Function TagValue(s As String, tag As String) As String
    Local p1 As Long, p2 As Long, v As String
    p1 = InStr(s, "<" & tag & ">")
    If p1 = 0 Then Exit Function
    p1 = p1 + Len(tag) + 2
    p2 = InStr(p1, s, "</" & tag & ">")
    If p2 = 0 Then Exit Function
    v = Mid$(s, p1, p2 - p1)
    If Left$(v, 9) = "<![CDATA[" Then v = Mid$(v, 10)
    If Right$(v, 3) = "]]>" Then v = Left$(v, Len(v) - 3)
    Function = Trim$(v)
End Function

Function JsonValue(s As String, key As String) As String
    Local p As Long, q As Long, c As String, v As String
    p = InStr(s, Chr$(34) & key & Chr$(34))
    If p = 0 Then Exit Function
    p = InStr(p, s, ":")
    If p = 0 Then Exit Function
    Incr p
    Do While p <= Len(s)
        c = Mid$(s, p, 1)
        If c <> " " And c <> Chr$(9) And c <> Chr$(13) And c <> Chr$(10) Then Exit Do
        Incr p
    Loop
    If Mid$(s, p, 1) = Chr$(34) Then
        Incr p
        q = InStr(p, s, Chr$(34))
        If q = 0 Then q = Len(s) + 1
        v = Mid$(s, p, q - p)
    Else
        q = p
        Do While q <= Len(s)
            c = Mid$(s, q, 1)
            If c = "," Or c = "}" Or c = "]" Then Exit Do
            Incr q
        Loop
        v = Trim$(Mid$(s, p, q - p))
    End If
    Function = v
End Function

Function GetWeather(lat As Single, lon As Single) As String
    Local fnum As Long
    Local req As String, resp As String, buf As String, body As String
    Local p As Long
    Local latstr As String, lonstr As String
    Local desc As String, tc As String, tf As String, fc As String, ff As String
    Local hum As String, pres As String

    latstr = Format$(lat, "0.0000")
    lonstr = Format$(lon, "0.0000")
    req = "/" & latstr & "," & lonstr & "?format=j1"

    fnum = FreeFile
    Tcp Open "http" At "wttr.in" As #fnum TimeOut 10000
    If Err Then
        Function = "Weather service unavailable (" & Error$(Err) & "). Check the Internet connection."
        Exit Function
    End If
    Tcp Print #fnum, "GET " & req & " HTTP/1.0"
    Tcp Print #fnum, "Host: wttr.in"
    Tcp Print #fnum, "User-Agent: WorldWeather/1.0"
    Tcp Print #fnum, "Accept: */*"
    Tcp Print #fnum, "Connection: close"
    Tcp Print #fnum, ""
    Do
        Tcp Recv #fnum, 4096, buf$
        If Len(buf$) = 0 Then Exit Do
        resp$ = resp$ & buf$
        If Len(resp$) > 131072 Then Exit Do
    Loop
    Tcp Close #fnum
    If InStr(Left$(resp$, 32), " 200 ") = 0 Then
        Function = "Weather service did not return valid data."
        Exit Function
    End If
    p = InStr(resp$, Chr$(13, 10, 13, 10))
    If p > 0 Then
        body$ = Mid$(resp$, p + 4)
    Else
        p = InStr(resp$, Chr$(10, 10))
        If p > 0 Then body$ = Mid$(resp$, p + 2) Else body$ = resp$
    End If
    body$ = Utf8ToChr$(body$)

    tc$ = JsonValue(body$, "temp_C")
    tf$ = JsonValue(body$, "temp_F")
    fc$ = JsonValue(body$, "FeelsLikeC")
    ff$ = JsonValue(body$, "FeelsLikeF")
    hum$ = JsonValue(body$, "humidity")
    pres$ = JsonValue(body$, "pressure")
    p = InStr(body$, Chr$(34) & "weatherDesc" & Chr$(34))
    If p > 0 Then desc$ = JsonValue(Mid$(body$, p), "value")
    desc$ = Trim$(desc$)
    If desc$ = "" Then desc$ = "Current conditions"

    If tc$ = "" Then
        Function = "No weather data returned."
    Else
        Function = desc$ & ", " & tc$ & Chr$(176) & "C / " & tf$ & Chr$(176) & "F" & _
                   " (feels " & fc$ & Chr$(176) & "C / " & ff$ & Chr$(176) & "F), " & _
                   "humidity " & hum$ & "%, pressure " & pres$ & " hPa"
    End If
End Function

Function GetNews(query As String) As Long
    Local fnum As Long
    Local srv As String, req As String
    Local resp As String, buf As String, body As String
    Local p As Long, p1 As Long, p2 As Long
    Local Item As String, title As String, link As String, n As Long

    gNewsN = 0
    srv = "www.bing.com"
    req = "/news/search?q=" & UrlEncode(query) & "&format=rss"

    fnum = FreeFile
    Tcp Open "http" At srv As #fnum TimeOut 12000
    If Err Then Function = 0 : Exit Function
    Tcp Print #fnum, "GET " & req & " HTTP/1.0"
    Tcp Print #fnum, "Host: " & srv
    Tcp Print #fnum, "User-Agent: WorldWeather/1.0"
    Tcp Print #fnum, "Accept: */*"
    Tcp Print #fnum, "Connection: close"
    Tcp Print #fnum, ""
    Do
        Tcp Recv #fnum, 4096, buf$
        If Len(buf$) = 0 Then Exit Do
        resp$ = resp$ & buf$
        If Len(resp$) > 262144 Then Exit Do
    Loop
    Tcp Close #fnum
    If InStr(Left$(resp$, 32), " 200 ") = 0 Then Function = 0 : Exit Function
    p = InStr(resp$, Chr$(13, 10, 13, 10))
    If p > 0 Then
        body$ = Mid$(resp$, p + 4)
    Else
        p = InStr(resp$, Chr$(10, 10))
        If p > 0 Then body$ = Mid$(resp$, p + 2) Else body$ = resp$
    End If
    body$ = Utf8ToChr$(body$)

    p = 1
    Do
        p1 = InStr(p, body$, "<item>")
        If p1 = 0 Then Exit Do
        p2 = InStr(p1, body$, "</item>")
        If p2 = 0 Then Exit Do
        Item$ = Mid$(body$, p1, p2 - p1)
        title$ = DecodeXml(TagValue(Item$, "title"))
        link$ = DecodeXml(TagValue(Item$, "link"))
        If Len(title$) > 0 And Len(link$) > 0 Then
            Incr n
            gNewsTitle(n) = title$
            If n >= %MAX_NEWS Then Exit Do
        End If
        p = p2 + 7
    Loop
    gNewsN = n
    Function = n
End Function

Sub OpenUrl(urlText As String)
    Local cmdline As String
    cmdline = "cmd.exe /c start " & Chr$(34) & Chr$(34) & " " & Chr$(34) & urlText & Chr$(34)
    Shell cmdline, %SW_Hide
End Sub

Sub DrawMap(hDlg As Dword, idx As Long)
    Local pp As PolyPoints
    Local i As Long, p As Long, k As Long, np As Long, ix As Long
    Local lon As Single, lat As Single
    Local s As String, t As String
    Local q As Long

    Graphic Attach hDlg, %ID_MAP, ReDraw
    Graphic Scale (-180, 90) - (180, -90)
    Graphic Clear gTheme.mapOcean

    Graphic Width 1
    For lon = -150 To 150 Step 30
        Graphic Line (lon, 90) - (lon, -90), gTheme.mapGrid
    Next lon
    For lat = -60 To 60 Step 30
        Graphic Line (-180, lat) - (180, lat), gTheme.mapGrid
    Next lat
    Graphic Line (-180, 0) - (180, 0), gTheme.mapAxis
    Graphic Line (0, 90) - (0, -90), gTheme.mapAxis

    ix = 1
    p = Val(Read$(ix)) : Incr ix
    For i = 1 To p
        np = Val(Read$(ix)) : Incr ix
        pp.n = np
        k = 0
        Do
            s = Read$(ix) : Incr ix
            Do While Len(s) > 0 And k < np
                t = Parse$(s, ";", 1)
                Incr k
                pp.xy(k).x = Val(Parse$(t, ",", 1)) / 10
                pp.xy(k).y = Val(Parse$(t, ",", 2)) / 10
                q = InStr(s, ";")
                If q > 0 Then s = Mid$(s, q + 1) Else s = ""
            Loop
        Loop Until k >= np
        Graphic Polygon pp, gTheme.mapLandEdge, gTheme.mapLand
    Next i

    If idx >= 1 And idx <= gN Then
        Graphic Width 2
        Graphic Box (gMinLon(idx), gMaxLat(idx)) - (gMaxLon(idx), gMinLat(idx)), 0, gTheme.mapMarker
        Graphic Width 1
        Graphic Ellipse (gLon(idx) - 2.4, gLat(idx) + 2.4) - (gLon(idx) + 2.4, gLat(idx) - 2.4), gTheme.mapMarker, gTheme.mapMarkerFill
        Graphic Line (gLon(idx) - 6, gLat(idx)) - (gLon(idx) + 6, gLat(idx)), gTheme.mapMarker
        Graphic Line (gLon(idx), gLat(idx) - 6) - (gLon(idx), gLat(idx) + 6), gTheme.mapMarker
    End If

    Graphic ReDraw

Data "69"
Data "114"
Data "1070,770;1141,758;1094,742;1270,736;1313,708;1405,728;1786,694;1795,626;1635,599;1568,510;1559,568;1645,626;1422,590;1351,547;1414,522;1382,463;1275,398;1291,351;1265,344;1253,396;1210,389;1216,410"
Data "1180,392;1224,374;1192,349;1217,282;1159,228;1059,198;1093,134;1052,86;1001,134;992,92;1042,13;914,228;803,159;775,80;726,214;664,254;480,300;518,240;564,264;598,223;553,172;435,126"
Data "324,298;427,117;510,106;392,-47;408,-147;348,-198;322,-288;258,-339;184,-341;118,-181;137,-107;94,37;43,63;-90,48;-166,122;-170,219;-59,358;95,374;103,338;191,303;215,328;338,310"
Data "362,366;276,367;262,395;417,420;367,452;391,473;339,444;308,466;288,410;226,403;225,364;131,457;185,402;161,380;89,444;31,431;-22,367;-89,369;-94,430;-14,440;-46,487;81,535"
Data "85,571;109,540;197,544;233,592;291,600;213,607;254,651;222,657;129,554;104,595;57,586;50,620;246,710;403,679;332,666;370,638;440,661;434,686;685,681;667,710;726,728;724,662"
Data "747,728;815,718;805,736;1044,777"
Data "63"
Data "-906,695;-813,676;-932,620;-947,590;-923,571;-823,552;-799,512;-765,565;-781,623;-738,624;-676,582;-646,603;-557,522;-711,468;-651,492;-645,462;-598,459;-671,451;-764,392;-757,356;-813,314;-804,252"
Data "-841,301;-966,283;-963,193;-870,215;-889,159;-834,153;-814,88;-718,124;-717,91;-699,122;-619,107;-513,42;-504,-1;-347,-73;-409,-219;-651,-411;-682,-524;-750,-523;-702,-198;-812,-61;-782,83;-809,72"
Data "-875,133;-1035,183;-1139,316;-1100,228;-1244,403;-1228,490;-1341,581;-1517,592;-1506,613;-1648,544;-1570,589;-1661,615;-1608,648;-1681,657;-1617,661;-1668,684;-1566,714;-961,673;-952,719"
Data "22"
Data "-586,-642;-657,-680;-608,-737;-772,-767;-737,-779;-780,-792;-582,-832;-286,-803;-353,-781;-69,-709;386,-698;545,-658;689,-679;699,-723;880,-662;1351,-653;1712,-717;1636,-762;1670,-788;1598,-810;1800,-847;1800,-900"
Data "14"
Data "1436,-138;1531,-261;1500,-374;1406,-380;1378,-329;1360,-349;1313,-315;1150,-342;1142,-218;1324,-111;1365,-119;1355,-150;1402,-177;1421,-110"
Data "20"
Data "-271,835;-208,827;-314,820;-122,813;-200,802;-177,801;-217,766;-194,743;-264,702;-224,701;-398,655;-434,601;-516,636;-540,672;-509,699;-547,696;-514,706;-586,755;-733,780;-434,832"
Data "13"
Data "-1800,-900;-1791,-841;-1431,-850;-1536,-837;-1568,-811;-1464,-803;-1584,-769;-1006,-753;-1037,-726;-749,-739;-674,-725;-672,-669;-572,-635"
Data "10"
Data "-866,732;-618,669;-680,663;-662,619;-786,646;-729,677;-790,702;-887,704;-902,722;-858,738"
Data "8"
Data "-685,831;-619,824;-806,762;-895,765;-850,775;-869,802;-818,805;-916,819"
Data "6"
Data "1341,-12;1446,-39;1507,-106;1376,-84;1379,-54;1305,-9"
Data "6"
Data "1179,18;1162,-40;1091,-5;1167,69;1192,54;1173,32"
Data "5"
Data "501,-136;471,-249;440,-250;444,-162;492,-120"
Data "4"
Data "-1142,731;-1065,731;-1024,688;-1194,716"
Data "3"
Data "1058,-58;953,55;1061,-31"
Data "5"
Data "1410,371;1310,339;1313,314;1294,333;1419,400"
Data "5"
Data "-30,586;14,513;-52,500;-30,540;-50,586"
Data "5"
Data "575,707;516,715;556,751;688,765;554,724"
Data "4"
Data "-1205,714;-1259,719;-1249,743;-1155,735"
Data "3"
Data "-145,665;-187,635;-243,656"
Data "4"
Data "182,797;215,790;159,768;104,796"
Data "5"
Data "-1750,666;-1699,660;-1730,642;-1800,650;-1800,690"
Data "4"
Data "-452,-780;-433,-800;-542,-806;-487,-780"
Data "3"
Data "1730,-409;1731,-438;1667,-462"
Data "7"
Data "1252,14;1202,2;1233,-6;1232,-53;1210,-26;1194,-54;1200,6"
Data "3"
Data "-947,771;-798,749;-971,768"
Data "4"
Data "-870,797;-908,782;-967,802;-924,813"
Data "4"
Data "-561,507;-531,467;-593,476;-559,516"
Data "4"
Data "-1082,762;-1137,744;-1177,752;-1105,764"
Data "4"
Data "1746,-362;1785,-377;1752,-417;1726,-345"
Data "3"
Data "1436,508;1421,460;1426,544"
Data "3"
Data "-684,-710;-750,-717;-702,-689"
Data "3"
Data "1439,442;1400,416;1420,456"
Data "3"
Data "1086,-68;1083,-78;1060,-59"
Data "3"
Data "999,789;912,803;1002,798"
Data "3"
Data "-678,-538;-747,-528;-694,-525"
Data "3"
Data "-68,523;-97,539;-57,546"
Data "3"
Data "1213,185;1241,125;1201,150"
Data "5"
Data "-797,228;-742,203;-778,199;-850,219;-823,232"
Data "3"
Data "-852,657;-801,637;-872,635"
Data "3"
Data "-1004,738;-967,717;-1015,734"
Data "4"
Data "1264,84;1254,56;1219,72;1254,98"
Data "3"
Data "1454,-408;1483,-409;1460,-436"
Data "3"
Data "254,804;230,794;174,803"
Data "3"
Data "-985,767;-1025,756;-1026,763"
Data "3"
Data "-726,199;-683,186;-734,196"
Data "3"
Data "-932,728;-960,734;-905,739"
Data "3"
Data "812,62;802,98;818,75"
Data "3"
Data "1051,783;994,779;1021,794"
Data "3"
Data "1451,756;1370,753;1388,761"
Data "3"
Data "-596,-800;-602,-810;-663,-803"
Data "3"
Data "-1162,776;-1171,765;-1228,761"
Data "3"
Data "155,382;151,366;124,376"
Data "3"
Data "92,412;88,389;82,410"
Data "3"
Data "1103,187;1086,194;1108,201"
Data "3"
Data "1244,-101;1240,-93;1273,-84"
Data "3"
Data "1212,228;1201,236;1215,253"
Data "3"
Data "1240,103;1224,97;1241,112"
Data "3"
Data "-1001,783;-1042,787;-1055,793"
Data "3"
Data "-956,691;-998,694;-982,701"
Data "3"
Data "1255,122;1248,101;1243,126"
Data "3"
Data "1287,11;1281,-9;1276,18"
Data "3"
Data "-586,-511;-580,-519;-612,-518"
Data "3"
Data "-759,672;-759,683;-751,676"
Data "3"
Data "1305,-31;1308,-39;1279,-34"
Data "3"
Data "1520,-55;1483,-58;1515,-42"
Data "3"
Data "-1327,540;-1318,541;-1312,522"
Data "3"
Data "703,-497;688,-498;689,-486"
Data "3"
Data "127,556;121,548;109,558"
Data "3"
Data "-1530,571;-1547,575;-1526,579"
Data "3"
Data "-1787,709;-1800,715;-1776,713"
End Sub

Sub ShowWeather(hDlg As Dword, idx As Long)
    Local latdir As String, londir As String
    Local coord As String, weather As String, msg As String

    latdir = "N" : If gLat(idx) < 0 Then latdir = "S"
    londir = "E" : If gLon(idx) < 0 Then londir = "W"
    coord = Format$(Abs(gLat(idx)), "0.0000") & " " & latdir & ", " & _
            Format$(Abs(gLon(idx)), "0.0000") & " " & londir

    msg = gName(idx) & $CrLf & _
          "Capital: " & gCap(idx) & " (" & coord & ")" & $CrLf & $CrLf & _
          "Fetching current weather from wttr.in ..."
    Control Set Text hDlg, %ID_TEXT, msg
    Dialog ReDraw hDlg

    weather = GetWeather(gLat(idx), gLon(idx))

    msg = gName(idx) & $CrLf & _
          "Capital: " & gCap(idx) & " (" & coord & ")" & $CrLf & $CrLf & _
          "Current weather: " & weather & $CrLf & $CrLf & _
          "Source: wttr.in - live current conditions." & $CrLf & _
          "Map: red outline = approximate country bounds; red circle = capital."
    gInfoText = msg
    Control Set Text hDlg, %ID_TEXT, msg
    Dialog ReDraw hDlg
End Sub

CallBack Function NewsProc() As Long
    Local idx As Long
    Local q As String, gurl As String
    Local pDis As DRAWITEMSTRUCT Ptr

    Select Case Cb.Msg
        Case %WM_DrawItem
            pDis = Cb.LParam
            If pDis <> 0 Then
                If @pDis.CtlType = %ODT_BUTTON Then
                    DrawOwnerButton pDis
                    Function = 1
                    Exit Function
                End If
            End If
            Function = 0
            Exit Function
        Case %WM_SettingChange, %WM_SysColorChange, %WM_ThemeChanged
            If gThemeBusy Then Exit Function
            BuildTheme
            ApplyNewsTheme Cb.Hndl
            Function = 0
            Exit Function
        Case %WM_Command
            If Cb.Ctl = %ID_NEWS_LIST And Cb.CtlMsg = %LBN_SelChange Then
                ListBox Get Select Cb.Hndl, %ID_NEWS_LIST To idx
                If idx >= 1 And idx <= gNewsN Then
                    q = gNewsLabel & " " & gNewsTitle(idx)
                    gurl = "https://www.google.com/search?q=" & UrlEncode(q)
                    OpenUrl gurl
                    ListBox Unselect Cb.Hndl, %ID_NEWS_LIST, idx
                End If
            ElseIf Cb.Ctl = %ID_NEWS_CLOSE And Cb.CtlMsg = %BN_Clicked Then
                Dialog End Cb.Hndl, 1
            End If
    End Select

    Function = 0
End Function

Sub ShowNewsPopup(hParent As Dword, lbl As String, n As Long)
    Local hNews As Dword
    Local i As Long

    Dialog New Pixels, hParent, "News - " & lbl, , , 760, 518, _
        %WS_Caption Or %WS_SysMenu To hNews
    Control Add Label, hNews, %ID_NEWS_LABEL, "Click a headline to search Google for the article:", 12, 10, 700, 16
    Control Add ListBox, hNews, %ID_NEWS_LIST, , 12, 32, 736, 438, _
        %WS_VScroll Or %WS_HScroll Or %LBS_Notify Or %WS_TabStop
    For i = 1 To n
        ListBox Add hNews, %ID_NEWS_LIST, gNewsTitle(i)
    Next i
    Control Add Button, hNews, %ID_NEWS_CLOSE, "Close", 650, 480, 90, 28, _
        %WS_TabStop Or %BS_OwnerDraw
    Dialog Send hNews, %DM_SetDefID, %ID_NEWS_CLOSE, 0
    ApplyNewsTheme hNews
    Dialog Show Modal hNews, Call NewsProc
End Sub

Sub ShowNews(hParent As Dword)
    Local idx As Long, n As Long
    Local query As String, lbl As String

    ListBox Get Select hParent, %ID_LIST To idx
    If idx >= 1 And idx <= gN Then
        query = gName(idx)
        lbl = gName(idx)
    Else
        query = "world news today"
        lbl = "World"
    End If
    gNewsLabel = lbl

    Control Set Text hParent, %ID_TEXT, "Fetching current news for " & lbl & " ..."
    Dialog ReDraw hParent

    n = GetNews(query)
    If n = 0 Then
        MsgBox "Not Found", %MB_IconInformation, "News - " & lbl
    Else
        ShowNewsPopup hParent, lbl, n
    End If

    Control Set Text hParent, %ID_TEXT, gInfoText
    Dialog ReDraw hParent
End Sub

Sub ShowHistory(hParent As Dword)
    Local idx As Long
    Local q As String, gurl As String

    ListBox Get Select hParent, %ID_LIST To idx
    If idx < 1 Or idx > gN Then
        MsgBox "Select a country first.", %MB_IconInformation, "History"
        Exit Sub
    End If

    q = gName(idx) & " history"
    gurl = "https://www.google.com/search?q=" & UrlEncode(q)
    OpenUrl gurl
End Sub

Sub ShowYouTube(hParent As Dword)
    Local idx As Long
    Local q As String, gurl As String

    ListBox Get Select hParent, %ID_LIST To idx
    If idx < 1 Or idx > gN Then
        MsgBox "Select a country first.", %MB_IconInformation, "YouTube"
        Exit Sub
    End If

    q = gName(idx)
    gurl = "https://www.youtube.com/results?search_query=" & UrlEncode(q)
    OpenUrl gurl
End Sub

Sub ShowGeography(hParent As Dword)
    Local idx As Long
    Local q As String, gurl As String

    ListBox Get Select hParent, %ID_LIST To idx
    If idx < 1 Or idx > gN Then
        MsgBox "Select a country first.", %MB_IconInformation, "Geography"
        Exit Sub
    End If

    q = gName(idx) & " geography"
    gurl = "https://www.google.com/search?q=" & UrlEncode(q)
    OpenUrl gurl
End Sub

Sub ShowMaps(hParent As Dword)
    Local idx As Long
    Local q As String, gurl As String

    ListBox Get Select hParent, %ID_LIST To idx
    If idx < 1 Or idx > gN Then
        MsgBox "Select a country first.", %MB_IconInformation, "Maps"
        Exit Sub
    End If

    q = gName(idx) & " country map"
    gurl = "https://www.google.com/search?q=" & UrlEncode(q)
    OpenUrl gurl
End Sub

Sub ShowEconomy(hParent As Dword)
    Local idx As Long
    Local q As String, gurl As String

    ListBox Get Select hParent, %ID_LIST To idx
    If idx < 1 Or idx > gN Then
        MsgBox "Select a country first.", %MB_IconInformation, "Economy"
        Exit Sub
    End If

    q = gName(idx) & " economy"
    gurl = "https://www.google.com/search?q=" & UrlEncode(q)
    OpenUrl gurl
End Sub

Sub ShowConflicts(hParent As Dword)
    Local idx As Long
    Local q As String, gurl As String

    ListBox Get Select hParent, %ID_LIST To idx
    If idx < 1 Or idx > gN Then
        MsgBox "Select a country first.", %MB_IconInformation, "Current Conflicts"
        Exit Sub
    End If

    q = gName(idx) & " current conflicts ongoing armed conflict"
    gurl = "https://www.google.com/search?q=" & UrlEncode(q)
    OpenUrl gurl
End Sub

Sub ShowClimate(hParent As Dword)
    Local idx As Long
    Local q As String, gurl As String

    ListBox Get Select hParent, %ID_LIST To idx
    If idx < 1 Or idx > gN Then
        MsgBox "Select a country first.", %MB_IconInformation, "Climate"
        Exit Sub
    End If

    q = "climate of " & gName(idx)
    gurl = "https://www.google.com/search?q=" & UrlEncode(q)
    OpenUrl gurl
End Sub

Sub ShowCulture(hParent As Dword)
    Local idx As Long
    Local q As String, gurl As String

    ListBox Get Select hParent, %ID_LIST To idx
    If idx < 1 Or idx > gN Then
        MsgBox "Select a country first.", %MB_IconInformation, "Culture"
        Exit Sub
    End If

    q = "culture of " & gName(idx)
    gurl = "https://www.google.com/search?q=" & UrlEncode(q)
    OpenUrl gurl
End Sub

CallBack Function DlgProc() As Long
    Local idx As Long
    Local pDis As DRAWITEMSTRUCT Ptr

    Select Case Cb.Msg
        Case %WM_DrawItem
            pDis = Cb.LParam
            If pDis <> 0 Then
                If @pDis.CtlType = %ODT_BUTTON Then
                    DrawOwnerButton pDis
                    Function = 1
                    Exit Function
                End If
            End If
            Function = 0
            Exit Function
        Case %WM_SettingChange, %WM_SysColorChange, %WM_ThemeChanged
            If gThemeBusy Then Exit Function
            BuildTheme
            ApplyTheme Cb.Hndl
            Function = 0
            Exit Function
        Case %WM_Close
            If gClosing Then
                Function = 1
                Exit Function
            End If
            gClosing = 1
            Dialog End Cb.Hndl
            Function = 1
            Exit Function
        Case %WM_Command
            If Cb.Ctl = %ID_LIST And Cb.CtlMsg = %LBN_SelChange Then
                ListBox Get Select Cb.Hndl, %ID_LIST To idx
                If idx >= 1 And idx <= gN Then
                    DrawMap Cb.Hndl, idx
                    ShowWeather Cb.Hndl, idx
                End If
            ElseIf Cb.Ctl = %ID_NEWS And Cb.CtlMsg = %BN_Clicked Then
                ShowNews Cb.Hndl
            ElseIf Cb.Ctl = %ID_HISTORY And Cb.CtlMsg = %BN_Clicked Then
                ShowHistory Cb.Hndl
            ElseIf Cb.Ctl = %ID_YOUTUBE And Cb.CtlMsg = %BN_Clicked Then
                ShowYouTube Cb.Hndl
            ElseIf Cb.Ctl = %ID_GEOGRAPHY And Cb.CtlMsg = %BN_Clicked Then
                ShowGeography Cb.Hndl
            ElseIf Cb.Ctl = %ID_MAPS And Cb.CtlMsg = %BN_Clicked Then
                ShowMaps Cb.Hndl
            ElseIf Cb.Ctl = %ID_ECONOMY And Cb.CtlMsg = %BN_Clicked Then
                ShowEconomy Cb.Hndl
            ElseIf Cb.Ctl = %ID_CONFLICTS And Cb.CtlMsg = %BN_Clicked Then
                ShowConflicts Cb.Hndl
            ElseIf Cb.Ctl = %ID_CLIMATE And Cb.CtlMsg = %BN_Clicked Then
                ShowClimate Cb.Hndl
            ElseIf Cb.Ctl = %ID_CULTURE And Cb.CtlMsg = %BN_Clicked Then
                ShowCulture Cb.Hndl
            End If
    End Select

    Function = 0
End Function

Function EnableVisualStyles() As Dword
    Local aCtx As ACTCTX

#If %Def(%UNICODE)
    Local szSys As WStringZ * %Max_Path
#Else
    Local szSys As AsciiZ * %Max_Path
#EndIf

    GetSystemDirectory szSys, SizeOf(szSys)    ' Need path to shell32.dll

    aCtx.cbSize = SizeOf(ACTCTX)
    aCtx.dwFlags = %ACTCTX_FLAG_RESOURCE_NAME_VALID Or _
                   %ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID Or _
                   %ACTCTX_FLAG_HMODULE_VALID
    aCtx.hModule = LoadLibrary("shell32.dll")  ' Use the manifest resource in shell32.dll
    aCtx.lpResourceName = 124                  ' Manifest resource name
    aCtx.lpAssemblyDirectory = VarPtr(szSys)

    ghShell32 = aCtx.hModule
    ghActCtx = CreateActCtx(aCtx)              ' Push the activation context

    If ghActCtx <> %INVALID_HANDLE_VALUE Then
        ActivateActCtx(ghActCtx, gCookie)
    End If

    Function = gCookie
End Function

Sub DisableVisualStyles
    If gCookie Then DeactivateActCtx(0, gCookie)
    If Not ghActCtx = %INVALID_HANDLE_VALUE Then ReleaseActCtx(ghActCtx)
    If ghShell32 Then FreeLibrary(ghShell32)
End Sub

Sub InitDarkModeSupport()
    ghUxTheme = LoadLibrary("uxtheme.dll")
    If ghUxTheme = 0 Then Exit Sub
    gpSetPreferredAppMode = GetProcAddress(ghUxTheme, ByVal 135)
    gpAllowDarkModeForWindow = GetProcAddress(ghUxTheme, ByVal 133)
End Sub

Function SystemUsesDarkMode() As Long
    Local hKey As Dword, uval As Dword, utyp As Dword, ucb As Dword, ures As Long

    uval = 1
    If RegOpenKeyEx(%HKEY_CURRENT_USER, _
            "Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", _
            0, %KEY_QUERY_VALUE, hKey) <> 0 Then Exit Function

    ucb = SizeOf(uval)
    ures = RegQueryValueEx(hKey, "AppsUseLightTheme", ByVal 0, utyp, uval, ucb)
    RegCloseKey hKey
    If ures = 0 And uval = 0 Then Function = 1
End Function

Function SystemUsesHighContrast() As Long
    Local hc As HIGHCONTRAST

    hc.cbSize = SizeOf(hc)
    If SystemParametersInfo(%SPI_GETHIGHCONTRAST, SizeOf(hc), hc, 0) Then
        If (hc.dwFlags And %HCF_HIGHCONTRASTON) Then Function = 1
    End If
End Function

Sub BuildTheme()
    If SystemUsesHighContrast() Then
        gTheme.highContrast = 1
        gTheme.dark = 0
        gTheme.windowBg = GetSysColor(%COLOR_BTNFACE)
        gTheme.textBg = GetSysColor(%COLOR_WINDOW)
        gTheme.textFg = GetSysColor(%COLOR_WINDOWTEXT)
        gTheme.subText = GetSysColor(%COLOR_GRAYTEXT)
        gTheme.border = GetSysColor(%COLOR_WINDOWFRAME)
        gTheme.listBg = GetSysColor(%COLOR_WINDOW)
        gTheme.listText = GetSysColor(%COLOR_WINDOWTEXT)
        gTheme.btnFace = GetSysColor(%COLOR_BTNFACE)
        gTheme.btnHover = GetSysColor(%COLOR_BTNFACE)
        gTheme.btnPressed = GetSysColor(%COLOR_BTNSHADOW)
        gTheme.btnBorder = GetSysColor(%COLOR_WINDOWFRAME)
        gTheme.btnText = GetSysColor(%COLOR_BTNTEXT)
        gTheme.btnFocus = GetSysColor(%COLOR_WINDOWTEXT)
        gTheme.mapOcean = GetSysColor(%COLOR_WINDOW)
        gTheme.mapGrid = GetSysColor(%COLOR_3DLIGHT)
        gTheme.mapAxis = GetSysColor(%COLOR_3DSHADOW)
        gTheme.mapLand = GetSysColor(%COLOR_BTNFACE)
        gTheme.mapLandEdge = GetSysColor(%COLOR_BTNTEXT)
        gTheme.mapMarker = GetSysColor(%COLOR_HIGHLIGHT)
        gTheme.mapMarkerFill = GetSysColor(%COLOR_HIGHLIGHTTEXT)
    ElseIf SystemUsesDarkMode() Then
        gTheme.highContrast = 0
        gTheme.dark = 1
        gTheme.windowBg = RGB(32, 32, 32)
        gTheme.textBg = RGB(26, 26, 26)
        gTheme.textFg = RGB(242, 242, 242)
        gTheme.subText = RGB(176, 176, 176)
        gTheme.border = RGB(62, 62, 62)
        gTheme.listBg = RGB(26, 26, 26)
        gTheme.listText = RGB(242, 242, 242)
        gTheme.btnFace = RGB(45, 45, 48)
        gTheme.btnHover = RGB(57, 57, 61)
        gTheme.btnPressed = RGB(30, 30, 32)
        gTheme.btnBorder = RGB(70, 70, 74)
        gTheme.btnText = RGB(242, 242, 242)
        gTheme.btnFocus = RGB(255, 255, 255)
        gTheme.mapOcean = RGB(14, 26, 36)
        gTheme.mapGrid = RGB(28, 44, 58)
        gTheme.mapAxis = RGB(46, 72, 92)
        gTheme.mapLand = RGB(44, 64, 50)
        gTheme.mapLandEdge = RGB(82, 112, 80)
        gTheme.mapMarker = RGB(255, 107, 107)
        gTheme.mapMarkerFill = RGB(255, 156, 156)
    Else
        gTheme.highContrast = 0
        gTheme.dark = 0
        gTheme.windowBg = GetSysColor(%COLOR_BTNFACE)
        gTheme.textBg = RGB(250, 250, 245)
        gTheme.textFg = RGB(20, 30, 50)
        gTheme.subText = GetSysColor(%COLOR_GRAYTEXT)
        gTheme.border = RGB(200, 200, 200)
        gTheme.listBg = RGB(250, 250, 245)
        gTheme.listText = RGB(20, 30, 50)
        gTheme.btnFace = RGB(253, 253, 253)
        gTheme.btnHover = RGB(238, 246, 255)
        gTheme.btnPressed = RGB(218, 234, 250)
        gTheme.btnBorder = RGB(200, 200, 200)
        gTheme.btnText = RGB(27, 27, 27)
        gTheme.btnFocus = RGB(30, 30, 30)
        gTheme.mapOcean = RGB(232, 244, 255)
        gTheme.mapGrid = RGB(205, 225, 240)
        gTheme.mapAxis = RGB(165, 195, 220)
        gTheme.mapLand = RGB(170, 210, 160)
        gTheme.mapLandEdge = RGB(90, 130, 90)
        gTheme.mapMarker = RGB(215, 30, 30)
        gTheme.mapMarkerFill = RGB(255, 80, 80)
    End If

    If gpSetPreferredAppMode Then
        If gTheme.dark Then
            Call Dword gpSetPreferredAppMode Using UxSetPreferredAppMode(2)
        Else
            Call Dword gpSetPreferredAppMode Using UxSetPreferredAppMode(1)
        End If
    End If
End Sub

Sub ThemeControl(hCtl As Dword)
    Local s As WStringZ * 64

    If gpAllowDarkModeForWindow Then
        If gTheme.dark Then
            Call Dword gpAllowDarkModeForWindow Using UxAllowDarkModeForWindow(hCtl, 1)
        Else
            Call Dword gpAllowDarkModeForWindow Using UxAllowDarkModeForWindow(hCtl, 0)
        End If
    End If

    If gTheme.highContrast Then
        s = ""
    ElseIf gTheme.dark Then
        s = "DarkMode_Explorer"
    Else
        s = "Explorer"
    End If
    SetWindowTheme hCtl, VarPtr(s), 0
    SetWindowPos hCtl, 0, 0, 0, 0, 0, _
        %SWP_NOMOVE Or %SWP_NOSIZE Or %SWP_NOZORDER Or %SWP_NOACTIVATE Or %SWP_FRAMECHANGED
End Sub

Sub ApplyTitleBarTheme(hDlg As Dword)
    Local dark As Long

    dark = gTheme.dark
    If DwmSetWindowAttribute(hDlg, 20, VarPtr(dark), 4) <> 0 Then
        DwmSetWindowAttribute hDlg, 19, VarPtr(dark), 4
    End If
    SetWindowPos hDlg, 0, 0, 0, 0, 0, _
        %SWP_NOMOVE Or %SWP_NOSIZE Or %SWP_NOZORDER Or %SWP_FRAMECHANGED
End Sub

Sub ApplyTheme(hDlg As Dword)
    Local hCtl As Dword, idx As Long

    If gThemeBusy Then Exit Sub
    gThemeBusy = 1

    ThemeControl hDlg
    Dialog Set Color hDlg, -1, gTheme.windowBg
    Control Set Color hDlg, %ID_LIST, gTheme.listText, gTheme.listBg
    Control Set Color hDlg, %ID_TEXT, gTheme.textFg, gTheme.textBg

    Control Handle hDlg, %ID_TEXT To hCtl
    ThemeControl hCtl

    ApplyTitleBarTheme hDlg

    Dialog ReDraw hDlg
    ListBox Get Select hDlg, %ID_LIST To idx
    DrawMap hDlg, idx

    gThemeBusy = 0
End Sub

Sub ApplyNewsTheme(hNews As Dword)
    If gThemeBusy Then Exit Sub
    gThemeBusy = 1

    Dialog Set Color hNews, -1, gTheme.windowBg
    Control Set Color hNews, %ID_NEWS_LABEL, gTheme.textFg, gTheme.windowBg
    Control Set Color hNews, %ID_NEWS_LIST, gTheme.listText, gTheme.listBg

    ApplyTitleBarTheme hNews

    Dialog ReDraw hNews
    gThemeBusy = 0
End Sub

Sub DrawOwnerButton(ByVal pDis As DRAWITEMSTRUCT Ptr)
    Local rc As RECT, trc As RECT
    Local Txt As AsciiZ * 128
    Local sbuf As AsciiZ * 128
    Local s As String
    Local Fill As Dword
    Local hBr As Dword, hPen As Dword, hOldBr As Dword, hOldPen As Dword
    Local hFont As Dword, hOldFont As Dword
    Local pressed As Long, disabled As Long

    If pDis = 0 Then Exit Sub
    If @pDis.CtlType <> %ODT_BUTTON Then Exit Sub

    rc = @pDis.rcItem
    pressed = (@pDis.itemState And %ODS_SELECTED)
    disabled = (@pDis.itemState And %ODS_DISABLED)

    If pressed Then
        Fill = gTheme.btnPressed
    Else
        Fill = gTheme.btnFace
    End If

    hBr = CreateSolidBrush(gTheme.windowBg)
    FillRect @pDis.hDC, rc, hBr
    DeleteObject hBr

    hBr = CreateSolidBrush(Fill)
    hPen = CreatePen(%PS_SOLID, 1, gTheme.btnBorder)
    hOldBr = SelectObject(@pDis.hDC, hBr)
    hOldPen = SelectObject(@pDis.hDC, hPen)
    RoundRect @pDis.hDC, rc.nLeft, rc.nTop, rc.nRight, rc.nBottom, 10, 10
    SelectObject @pDis.hDC, hOldPen
    SelectObject @pDis.hDC, hOldBr
    DeleteObject hPen
    DeleteObject hBr

    GetWindowText @pDis.hwndItem, Txt, SizeOf(Txt)
    s = Txt
    Replace "&" With "" In s
    sbuf = s

    hFont = SendMessage(@pDis.hwndItem, %WM_GETFONT, 0, 0)
    If hFont <> 0 Then hOldFont = SelectObject(@pDis.hDC, hFont)

    SetBkMode @pDis.hDC, %TRANSPARENT
    If disabled Then
        SetTextColor @pDis.hDC, gTheme.subText
    Else
        SetTextColor @pDis.hDC, gTheme.btnText
    End If

    trc = rc
    If pressed Then OffsetRect trc, 1, 1
    DrawText @pDis.hDC, sbuf, Len(sbuf), trc, _
        %DT_CENTER Or %DT_VCENTER Or %DT_SINGLELINE Or %DT_NOPREFIX Or %DT_END_ELLIPSIS

    If hFont <> 0 Then SelectObject @pDis.hDC, hOldFont

    If (@pDis.itemState And %ODS_FOCUS) Then
        trc = rc
        InflateRect trc, -4, -4
        DrawFocusRect @pDis.hDC, trc
    End If
End Sub

Function PBMain() As Long
    Local hDlg As Dword
    Local i As Long

    SetProcessDPIAware

    Dim gName(1 To %MAX_COUNTRIES) As String
    Dim gCap(1 To %MAX_COUNTRIES) As String
    Dim gLat(1 To %MAX_COUNTRIES) As Single
    Dim gLon(1 To %MAX_COUNTRIES) As Single
    Dim gMinLat(1 To %MAX_COUNTRIES) As Single
    Dim gMaxLat(1 To %MAX_COUNTRIES) As Single
    Dim gMinLon(1 To %MAX_COUNTRIES) As Single
    Dim gMaxLon(1 To %MAX_COUNTRIES) As Single
    Dim gNewsTitle(1 To %MAX_NEWS) As String

    Dialog Default Font "Segoe UI", 11

    LoadCountries
    If gN = 0 Then
        MsgBox "Country data could not be loaded.", %MB_IconError, "World Weather"
        Exit Function
    End If

    InitDarkModeSupport   ' Optional uxtheme dark-mode support (scrollbars etc.)
    BuildTheme            ' Read the current Windows light/dark/high-contrast theme

    EnableVisualStyles    ' Enable ComCtl32 v6 visual styles before creating the dialog

    Dialog New Pixels, 0, "World Weather - Countries and Current Conditions", , , 1000, 742, _
        %WS_Caption Or %WS_SysMenu Or %WS_MinimizeBox To hDlg

    Control Add ListBox, hDlg, %ID_LIST, , 10, 10, 250, 722, _
        %WS_VScroll Or %LBS_Notify Or %WS_TabStop
    For i = 1 To gN
        ListBox Add hDlg, %ID_LIST, gName(i)
    Next i

    Control Add Graphic, hDlg, %ID_MAP, "", 270, 10, 720, 360
    Control Add TextBox, hDlg, %ID_TEXT, "", 270, 380, 720, 270, _
        %ES_MultiLine Or %ES_AutoVScroll Or %WS_VScroll Or %ES_ReadOnly Or %WS_TabStop
    Control Add Button, hDlg, %ID_NEWS, "&News", 270, 660, 138, 32, %WS_TabStop Or %BS_OwnerDraw
    Control Add Button, hDlg, %ID_HISTORY, "&History", 416, 660, 138, 32, %WS_TabStop Or %BS_OwnerDraw
    Control Add Button, hDlg, %ID_YOUTUBE, "&YouTube", 562, 660, 138, 32, %WS_TabStop Or %BS_OwnerDraw
    Control Add Button, hDlg, %ID_GEOGRAPHY, "&Geography", 708, 660, 138, 32, %WS_TabStop Or %BS_OwnerDraw
    Control Add Button, hDlg, %ID_MAPS, "&Maps", 854, 660, 138, 32, %WS_TabStop Or %BS_OwnerDraw
    Control Add Button, hDlg, %ID_ECONOMY, "&Economy", 270, 700, 138, 32, %WS_TabStop Or %BS_OwnerDraw
    Control Add Button, hDlg, %ID_CLIMATE, "&Climate", 416, 700, 138, 32, %WS_TabStop Or %BS_OwnerDraw
    Control Add Button, hDlg, %ID_CULTURE, "&Culture", 562, 700, 138, 32, %WS_TabStop Or %BS_OwnerDraw
    Control Add Button, hDlg, %ID_CONFLICTS, "&Current Conflicts", 708, 700, 138, 32, %WS_TabStop Or %BS_OwnerDraw

    gInfoText = "Select a country from the list." & $CrLf & $CrLf & _
        "The world map marks the country and its capital. Current weather is shown in Celsius and Fahrenheit." & $CrLf & _
        "Click News for current headlines about the selected country." & $CrLf & _
        "Click History for a Google search about the selected country's history." & $CrLf & _
        "Click YouTube to search YouTube for the selected country." & $CrLf & _
        "Click Geography for a Google search about the selected country's geography." & $CrLf & _
        "Click Maps for a Google search for a map of the selected country." & $CrLf & _
        "Click Economy for a Google search about the selected country's economy." & $CrLf & _
        "Click Climate for a Google search about the climate of the selected country." & $CrLf & _
        "Click Culture for a Google search about the culture of the selected country." & $CrLf & _
        "Click Current Conflicts for a Google search on current conflicts in the selected country."
    Control Set Text hDlg, %ID_TEXT, gInfoText

    ApplyTheme hDlg

    Dialog Show Modeless hDlg, Call DlgProc

    Do
        Dialog DoEvents
    Loop While IsWin(hDlg)

    DisableVisualStyles

    Function = 0
End Function
Reply


Messages In This Thread
WorldWeather.bas - by Stanley Durham - 16.11.2026, 01:02
RE: WorldWeather.bas - by Stanley Durham - 16.11.2026, 01:53
RE: WorldWeather.bas - by Stanley Durham - 16.11.2026, 07:56
RE: WorldWeather.bas - by Stanley Durham - Yesterday, 20:30

Forum Jump:


Users browsing this thread: 2 Guest(s)