Aqui os dejo un generador de codigo QR que usa servicios en la red.
Espero que os guste .
Espero que os guste .
// Our first DialogBox sample
#include "FiveWin.ch"
#include "ttitle.ch"
# define HTTPREQUEST_PROXYSETTING_PROXY 聽2
function Main()
聽 local obmp ,cBmp
聽 local oDlg, oIco
聽 local ofont
聽 聽local cCode:= space(180)
聽 聽DEFINE Font ofont NAME "Verdana" SIZE 0,14
聽 聽
聽 聽DEFINE ICON oIco FILE "..\icons\fivewin.ico"
聽 聽DEFINE DIALOG oDlg TITLE "Qrcode Generator" ;
聽 聽 聽 ICON oIco SIZE 350, 440
聽 聽@ 30,24 聽IMAGE oBmp FILE cBmp OF oDlg size 128,128 pixel NOBORDER
聽 聽 聽
聽 聽 聽oBmp:lTransparent := .t.
聽 聽 聽
聽 聽// 聽cargaBmp( "hola",oBmp )
聽 聽 聽 聽
聽
聽 聽 聽@ 160, 10 SAY "Introduce el codigo a generar :" size 100, 12 ;
聽 聽 聽聽 聽聽 聽 聽 聽 聽 聽 聽 聽 FONT oFont pixel OF oDlg
聽 聽 聽
聽 聽 聽@ 170, 10 GET cCode size 120, 12 FONT oFont pixel OF oDlg
聽 聽 聽@ 205, 85 BUTTON "&Buscar" SIZE 40, 12 OF oDlg pixel ;
聽 聽 聽 聽 聽 聽 聽 FONT oFont ;
聽 聽 聽 聽 聽 聽 聽 ACTION cargaBmp( alltrim( cCode) ,oBmp )
聽 聽 聽@ 205,130 BUTTON "&Salir" SIZE 40, 12 pixel OF oDlg;
聽 聽 聽 聽 聽 聽 聽 聽FONT oFont ;
聽 聽 聽 聽 聽 聽 聽 聽ACTION oDlg:End()
聽 聽ACTIVATE DIALOG oDlg CENTERED ;
聽 聽 ON INIT 聽DlgBarTitle( oDlg, " 聽Generador de Qrcode","" ,44 ) 聽;
聽 聽 ON PAINT DlgStatusBar(oDlg, 68,, .t. )
聽 聽
return nil
//------------------------------------------------------------------------------
Function cargaBmp( cCode, oImage )
聽local cResp
聽local nZeroZeroClr
聽local ogbmp := GdiBmp():new()
聽local nHeight := 248
聽local nWidth 聽:= 248
聽local cUrl 聽:= "http://api.qrserver.com/v1/create-qr-code/?data="
聽
聽 cUrl += GetSafeURL(hb_strtoutf8( cCode ) )
聽 cUrl += "&size=" + alltrim( str( nWidth ) ) 聽+ "x" + alltrim( str( nHeight ) )
聽 聽
聽cResp := loadBmp(cUrl)
聽if !Empty( cResp )
聽
聽 聽 oGbmp:hbmp := GDIPLUSIMAGELOADPNGFROMSTR( cResp,len(cResp) )
聽 聽
聽 聽 oImage:hBitmap := oGBmp:GetGDIHbitmap()
聽 聽 oImage:HasAlpha()
聽 聽 oImage:Refresh()
聽 聽 if msgYesNo( " 篓 quiere grabar el codigo QR a Disco ?")
聽 聽 聽 聽oGBmp:save(".\qrcode.png" )
聽 聽 endif 聽
聽 聽 oGbmp:End()
聽endif
聽
Return nil
Static Function GetSafeURL( 聽cUrl )
聽 聽local cAsc
聽 聽local nChr
聽 聽local sHex
聽 聽local i
聽 聽local cGetSafeURL := ""
聽 聽 聽 聽
聽 聽 For i = 1 To Len( cUrl )
聽 聽 聽 聽 cASC := substr( cUrl, i, 1)
聽 聽 聽 聽 nChr := Asc( cASC )
聽 聽 聽 聽
聽 聽 聽 聽 If ( nChr > 47 .and. nChr < 58 ) .Or. ( nChr > 64 .And. nChr < 91 ) .Or. ( nChr > 96 .And. nChr < 123 )
聽 聽 聽 聽 聽 聽 cGetSafeURL += cASC
聽 聽 聽 聽 Else
聽 聽 聽 聽 聽 聽 sHex := 聽hb_NumtoHex( nChr )
聽 聽 聽 聽 聽 聽 If Len( sHex ) = 1
聽 聽 聽 聽 聽 聽 聽 聽 cGetSafeURL += "%0" + sHex
聽 聽 聽 聽 聽 聽 Else
聽 聽 聽 聽 聽 聽 聽 聽 cGetSafeURL += "%" 聽+ sHex
聽 聽 聽 聽 聽 聽 End If
聽 聽 聽 聽 End If
聽 聽 Next
Return cGetSafeURL
//------------------------------------------------------------------------------
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 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