#Include once "window9.bi"
Using GDIPLUS
Dim shared ULONG_PTR_01 AS ULONG_PTR
DIM GDIPLUSSTARTUPINPUT_01 AS GDIPLUSSTARTUPINPUT
GDIPLUSSTARTUPINPUT_01.GdiplusVersion = 1
IF (GDIPLUSSTARTUP(@ULONG_PTR_01, @GDIPLUSSTARTUPINPUT_01, NULL) <> 0) THEN
	PRINT "FAIL"
EndIf
Function Extract_Icon (byval FileName as String,ByVal number As Integer,ByVal ColorBack As Integer) as HBITMAP Export
	DIM GPIMAGE_01 AS GPIMAGE PTR
	var  hicon= ExtractIcon(0,FileName,number)
	Dim bmp As HBITMAP
	GdipCreateBitmapFromHICON(hicon,Cast(GpBitmap ptr Ptr,@GPIMAGE_01))
	If LoByte(LOWORD(GetVersion)) <6 Then
		DIM AS PVOID PTR GPIMAGE_02,GpGraphics
		Dim As Integer w,h
		GdipGetImageWidth(GPIMAGE_01,@w)
		GdipGetImageHeight(GPIMAGE_01,@h)
		GdipCreateBitmapFromScan0(w, h, 0, PixelFormat32bppARGB, NULL, Cast(Any Ptr,@GPIMAGE_02))
		GdipGetImageGraphicsContext(Cast(Any Ptr,GPIMAGE_02),Cast(Any Ptr,@GpGraphics))
		GdipGraphicsClear(Cast(Any Ptr,GpGraphics),ColorBack or &hff000000)
		GdipDrawImageRectI(Cast(Any Ptr,GpGraphics),GPIMAGE_01,0,0,w,h)
		GdipCreateHBITMAPFromBitmap(Cast(Any Ptr,GPIMAGE_02),@bmp,ColorBack or &hff000000)
		If GPIMAGE_02 <> 0 Then GdipDisposeImage(Cast(Any Ptr,GPIMAGE_02))
		If GpGraphics <> 0 Then GdipDeleteGraphics(Cast(Any Ptr,GpGraphics))
	Else
		GdipCreateHBITMAPFromBitmap(Cast(GpBitmap ptr,GPIMAGE_01),@bmp,ColorBack or &hff000000)
	EndIf
	DestroyIcon(hicon)
	GdipDisposeImage(GPIMAGE_01)
	Return Cast(HBITMAP,bmp)
end Function
