$TYPECHECK ON

Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type

Declare Function GdiplusStartup Lib "GDIPlus" ALIAS "GdiplusStartup" ( byref token As Long, byref inputbuf As long, outputbuf As Long) As Long
Declare Function GdiplusShutdown Lib "GDIPlus" ALIAS "GdiplusShutdown" ( token As Long) As Long
Declare Function GdipCreateFromHDC Lib "gdiplus.dll" ALIAS "GdipCreateFromHDC"(hdc As Long, byref GpGraphics As Long) As Long
Declare Function GdipCreateFromHWND Lib "gdiplus" ALIAS "GdipCreateFromHWND"(hwnd As Long, byref graphics As Long) As long
Declare Function GdipSetSmoothingMode Lib "gdiplus" ALIAS "GdipSetSmoothingMode"(graphics As Long, SmoothingMode As long) As long
Declare Function GdipCreatePen1 Lib "gdiplus" ALIAS "GdipCreatePen1"(color As Long, Width As Single, unit As long, byref pen As Long) As long
Declare Function GdipDrawLineI Lib "gdiplus" ALIAS "GdipDrawLineI" (graphics As Long, hpen As Long, x1 As Long, y1 As Long, x2 As Long, y2 As Long) As long
'Declare Function GdipDrawLine Lib "gdiplus" (graphics As Long, pen As Long, ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal y2 As Single) As GpStatus
Declare Function GdipDeletePen Lib "gdiplus" ALIAS "GdipDeletePen"(pen As Long) As long
Declare Function GdipDeleteGraphics Lib "gdiplus"ALIAS "GdipDeleteGraphics"(graphics As Long) As long

Declare Function GdipGetImageEncodersSize		Lib "gdiplus" 	ALIAS "GdipGetImageEncodersSize" (pNum As Long, pSize As Long) As Long
Declare Function GdipGetImageEncoders 			Lib "gdiplus" 	ALIAS "GdipGetImageEncoders" (numEncoders As Long, size As Long, encoders As Long) As Long
Declare Function GdipSaveImageToFile			Lib "gdiplus" 	ALIAS "GdipSaveImageToFile" (image As Long,pFilename As integer, pclsidEncoder As Long, encoderParams As Long) As Long
Declare Function GdipCreateBitmapFromHBITMAP 	Lib "gdiplus" 	ALIAS "GdipCreateBitmapFromHBITMAP" (hbm As Long, hpal As Long, bitmap As Long) As long
Declare Function GdipCreateHBITMAPFromBitmap 	Lib "gdiplus" 	ALIAS "GdipCreateHBITMAPFromBitmap" (bitmap As Long, hbmReturn As Long, background As Long) As Long
Declare Function GdipLoadImageFromFile 			Lib "gdiplus" 	ALIAS "GdipLoadImageFromFile" (filename As Long, image As Long) As Long
Declare Function GdipImageRotateFlip 			Lib "gdiplus" 	ALIAS "GdipImageRotateFlip" (image As Long, rfType As Long) As Long
Declare Function GdipDisposeImage 				Lib "gdiplus" 	ALIAS "GdipDisposeImage" (image As Long) As Long
Declare Function CLSIDFromString 				Lib "ole32.dll" ALIAS "CLSIDFromString" (lpszProgID As string, pCLSID As Long) As Long



Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long

Dim tSI As GdiplusStartupInput
Dim lRes As Long
Dim lGDIP As Long

dim imgMemory as QBitmap

'#############################################################################
' ----==== GDIPlus Const ====----
Const GdiPlusVersion As Long = 1
Const QualityModeInvalid As Long = -1
Const QualityModeDefault As Long = 0
Const QualityModeLow As Long = 1
Const QualityModeHigh As Long = 2
Const SmoothingModeAntiAlias = QualityModeHigh + 2
Const UnitPixel=2 ' 2 -- Each unit is one device pixel.
'#############################################################################
Declare sub Visi
Declare sub testit
Declare sub Finish
'#############################################################################
CREATE Form AS QFORM
Caption = "Form1"
Width = 582
Height = 476
onclose = Finish
'onclick = testit

Center
CREATE Canvas1 AS QCANVAS
left=5
top=5
width=560
height=400
onclick = testit
onpaint = Visi
END CREATE
END CREATE

'#############################################################################
' Inizializza GDI+

tSI.GdiplusVersion = 1

dim pp as long

pp = varptr(tSI)

lRes = GdiplusStartup( lGDIP, pp,0)

If lRes <> 0 Then
showmessage "GDIPlus ERROR = " + str$(lRes)
end
end if
'#############################################################################
'showmessage "x2"

imgMemory.width=Canvas1.width
imgMemory.height=Canvas1.height


form.showmodal

'#############################################################################
sub testit
Dim graphics As Long, pen As Long,res as long,HdcScreen as long
Dim kcol as long
'vedere come creare HDC in test precedenti.....

kcol=RGB(50,55,0)
'hdcScreen = GetDC(form.handle)
'showmessage str$(hdcscreen)
hdcScreen = imgmemory.handle

'res=GdipCreateFromHWND(imgmemory.handle,graphics)
res=GdipCreateFromHDC(hdcScreen, graphics)
if res<>0 then showmessage "1 " + str$(res)
res=GdipSetSmoothingMode(graphics, SmoothingModeAntiAlias)
if res<>0 then showmessage "2 " + str$(res)
res=GdipCreatePen1(kcol, 10, UnitPixel, pen)
if res<>0 then showmessage "3 " + str$(res)

res=GdipDrawLineI(graphics,pen, 100,100,400,150)
imgmemory.line(150,150,450,200,kcol)
if res<>0 then showmessage "4 " + str$(res)

res=GdipDeletePen(pen)
if res<>0 then showmessage "5 " + str$(res)
res=GdipDeleteGraphics( graphics)
if res<>0 then showmessage "6 " + str$(res)

call visi


end sub

'#############################################################################
sub Finish
GdiplusShutdown lGDIP
end sub
'#############################################################################
sub visi
Canvas1.draw(0,0,imgMemory.bmp)
end sub



