#Include "windows.bi"
#Include "win/gdiplus.bi"
Using GDIPLUS
Dim wc As WNDCLASSEX
Dim  msg As MSG
Dim 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
#Ifndef PI
#define PI 3.14159265358979323846
#EndIf
Function Load_image(ByVal Image As String) As Any Ptr
	Dim GPIMAGE_01 As GPBITMAP Ptr
	Var blen = (Len(Image)*2)+2
	Dim As WString Ptr wbuf
	wbuf  = Allocate( blen )
	MultiByteToWideChar(CP_ACP, 0, Image, -1, wbuf, blen)
	If (GdipLoadImageFromFile( *wbuf, @GPIMAGE_01) <> 0) Then
		Print "FAIL"
	End If
	DeAllocate(wbuf)
	Return GPIMAGE_01
End Function
Sub OnPaint(compHdc As HDC)
	Dim As PVOID GpGraphics,Image,ImageAttributes
	Dim As UInteger w,h
	Dim As Single degrees=60, r=degrees * pi / 180
	Dim As ColorMatrix ColorMatrix
	ColorMatrix.m(0,0) = Cos(r)
	ColorMatrix.m(1,0) = -Sin(r)
	ColorMatrix.m(0,1) = Sin(r)
	ColorMatrix.m(1,1) = Cos(r)
	ColorMatrix.m(2,2) = 1.0
	ColorMatrix.m(3,3) = 1.0
	ColorMatrix.m(4,4) = 1.0
	GdipCreateFromHDC(compHdc,@GpGraphics)
	GdipGraphicsClear(GpGraphics,&hffffffff)
	Image=Load_image("..\Media\RotationInput.png")
	GdipCreateImageAttributes(@ImageAttributes)
	GdipGetImageWidth(Image,@w)
	GdipGetImageHeight(Image,@h)
	GdipSetImageAttributesColorMatrix(ImageAttributes,ColorAdjustTypeBitmap,TRUE,Cast(Any Ptr,@ColorMatrix),0,ColorMatrixFlagsDefault)
	GdipDrawImageRect(GpGraphics,Image,10,10,w,h)
	GdipDrawImageRectRect(GpGraphics,Image,130,10,w,h,0,0,w,h,UnitPixel,ImageAttributes,0,0)
	GdipDisposeImage(Image)
	GdipDisposeImageAttributes(ImageAttributes)
	GdipDeleteGraphics(GpGraphics)
End Sub
Function WndProc(hWnd As HWND,uMsg As UINT,wParam As WPARAM,lParam As LPARAM) As Integer
	Dim ps As PAINTSTRUCT
	Static As HDC compHdc,hdc
	Select Case uMsg
		Case WM_CLOSE
			DeleteDC(compHdc)
			PostQuitMessage(0)
		Case WM_CREATE
			hdc=GetDC(GetDesktopWindow)
			compHdc=CreateCompatibleDC(hdc)
			Var bitmap = CreateCompatibleBitmap(hdc,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN))
			SelectObject(compHdc,bitmap)
			DeleteObject(bitmap)
			ReleaseDC(GetDesktopWindow,hdc)
			OnPaint(compHdc)
			InvalidateRect(hwnd,0,0)
		Case WM_PAINT
			BeginPaint(hWnd,@ps)
			BitBlt(ps.hdc,ps.rcPaint.left,ps.rcPaint.top,ps.rcPaint.right-ps.rcPaint.left,ps.rcPaint.bottom-ps.rcPaint.top,compHdc,ps.rcPaint.left,ps.rcPaint.top,SRCCOPY)
			EndPaint(hWnd,@ps)
			Return 0
		Case Else
			Return DefWindowProc(hWnd,uMsg,wParam,lParam)
	End Select
End Function

With wc
	.hInstance=GetModuleHandle(0)
	.cbSize=SizeOf(WNDCLASSEX)
	.style=CS_HREDRAW Or CS_VREDRAW
	.lpfnWndProc=@WndProc
	.lpszClassName=StrPtr("class")
	.hCursor=LoadCursor(NULL,IDC_ARROW)
End With
RegisterClassEx(@wc)
CreateWindowEx(0,wc.lpszClassName,"DrawGDI+",WS_OVERLAPPEDWINDOW Or WS_VISIBLE,200,200,245,135,0,0,wc.hInstance,0)

While GetMessage(@msg,0,0,0)
	TranslateMessage(@msg)
	DispatchMessage(@msg)
Wend