acuellar wrote:Ya hice los cambios indicados y no funciona
- Code: Select all Expand view
Try
cProxi:= "192.10.1.7:8080"
oHttp := CreateObject("winhttp.winhttprequest.5.1")
oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY,cProxi )
oHttp:Open("GET", cDir, .f. )
oHttp:Send()
cResp := oHttp:ResponseText()
leejson( cResp )
Catch
MsgStop( "Error al cargar el tiempo" )
Return cResp
End Try
Saludos,
Adhemar
#include "FiveWin.ch"
#define HTTPREQUEST_PROXYSETTING_DEFAULT 0
#define HTTPREQUEST_PROXYSETTING_PRECONFIG 0
#define HTTPREQUEST_PROXYSETTING_DIRECT 1
#define HTTPREQUEST_PROXYSETTING_PROXY 2
Function Main()
MsgInfo( Tipo_de_cambio(), "US Dollar" )
Return Nil
Function Tipo_de_cambio()
Local oHttp, ;
cResp := ""
Try
oHttp := CreateObject("winhttp.winhttprequest.5.1")
oHttp:Open("GET","http://www.peru.gob.pe/",.f.)
* oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_DEFAULT ) // toma valores del registro
oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY, "proxy.itc.pascal:80", "172.15.5.1" ) // explícito
oHttp:Send()
cResp := oHttp:ResponseText()
Catch
MsgStop( "Error" )
Return cResp
End Try
cResp := SubStr( cResp, At( "Tipo de cambio C: S/. ", cResp ) )
cResp := StrTran( StrTran( Substr( cResp, 1, At( "</b>", cResp ) - 1 ), "C: S/.", "Compra: S/." ), "V: S/.", ;
"Venta: S/." )
Return cResp
Function loadBmp(cUrl,lProxy)
local oHttp
local cResp := nil
cProxi:= "172.15.5.1:8080"
IF lProxy
Try
oHttp := CreateObject("winhttp.winhttprequest.5.1")
oHttp:Open("GET",cUrl,.f.)
oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY, cProxi )
oHttp:Send()
cResp := oHttp:ResponseBody()
oHttp:WaitForResponse()
Catch
MsgStop( "Error" )
Return cResp
End Try
ELSE
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
//------------------------------------------------------------------------------
ENDIF
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
lProxy:=.T.
Try
oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
if lProxy
oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY, PROXY_SCHOOL+":"+alltrim(str(NPORT)) )
endif
oHttp:Open("GET", cUrl, .f. )
if lProxy
oHttp:SetCredentials(USERNAME,PASSWORD,HTTPREQUEST_SETCREDENTIALS_FOR_PROXY)
endif
oHttp:Send()
cResp := oHttp:ResponseBody()
oHttp:WaitForResponse()
leejson( cResp )
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
lProxy:=.T.
Try
oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
if lProxy
oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY, PROXY_SCHOOL+":"+alltrim(str(NPORT)) , "*.yahooapis.com")
endif
oHttp:Open("GET", cUrl, .f. )
if lProxy
oHttp:SetCredentials(USERNAME,PASSWORD,HTTPREQUEST_SETCREDENTIALS_FOR_PROXY)
endif
oHttp:Send()
cResp := oHttp:ResponseText()
oHttp:WaitForResponse()
leejson( cResp )
Catch
MsgStop( "Error" )
Return cResp
End Try
Return cResp
// Our first DialogBox sample
#include "FiveWin.ch"
#include "ttitle.ch"
#include "constant.ch"
#define HTTPREQUEST_PROXYSETTING_DEFAULT 0
#define HTTPREQUEST_PROXYSETTING_PRECONFIG 0
#define HTTPREQUEST_PROXYSETTING_DIRECT 1
#define HTTPREQUEST_PROXYSETTING_PROXY 2
#define HTTPREQUEST_SETCREDENTIALS_FOR_SERVER 0
#define HTTPREQUEST_SETCREDENTIALS_FOR_PROXY 1
Function Meteo()
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
local lProxy
Local cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + "Meteo.ini"
DEFINE Font ofont NAME "Verdana" SIZE 0,14
DEFINE ICON oIco FILE "c:\work\fwh\icons\fivewin.ico"
lProxy:=Request_Proxy()
If lProxy
cSection :="Config"
cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + "Meteo.ini"
PROXY_SCHOOL := GetIni(cIniFile, cSection, "Proxy")
NPORT := val(GetIni(cIniFile, cSection, "Port"))
USERNAME := GetIni(cIniFile, cSection, "Username")
PASSWORD := GetIni(cIniFile, cSection, "Password")
Endif
// ?PROXY_SCHOOL
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,lProxy)
// 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,lProxy)
@ 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:\work\fwh\bitmaps\alphaBmp\weather.bmp" ,44 )) ;
ON PAINT DlgStatusBar(oDlg, 68,, .t. )
return nil
//--------------------------------------------------------------------------//
Function Request_Proxy()
Local lReturn
IF MsgyesNo("Devo usare il proxy ?")
lReturn :=.t.
Valid_Proxy()
else
lReturn :=.f.
endif
return lReturn
//------------------------------------------------------------------------------//
Function Valid_Proxy()
Local oDlgProxy,oFont
Local cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + "Meteo.ini"
Local nBottom := 14
Local nRight := 55
Local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
Local nHeight := nBottom * DLG_CHARPIX_H
Local oBtnHelp,oBtnOK,oBtnCan
Local cUSERNAME := pad(GetPvProfString("Config","Username" ,"mioUsername" ,cIniFile ) , 30 ," " )
Local cPASSWORD := pad(GetPvProfString("Config","Password" ,"miapassword" ,cIniFile ) , 30 ," " )
Local cPROXY := pad(GetPvProfString("Config","Proxy" ,"miaproxy" ,cIniFile ) , 15 ," " )
Local nPORT := pad(GetPvProfString("Config","Port" ,"8080" ,cIniFile ) , 4 ," " )
Local aGet[4]
DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0, 8
DEFINE DIALOG oDlgProxy TITLE "Inserimento Proxy" ;
FROM 100, 100 TO 230,600 pixel
@ 12, 10 SAY "Proxy:" OF oDlgProxy SIZE 60, 8 PIXEL FONT oFont
@ 10, 45 GET aGet[1] VAR cPROXY OF oDlgProxy SIZE 50, 12 PIXEL FONT oFont
@ 26, 10 SAY "Porta:" OF oDlgProxy SIZE 80, 8 PIXEL FONT oFont
@ 24, 45 GET aGet[2] var nPORT OF oDlgProxy SIZE 44, 12 PIXEL FONT oFont
@ 12, 120 SAY "Codice utente:" OF oDlgProxy SIZE 80, 8 PIXEL FONT oFont
@ 10, 175 GET aGet[3] var cUSERNAME OF oDlgProxy SIZE 44, 12 PIXEL FONT oFont
@ 26, 120 SAY "Password:" OF oDlgProxy SIZE 80, 8 PIXEL FONT oFont
@ 24, 175 GET aGet[4] var cPASSWORD OF oDlgProxy SIZE 44, 12 PIXEL FONT oFont
@ 46, 4 BUTTON oBtnHelp PROMPT "&Aiuto" OF oDlgProxy SIZE 42, 12 PIXEL FONT oFont ACTION Helpindex()
@ 46, 160 BUTTON oBtnOK PROMPT I18n("Conferma") OF oDlgProxy SIZE 42, 12 PIXEL FONT oFont DEFAULT ACTION (oDlgProxy:End(IDOK ))
@ 46, 204 BUTTON oBtnCan PROMPT i18n("Annulla") OF oDlgProxy SIZE 42, 12 PIXEL FONT oFont CANCEL ACTION (oDlgProxy:End(IDCANCEL))
ACTIVATE DIALOG oDlgProxy CENTERED
if oDlgProxy:nresult == IDOK
SetIni( cInifile, "Config", "Proxy", cPROXY )
SetIni( cInifile, "Config", "Username", cUSERNAME )
SetIni( cInifile, "Config", "Password", cPASSWORD )
SetIni( cInifile, "Config", "Port", nPORT )
endif
return nil
Function cargaBmp(cUrl,oImage,lProxy)
local cResp := loadBmp(cUrl,lProxy)
local nZeroZeroClr
if !Empty( cResp )
// oImage:LoadFromString( cResp )
oImage:LoadFromMemory( cResp )
oImage:HasAlpha()
oImage:Refresh()
endif
Return nil
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
Function loadBmp(cUrl,lProxy)
local oHttp
local cResp := nil
cProxyNo := "*.yimg.com"
If lProxy
cSection :="Config"
cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + "Meteo.ini"
PROXY_SCHOOL := GetIni(cIniFile, cSection, "Proxy")
NPORT := val(GetIni(cIniFile, cSection, "Port"))
USERNAME := GetIni(cIniFile, cSection, "Username")
PASSWORD := GetIni(cIniFile, cSection, "Password")
Endif
// ?PROXY_SCHOOL ,NPORT ,USERNAME ,PASSWORD
Try
oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
if lProxy
oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY, PROXY_SCHOOL+":"+alltrim(str(NPORT)))
endif
oHttp:Open("GET", cUrl, .f. )
if lProxy
oHttp:SetCredentials(USERNAME,PASSWORD,HTTPREQUEST_SETCREDENTIALS_FOR_PROXY)
endif
oHttp:Send()
cResp := oHttp:ResponseBody()
oHttp:WaitForResponse()
Catch
MsgStop( "Error" )
Return cResp
End Try
Return cResp
//------------------------------------------------------------------------------
Function llamada(cCity,lProxy)
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
If lProxy
cSection :="Config"
cIniFile := cFilePath(GetModuleFileName( GetInstance() ) ) + "Meteo.ini"
PROXY_SCHOOL := GetIni(cIniFile, cSection, "Proxy")
NPORT := val(GetIni(cIniFile, cSection, "Port"))
USERNAME := GetIni(cIniFile, cSection, "Username")
PASSWORD := GetIni(cIniFile, cSection, "Password")
Endif
//?PROXY_SCHOOL ,NPORT ,USERNAME ,PASSWORD
Try
oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
if lProxy
oHttp:SetProxy( HTTPREQUEST_PROXYSETTING_PROXY, PROXY_SCHOOL+":"+alltrim(str(NPORT)))
endif
oHttp:Open("GET", cDir, .f. )
if lProxy
oHttp:SetCredentials(USERNAME,PASSWORD,HTTPREQUEST_SETCREDENTIALS_FOR_PROXY)
endif
oHttp:Send()
*cResp := oHttp:ResponseBody()
cResp := oHttp:ResponseText()
oHttp:WaitForResponse()
leejson( cResp,lProxy )
Catch
MsgStop( "Error" )
Return cResp
End Try
Return cResp
/*
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 ,lProxy)
local hvar
local hvar1,hvar2
local cTexto:=""
local oDlg, cBmp
local nValor
local oBmp
local ofont1,ofont2
Local oBrwForecast
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, 600 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"]
nRow:=185
nCol:= 5
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"
@ nRow,nCol say cData OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 8
@ nRow,nCol+15 say cDay OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 8
@ nRow,nCol+15 say cMax OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 8
@ nRow,nCol+15 say cMin OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 8
@ nRow,nCol say cPrev OF oDlg pixel color CLR_BLACK,CLR_WHITE FONT ofont2
nRow+= 10
@ nRow,nCol IMAGE oBmp FILE cBmp OF oDlg size 32,32 pixel NOBORDER
cargaBmp(cUrl,oBmp,lProxy)
nCol+=50
nRow:=185
next
@ 170, 2 GROUP oGroup TO 260,248 LABEL "Forecast Week" OF oDlg pixel TRANSPARENT
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,lProxy)
@ 280, 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
FUNCTION SetIni( cIni, cSection, cEntry, xVar )
LOCAL oIni
DEFAULT cIni := oApp:cIniFile
INI oIni FILE cIni
SET SECTION cSection ;
ENTRY cEntry ;
TO xVar ;
OF oIni
ENDINI
RETURN nil
/*_____________________________________________________________________________*/
FUNCTION GetIni( cIni, cSection, cEntry, xDefault )
LOCAL oIni
LOCAL xVar := xDefault
DEFAULT cIni := oApp:cIniFile
INI oIni FILE cIni
GET xVar ;
SECTION cSection ;
ENTRY cEntry ;
DEFAULT xDefault ;
OF oIni
ENDINI
RETURN xVar
mastintin wrote:Segui un poco con el ejemplo del uso de servicio meteorológico y lo he completado un poco mas .
Aqui dejo el código del ejemplo, funciona bien si no usas proxi , lo colocas como meteo.prg en samples y lo compilas .
- Code: Select all Expand view
// 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()
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()
// 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
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, 400 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"]
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)
@ 184, 100 BUTTON "&Ok" SIZE 40, 12 OF oDlg pixel ;
ACTION odlg:end() FONT oFont2
ACTIVATE DIALOG oDlg CENTERED on paint ( cargaBmp(cTexto,obmp), 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
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: No registered users and 40 guests