// Our first DialogBox sample
#include "FiveWin.ch"
#include "ttitle.ch"
function Main()
local obmp ,cBmp
local oDlg, oIco ,cCity:= "Marbella"+space(20)
local cUrl := "http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"
local ofont
DEFINE Font ofont NAME "Verdana" SIZE 0,14
DEFINE ICON oIco FILE "..\icons\fivewin.ico"
DEFINE DIALOG oDlg TITLE "Ciudad a buscar" ;
ICON oIco SIZE 350, 240
@ 30,10 IMAGE oBmp FILE cBmp OF oDlg size 142,35 pixel NOBORDER
obmp:lTransparent := .t.
cargaBmp(cUrl,oBmp)
// oBmp:display()
@ 60, 10 SAY "Introduce la ciudad a buscar :" size 100, 12 ;
FONT oFont pixel OF oDlg
@ 70, 10 GET cCity size 120, 12 FONT oFont pixel OF oDlg
@ 105, 85 BUTTON "&Buscar" SIZE 40, 12 OF oDlg pixel ;
FONT oFont ;
ACTION llamada(cCity)
@ 105,130 BUTTON "&Salir" SIZE 40, 12 pixel OF oDlg;
FONT oFont ;
ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT DlgBarTitle( oDlg, " Servicio Metereologico","c:\fwh\bitmaps\alphaBmp\weather.bmp" ,44 ) ;
ON PAINT DlgStatusBar(oDlg, 68,, .t. )
return nil
//------------------------------------------------------------------------------
Function cargaBmp(cUrl,oImage)
local cResp := loadBmp(cUrl)
local nZeroZeroClr
if !Empty( cResp )
// oImage:LoadFromString( cResp )
oImage:LoadFromMemory( cResp )
oImage:HasAlpha()
oImage:Refresh()
endif
Return nil
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
Function loadBmp(cUrl)
local oHttp
local cResp := nil
Try
oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
oHttp:Open("GET", cUrl, .f. )
oHttp:Send()
cResp := oHttp:ResponseBody()
oHttp:WaitForResponse()
Catch
MsgStop( "Error" )
Return cResp
End Try
Return cResp
//------------------------------------------------------------------------------
Function llamada(cCity)
local oHttp
local cResp
local cDir
local Formato := "json" // "xml"
local cUnits:= "c"
cDir := "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1)"
cDir:= cDir + " where text= '"+ cCity +"' ) and u='"+cUnits+"'&format=" + Formato
Try
oHttp := CreateObject("winhttp.winhttprequest.5.1")
oHttp:Open("GET", cDir, .f. )
oHttp:Send()
cResp := oHttp:ResponseText()
oHttp:WaitForResponse()
// memowrit("eltiempo.txt",cResp )
// msginfo("grabado")
// winexec( "notepad.exe eltiempo.txt" )
leejson( cResp )
Catch
MsgStop( "Error" )
Return cResp
End Try
Return nil
//------------------------------------------------------------------------------
function Leejson(cResp )
local hvar
local hvar1,hvar2
local cTexto:=""
local oDlg, cBmp
local nValor
local oBmp
local ofont1,ofont2
Local oBrwForecast
local aForecast:= {}
local i
local cImage,cMin,cMax,cData,cDay
local ahTexto,hDias,cPrev
local cUrl
hb_jsondecode( cResp, @hvar )
hvar1:= hvar["query"]["results"]["channel"]
define font ofont1 name "Arial" size 0,16 bold
DEFINE Font ofont2 NAME "Verdana" SIZE 0,13
DEFINE DIALOG oDlg TITLE "Resultados" SIZE 500, 550 pixel color CLR_BLACK,CLR_WHITE
@ 10 ,80 SAY alltrim(hvar1["title"] ) OF oDlg SIZE 180, 20 ;
pixel Font ofont1 color CLR_BLACK,CLR_WHITE
@ 25, 70 SAY "Fecha : "+ alltrim(hvar["query"]["created"]) SIZE 180, 20 OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
hvar2:= hvar1["wind"]
@ 40, 100 say alltrim("Viento") SIZE 50, 20 OF oDlg ;
pixel COLOR CLR_BLACK,CLR_WHITE FONT ofont1
@ 50, 50 say alltrim("Sensacion Termica :" ) OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 50, 130 say alltrim( hVar2["chill"]+chr(186)+" "+ hvar1["units"]["temperature"] ) OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 60, 50 say "Direcccion " OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 60, 130 say hVar2["direction"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 70, 50 say "Velocidad " OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 70, 130 say hVar2["speed"]+" "+ hvar1["units"]["speed"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
hvar2:= hvar1["atmosphere"]
@ 85, 95 say "Atmosfera " OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont1
@ 100, 50 say "Humedad " OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 100, 130 say hVar2["humidity"] + " %" OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 110, 50 say "Presion Barometrica " OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 110, 130 say hVar2["pressure"] + " "+ hvar1["units"]["pressure"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nValor:= hVar2["rising"]
if nValor == "0"
cTexto := "Estable"
elseif nValor == "1"
cTexto := "Subiendo"
elseif nValor == "2"
cTexto := "Bajando"
endif
@ 120, 50 say "Tendencia Barometrica: " OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 120, 130 say cTexto OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
hvar2:= hvar1["astronomy"]
@ 160, 30 say "Orto " + hVar2["sunrise"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
@ 160, 160 say "Ocaso " + hVar2["sunset"] OF oDlg ;
pixel color CLR_BLACK,CLR_WHITE FONT ofont2
hvar2:= hvar1["item"]
aHTexto:=hVar2["forecast"]
for i=1 to len(aHTexto)
hDias:=aHTexto[i]
cData:= hDias["date"]
cDay:= hDias["day"]
cMax:= hDias["high"]
cMin:= hDias["low"]
cPrev:= hDias["text"]
cUrl:= "http://l.yimg.com/a/i/us/we/52/"+hDias["code"]+".gif"
cImage:= loadBmp(cUrl)
Aadd(aForecast,{cData,cDay,cMax,cMin,cPrev,cImage} )
next
@ 185,10 XBROWSE oBrwForecast SIZE 230,060 PIXEL OF oDlg;
DATASOURCE aForecast ;
COLUMNS 1,2,3,4,5,6 ;
HEADERS "Fecha","Dia","maxima","minima","prevision","imagen" ;
COLSIZES 45, 45,45,50,80,45
WITH OBJECT oBrwForecast
:nMarqueeStyle := MARQSTYLE_HIGHLROW
:lHScroll := .f.
:CreateFromCode()
END
cTexto:=hVar2["condition"]["code"]
cTexto:="http://l.yimg.com/a/i/us/we/52/"+cTexto+".gif"
@ 10,12 IMAGE oBmp FILE cBmp OF oDlg size 32,32 pixel NOBORDER
cargaBmp(cTexto,oBmp)
@ 260, 100 BUTTON "&Ok" SIZE 40, 12 OF oDlg pixel ;
ACTION odlg:end() FONT oFont2
ACTIVATE DIALOG oDlg CENTERED on paint DlgStatusBar(oDlg, 68,, .t. )
ofont1:end()
ofont2:end()
return nil
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
Function DlgStatusBar(oDlg, nHeight, nCorrec , lColor )
Local nDlgHeight := oDlg:nHeight
Local aColor := { { 0.40, nRGB( 200, 200, 200 ), nRGB( 184, 184, 184 ) },;
{ 0.60, nRGB( 184, 184, 184 ), nRGB( 150, 150, 150 ) } }
DEFAULT nHeight := 72
DEFAULT nCorrec := 0
DEFAULT lColor := .F.
nDlgHeight:= nDlgHeight+ncorrec
IF lColor
GradienTfill(oDlg:hDC,nDlgHeight-( nHeight-2 ),0,nDlgHeight-20,oDlg:nWidth, aColor ,.t.)
WndBoxIn( oDlg:hDc,nDlgHeight-( nHeight-1 ),0,nDlgHeight-( nHeight ),oDlg:nWidth )
ELSE
WndBoxIn( oDlg:hDc,nDlgHeight -( nHeight-1 ),4,nDlgHeight-( nHeight ),oDlg:nWidth - 10 )
endif
Return Nil
//------------------------------------------------------------------------------
FUNCTION DlgBarTitle( oWnd, cTitle, cBmp ,nHeight )
LOCAL oFont
LOCAL oTitle
LOCAL nColText := 180
LOCAL nRowImg := 0
DEFAULT cTitle := ""
DEFAULT nHeight := 48
IF nHeight < 48
nColText := 60
nRowImg := 12
DEFINE FONT oFont NAME "Arial" size 10, 30
ELSE
DEFINE FONT oFont NAME "Arial" size 12, 30
endif
@ -1, -1 TITLE oTitle size oWnd:nWidth+1, nHeight+1 of oWnd SHADOWSIZE 0
@ nRowImg, 10 TITLEIMG OF oTitle BITMAP cBmp SIZE 48, 48 REFLEX ;
TRANSPARENT
@ nRowImg-2 , nColText TITLETEXT OF oTitle TEXT cTitle COLOR CLR_BLACK FONT oFont
oTitle:aGrdBack := { { 1, RGB( 255, 255, 255 ), RGB( 229, 233, 238 ) } }
oTitle:nShadowIntensity = 0
oTitle:nShadow = 0
oTitle:nClrLine1 := nrgb(0,0,0)
oTitle:nClrLine2 := RGB( 229, 233, 238 )
oWnd:oTop:= oTitle
RETURN oTitle