Api Google Char

Iniciado por LeandroA, 23 Julio 2008, 03:09 AM

0 Miembros y 1 Visitante están viendo este tema.

LeandroA

Hola este es un ejemplo para pode utilizar el Api Google Char desde visual, bien esto puede ser utili en muy pocos caso, cuando tengamos conexion a internet y las consultas no sea muy frecuentes, asi que bien cada uno sabra si le puede dar utilidad.

Aca pueden encontrar toda la informacion de como utilizar esta api
http://code.google.com/apis/chart/


agregar Cuatro Botones, un Picture1,  y un HScroll1

Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal HDC As Long, graphics As Long) As Long
Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal image As Long) As Long
Private Declare Function GdipDrawImageRectRectI Lib "gdiplus" (ByVal graphics As Long, ByVal image As Long, ByVal dstx As Long, ByVal dsty As Long, ByVal dstwidth As Long, ByVal dstheight As Long, ByVal srcx As Long, ByVal srcy As Long, ByVal srcwidth As Long, ByVal srcheight As Long, ByVal srcUnit As Long, ByVal imageAttributes As Long, Optional ByVal callback As Long = 0, Optional ByVal callbackData As Long = 0) As Long
Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As Long
Private Declare Function GdipLoadImageFromFile Lib "gdiplus" (ByVal filename As String, ByRef image As Long) As Long
Private Declare Function GdiplusStartup Lib "gdiplus" (ByRef token As Long, inputbuf As Long, Optional ByVal outputbuf As Long = 0) As Long
Private Declare Sub GdiplusShutdown Lib "gdiplus" (ByVal token As Long)

Private Function RenderChar(ByVal HDC As Long, ByVal Param As String, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long) As Boolean
Dim hGraph As Long
Dim hImage As Long
Dim hGdiPlus As Long

If URLDownloadToFile(0, "http://chart.apis.google.com/chart?chs=" & Width & "x" & Height & "&" & Param, App.Path & "\Temp.png", 0, 0) = 0 Then

    GdiplusStartup hGdiPlus, 1
   
    If GdipCreateFromHDC(HDC, hGraph) = 0 Then

        If GdipLoadImageFromFile(StrConv(App.Path & "\Temp.png", vbUnicode), hImage) = 0 Then
       
            If GdipDrawImageRectRectI(hGraph, hImage, X, Y, Width, Height, 0, 0, Width, Height, &H2&, 0) = 0 Then
                RenderChar = True
            End If
           
        End If
       
        GdipDisposeImage hImage
       
    End If
   
    GdipDeleteGraphics hGraph
    GdiplusShutdown hGdiPlus
    Kill App.Path & "\Temp.png"
End If
End Function



Private Sub Command1_Click()
Dim Param As String
Param = "cht=p3&chd=t:80,40,30&chl=Sapallo|Lechuga|Tomate"
Debug.Print RenderChar(Picture1.HDC, Param, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight)
End Sub

Private Sub Command2_Click()
Dim Param As String
Param = "cht=bhs&chco=ff0000,00ff00,0000ff,&chd=s:FOE,THE,Bar&chxt=x,y&chxl=1:|Dec|Nov|Oct|0:||20K||60K||100K|"
Debug.Print RenderChar(Picture1.HDC, Param, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight)
End Sub

Private Sub Command3_Click()
Dim Param As String
Param = "cht=gom&chd=t:" & HScroll1.Value & "&chl=" & "Valor " & HScroll1.Value
Debug.Print RenderChar(Picture1.HDC, Param, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight)
End Sub

Private Sub Command4_Click()
Dim Param As String
Param = "cht=v&chd=t:100,80,60,30,30,30,10&chco=00ff00,0000ff"
Debug.Print RenderChar(Picture1.HDC, Param, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight)
End Sub

Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
Picture1.Move 0, 0, 5500, 2500
HScroll1.Max = 100: HScroll1.Min = 1
End Sub


Saludos

seba123neo

Hola, excelente Leandro  ;D,esto esta muy bueno,viste se pueden hacer un monton de cosas con estas api's onlines ya sea de google o de cualquier otro,tienen tantas opciones que no da para leerlo todo,por lo menos yo no podria es una perdida de tiempo bastante importante leer todo,pero ir haciendo miniaplicaciones de a poco asi mostrando funciones esta bien... :xD

saludos.
La característica extraordinaria de las leyes de la física es que se aplican en todos lados, sea que tú elijas o no creer en ellas. Lo bueno de las ciencias es que siempre tienen la verdad, quieras creerla o no.

Neil deGrasse Tyson