Written more than 6 years ago with the GDI+ Helper toolkit ...
'This is a PowerBASIC example, but it could be easily translated to either C or VB.
'No runtime required, except that the GDIPLUS.DLL must be already installed.
'Note: The GDIPLUS.DLL works with any Windows version except 95 and NT3.
'
' ---------------------------------------------------------------------------------
'
' gpSPHERE GDIPLUS Flat API example
'
' Most GDIPLUS examples and features have been translated to PB/WIN
' in the Patrice Terrier's "GDI+ helper" graphic toolkit.
'
' This demo draws two spheres using the GDI+ AntiAlias mode.
' it is written in pure SDK code to reach the majority of the programming community.
'
#COMPILE EXE "gpSPHERE.exe"
#INCLUDE "win32api.inc"
#INCLUDE "gdiplus.inc"
SUB DrawSphere(BYVAL hDC&)
' First Sphere coordinates
x& = 100: y& = 100: Size& = 200
CALL GdipCreateFromHDC(hDC&, graphics&)
' BRUSH EFFECT
' Create a GraphicsPath object
CALL GdipCreatePath(%FillModeAlternate, path1&)
' Add an ellipse to the path
CALL GdipAddPathEllipseI(path1&, x&, y&, Size&, Size&)
' Create a path gradient based on the ellipse
CALL GdipCreatePathGradientFromPath(path1&, brush1&)
' Set the middle color of the path
MiddleColorToOpaque& = ColorSetAlpha(%ColorsMediumAquamarine, 0)
CALL GdipSetPathGradientCenterColor(brush1&, MiddleColorToOpaque&)
' Set the entire path boundary to Alpha Black using 50% translucency
BlackFullTranslucent& = ColorSetAlpha(%ColorsBlack, 128)
CALL GdipSetPathGradientSurroundColorsWithCount(brush1&, BlackFullTranslucent&, 1)
' Draw the ellipse, keeping the exact coords we defined for the path
' I want to use AntiAlias drawing mode
CALL GdipSetSmoothingMode(graphics&, %SmoothingModeAntiAlias)
CALL GdipFillEllipseI(graphics&, brush1&, x& + 2, y& + 2, Size& - 4, Size& - 4)
' + 2 and - 4 are used to better achieve the AntiAlias
' Second Sphere coordinates
x& = 200: y& = 200: Size& = 150
' Create a GraphicsPath object
CALL GdipCreatePath(%FillModeAlternate, path2&)
' Add an ellipse to the path
CALL GdipAddPathEllipseI(path2&, x&, y&, Size&, Size&)
' Create a path gradient based on the ellipse
CALL GdipCreatePathGradientFromPath(path2&, brush2&)
' Set the middle color of the path
MiddleColorToOpaque& = ColorSetAlpha(%ColorsYellow, 64)
CALL GdipSetPathGradientCenterColor(brush2&, MiddleColorToOpaque&)
' Set the entire path boundary to Alpha Black using 50% translucency
BlackFullTranslucent& = ColorSetAlpha(%ColorsRed, 128)
CALL GdipSetPathGradientSurroundColorsWithCount(brush2&, BlackFullTranslucent&, 1)
' Draw the ellipse, keeping the exact coords we defined for the path
CALL GdipFillEllipseI(graphics&, brush2&, x& + 2, y& + 2, Size& - 4, Size& - 4)
' + 2 and - 4 are used to better achieve the AntiAlias
' Cleanup
CALL GdipDeletePath(path1&)
CALL GdipDeletePath(path2&)
CALL GdipDeleteBrush(brush1&)
CALL GdipDeleteBrush(brush2&)
CALL GdipDeleteGraphics(graphics&)
END SUB
FUNCTION WndProc(BYVAL hWnd& , BYVAL Msg&, BYVAL wParam&, BYVAL lParam&) AS LONG
LOCAL ps AS PAINTSTRUCT
SELECT CASE Msg&
CASE %WM_PAINT
hDC& = BeginPaint(hWnd&, ps)
CALL DrawSphere(hDC&)
CALL EndPaint(hWnd&, ps)
CASE %WM_DESTROY
CALL PostQuitMessage(0)
END SELECT
FUNCTION = DefWindowProc(hWnd&, Msg&, wParam&, lParam&)
END FUNCTION
FUNCTION WinMain (BYVAL hInstance AS LONG, _
BYVAL hPrevInstance AS LONG, _
BYVAL lpCmdLine AS ASCIIZ PTR, _
BYVAL iCmdShow AS LONG) AS LONG
LOCAL msg AS tagMSG
LOCAL wc AS WNDCLASSEX
LOCAL szClassName AS ASCIIZ * 128
szClassName = "GDI+ demo"
' LOAD the GDI+ Engine
hGDIplus& = gpStart
IF hGDIplus& THEN
IF ISFALSE(hPrevInstance&) THEN
wc.cbSize = SIZEOF(wc)
wc.style = %CS_HREDRAW OR %CS_VREDRAW
wc.lpfnWndProc = CODEPTR(WndProc)
wc.cbClsExtra = 0
wc.cbWndExtra = 0
wc.hInstance = hInstance&
wc.hIcon = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)
wc.hCursor = LoadCursor(%NULL, BYVAL %IDC_ARROW)
wc.hbrBackground = GetStockObject(%WHITE_BRUSH)
wc.lpszMenuName = %NULL
wc.lpszClassName = VARPTR(szClassName)
wc.hIconSm = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)
CALL RegisterClassEx(wc)
END IF
hWnd& = CreateWindowEx(0, _
szClassName, _ ' window class name
szClassName, _ ' window caption
%WS_OVERLAPPEDWINDOW, _ ' window style
%CW_USEDEFAULT, _ ' initial x position
%CW_USEDEFAULT, _ ' initial y position
%CW_USEDEFAULT, _ ' initial x size
%CW_USEDEFAULT, _ ' initial y size
%NULL, _ ' parent window handle
%NULL, _ ' window menu handle
hInstance&, _ ' program instance handle
BYVAL %NULL) ' creation parameters
IF hWnd& THEN
CALL ShowWindow(hWnd&, %SW_SHOW)
CALL UpdateWindow(hWnd&)
DO WHILE GetMessage(msg, %NULL, 0, 0)
TranslateMessage msg
DispatchMessage msg
LOOP
FUNCTION = msg.wParam
END IF
' UNLOAD the GDI+ Engine
CALL gpEnd(hGDIplus&)
END IF
END FUNCTION
For rectangle, see the examples in the GDImage trial version.
...