GDI+?

Started by
18 comments, last by ageny6 20 years, 10 months ago
No, there''s an unmanaged C++ API as well.


AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Advertisement
This is great! I thought it was only for .NET. So somebody can usit with C++ or VB6 and doesn''t need .NET framework at all to work?

Because even if it isn''t the solution for fast graphically intense games, it includes lots of useful things for loading pictures, creating shapes, paths and other stuff that you use in the background for different things, maybe even texture creation (but I''m not sure how fast this part of GDI+ is).
School TournamentThis game is going to kisk some teacher ass!More on: www.3dlevel.com
Yes, GDI+ is quite good actually. Over at CodePrject.com somebody did an article on drawing speed in GDI+. Might wanna check it out:
Drawing Speed in GDI+

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction.
"We confess our little faults to persuade people that we have no large ones." -Francois de La Rochefoucauld (1613 - 1680). | My blog
quote:Original post by Flamer3D
So somebody can usit with C++ or VB6 and doesn't need .NET framework at all to work?

So you are telling me that you can take the GDI+ for c++ and convert it to vb6? If so, how in the world can you do that??? Did I interpret what you meant all wrong (did you mean something else when you mentioned vb6?)?


Jonathan

[edited by - ageny6 on June 1, 2003 8:51:52 AM]
My signature used to suck. But it's much better and more accurate now.
I was asking Arild Fines if you can use GDI+ withouth having .NET framework installed. That was the meaning of the question, I got that VB6 or C++ there unintentually.

Otherwise you can make any C++ API work with VB6, just have to make a wrapper for it (I think it is the sam as with calls to win32 from VB6 when you use the declare statement)
School TournamentThis game is going to kisk some teacher ass!More on: www.3dlevel.com
GDI+ uses C++ and classes for all the graphic objects.
You will not be able to manipulate these classes directly in VB6.

You will need to create a DLL in C++ and create wrapper functions around GDI+

For instance here are a couple of functions that I have exposed to VB6.

The wrapper functions...

int CALLBACK GDIplusInitEngine(void)
{

// Init gdiplus

Gdiplus::Status Stat = Gdiplus::GdiplusStartup(&gdiplusToken,&gdiplusStartupInput, NULL);

if(Stat == Gdiplus::Ok) return -1; else return 0;

}

void CALLBACK GDIplusCloseEngine(void)
{
Gdiplus::GdiplusShutdown(gdiplusToken);
}

You have to initialise GDI+ once and you have to close it when finished.






Alrighty,

I know that you can create a .dll wrapper class for VB6, but I have never done it (never really had to). Is there a good tutorial out there that can help me in this process? Is there a VB6 GDI+ already created?

Jonathan

[edited by - ageny6 on June 2, 2003 10:02:36 AM]
My signature used to suck. But it's much better and more accurate now.

Don't know which VC you are using but you need to create a DLL project.

You will need to get the GDI+ sdk from Msofts site and refer to gdiplus.lib in your
dependicies for the linker to resolve. You will also need to put wingdi on your include
path as well.

For non XP end users get the redistribution. Never attempt to replace the Msoft
GDI+ dll on XP. Only win 95 cannot have GDI+ (Think)


Here is some sample code. Very monolithic but you should get the idea from this.

// windows and gdi stuff

#include <windows.h>
#include <wingdi.h>
#include <gdiplus.h>



// Just for convenience. You might want to prefix eg. Gdiplus:en
using namespace Gdiplus;

// Some magic decimal numbers for converting VB long colour values to RGB

#define RED_MASK 255
#define GREEN_MASK 65280
#define BLUE_MASK 16711680


// Some globals. Stick em in a class if you want this is just to get it going.

static ULONG_PTR gdiplusToken;
static GdiplusStartupInput gdiplusStartupInput;

// A flag to detect if we called init

static int GdiPlusInit;


/* Just some functions.

I find creating a .def file in VC works ok for the mangling for VB6

so create a .def file and list each function like this

EXPORTS

GDIplusInitEngine
GDIplusCloseEngine
GDIplusLineTo
SomeOtherFunc


*/


// CloseEngine - See DLL - Also read Msofts notes on caveats

void CALLBACK GDIplusCloseEngine(void)
{

if(GdiPlusInit)
{
GdiplusShutdown(gdiplusToken);
GdiPlusInit = 0;
}


}

// Initengine - read notes further down in DLLmain
int CALLBACK GDIplusInitEngine(void)
{

// Just in case you call it twice - Global keeps track of it.
GDIplusCloseEngine();
// Init gdiplus

Status Stat = GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

if(Stat == Ok)
{
GdiPlusInit = 1;
}
else
{
GdiPlusInit = 0;
}

return(GdiPlusInit);

}


//Just a simple Drawline. Pass the Device context in from VB


void CALLBACK GDIplusLineTo(HDC Ahdc, int x1, int y1, int x2, int y2, int outlineW, int outlineCol)
{

Pen* myPen;
Graphics* myGraphics;

int S_Red , S_Green , S_Blue;

S_Red = (outlineCol & RED_MASK);
S_Green = (outlineCol & GREEN_MASK) >> 8;
S_Blue = (outlineCol & BLUE_MASK) >> 16;


myPen = new Pen(Color(255, S_Red, S_Green, S_Blue),(float) outlineW);

myGraphics = new Graphics(Ahdc);

// Cool GDI+ antialiased lines
myGraphics->SetSmoothingMode(SmoothingModeHighQuality);

// I want round ended lines. Have a look there is a ton if settings.
myPen->SetStartCap(LineCapRound);
myPen->SetEndCap(LineCapRound);

/* GDI+ seems to have a problem with some linewidths when plotting
a line with the same cords. Drawing an ellipse seems to fix it and it looks better */

if(x1 == x2 && y1 == y2)
{
SolidBrush brush(Color(255, S_Red, S_Green, S_Blue));
myGraphics->FillEllipse(&brush, x1 - (outlineW/2),y1 - (outlineW/2),outlineW ,outlineW);

}
else
{
myGraphics->DrawLine(myPen, x1, y1, x2, y2);
}

delete myGraphics;
delete myPen;


}


// Dll Entry point
int WINAPI DllMain(HINSTANCE hInstance,DWORD fdwReason,PVOID pvReserved)
{


switch (fdwReason)
{
case DLL_PROCESS_ATTACH:

/* Do not be tempted to init GDIplus from here
Microsoft strongly advises not too
Init it from your calling application.

You must also close it down when finished with it
don't attempt to nest either */

GdiPlusinit = 0;
break;

case DLL_THREAD_ATTACH:

break;

case DLL_THREAD_DETACH:

break;

case DLL_PROCESS_DETACH:

/* msoft says nothing about closing it down in a dLL
all depends on what you are using it for I suppose

Note in VB6 you will get bad crashes in the IDE if Gdiplus
is not closed down properly. Watch your close app event
this detach will catch any stragglers though.


if(GdiPlusInit)
{
GdiplusShutdown(gdiplusToken);
GdiPlusInit = 0;
}


break;
}


return TRUE;
}



Ok there is a skeleton. Put your DLL where VB can find it. Usually system directory.


Now the VB end....

Declare Function GDIplusInitEngine Lib "YourGdiPlusDLL" () As Long
Declare Sub GDIplusCloseEngine Lib "YourGdiPlusDll" ()

Declare Sub GDIplusLineTo Lib "YourGdiPlusDLL" (ByVal Winhdc As Long, _
ByVal x1 As Long, _
ByVal y1 As Long, _
ByVal x2 as Long, _
Byval y2 as Long, _
ByVal penwidth As Long, _
ByVal pencolour As Long)



sub main()
ok = GDIplusInitEngine()

if ok = 0 then
beep
end
end if
myform.show

' draw a line
GdiPlusLineTo(myform.hDc, 0 , 0 , 100 , 132 , 4 , vbRed)

end sub



That should get you started. I also think there is a good tutorial over at flipcode.com for using your own DLL's
from VB.

Good luck














[edited by - andyed on June 2, 2003 12:12:20 PM]
Awesome, that should get me started. I will look into it tommorrow and ask questions later (because god knows how much I ask)

Jonathan
My signature used to suck. But it's much better and more accurate now.
Here is the tutorial for interfacing VB with C++ via Dll''s Some good stuff about string types and UDT''s as well.

http://www.flipcode.com/articles/article_vbdlls.shtml

This topic is closed to new replies.

Advertisement