GDIplus

Confused about the state of GDIPlus vs Windows vs Xojo

I have some code the uses these Windows Declares…
Are they still going to work for the foreseeable future?
Has the DLL that supports them been deprecated and I need a replacement?

I don’t want to waste time programming around this snippet if I should be using something “newer”

// ************************** //
// ** Windows Pattern Line ** //
// ************************** //
Dim pen As Integer
Dim n As Integer
Dim c As Color
Dim gpx As Integer
Dim mb As New MemoryBlock(4)

Declare Function GdipCreatePen1 Lib "GDIPlus" (c As Integer, width As Single, unit As Integer, ByRef p As Integer) As Integer
Declare Function GdipSetPenDashStyle Lib "GDIPlus" (pen As Integer, style As Integer) As Integer
Declare Function GdipCreateFromHDC Lib "GDIPlus" (hdc As Integer, ByRef g As Integer) As Integer
Declare Function GdipDrawLine Lib "GDIPlus" (g As Integer, pen As Integer, x1 As Single, y1 As Single, x2 As Single, y2 As Single) As Integer
Declare Function GdipDeletePen Lib "GDIPlus" (pen As Integer) As Integer
Declare Function GdipDeleteGraphics Lib "GDIPlus" (g As Integer) As Integer


c = g.ForeColor
mb.Byte(0) = c.blue
mb.Byte(1) = c.green
mb.Byte(2) = c.red
mb.Byte(3) = 255    // alpha = opaque
n = mb.Int32Value(0)
Call GdipCreatePen1(n, g.PenWidth, 2, pen)
Call GdipSetPenDashStyle(pen, pattern)
Call GdipCreateFromHDC(g.handle(Graphics.HandleTypeHDC), gpx)
Call GdipDrawLine(gpx, pen, x1, y1, x2, y2)
Call GdipDeletePen(pen)
Call GdipDeleteGraphics(gpx)

GDI+ was removed from 2017r1 and newer, so it depends on which version you are using.

Well for now 2016r4.1
but I wish to plan for the future… so I guess you are saying that those Declares are not “future proof” (not that any really are)

Any idea on a chunk of replace code?

Actually that change was made in 2016r4… at the same time that the IDE became hidpi aware.

[quote=338523:@Dave S]Confused about the state of GDIPlus vs Windows vs Xojo

I have some code the uses these Windows Declares…
Are they still going to work for the foreseeable future?
Has the DLL that supports them been deprecated and I need a replacement?

I don’t want to waste time programming around this snippet if I should be using something “newer”[/quote]

Fortunately, using declares has nothing to do with the framework or what route Xojo take, those calls should be in windows forever. As long as you can get a HDC from Xojo, you will be fine.

If you are interested in going the D2D route, here’s a comparison between drawing with GDI and D2D.

https://msdn.microsoft.com/en-us/library/windows/desktop/dd535473(v=vs.85).aspx

The part you will need to look at is down in Step 4:

Follow the link to ID2D1StrokeStyle and have a read there, if you have nothing better to do :slight_smile: