winzip icon

Use GDI+ ( aka GDIPlus ) with VB6 and Win98!

Submitted on: 1/27/2015 1:41:00 AM
By: Avery (from psc cd)  
Level: Advanced
User Rating: By 50 Users
Compatibility: VB 6.0
Views: 7318
     Yes, you can use GDI+ with VB6 (and maybe previous versions with a little editing) along with Win98 or better! Fixed GdiplusShutdown declaration [8/3]. Added ImageLockMode and ImageCodecFlags enums [1/22]. Dana Seaman contributed the translation of the huge EmfPlusRecordType enum and I fixed a frame delay bug in Play GIF [12/4]. Dana created an even better function for getting all GUID constants [12/19]. The goal was to simply port the C++ APIs to VB6, and as I never personally found any comprehensive examples or declarations, although there was one newsgroup post mentioned to me that clarified one issue holding me back (See "HOWTO: call GDIPLUS directly from VB6" in comp.lang.basic.visual.misc), I decided to port nearly 30 SDK samples and declared basically every single API I could find and the required enums and constants. There is so much, I hope I didn't miss anything else... Estimated API conversion accuracy: 99% Correct. If you don't have WinXP, you may need the GDI+ Redistributable RTM which is available here: . . . You should also read the beginning of the GDIPlusAPI module, as it has some useful information. If you find anything wrong, complain away, but show the fix when possible! I don't like when people have a problem and then simply say "I fixed it", as others may have a similar problem and not know how to fix it. I encourage everyone to edit the sample, post better samples, and make some classes to simplify the GDI+ usage even more! I'm not great at writing boring or even exciting introductions, so I'll try my best to explain some core ideas to you, and the code is also heavily commented, though not "well" commented. A GDI+ object class, for the purposes of VB, is simply a pointer (aka Long). The pointer, once retrieved, is simply passed ByVal to the API functions. All you really have to worry about is remembering to delete the object that the pointer represents when you are done. You could also think of the pointer as a handle, if it helps you understand better. Some API functions also want arrays of types for a parameter (you'll usually see a count parameter associated with that function). Another important fact to remember is that ALL strings that GDI+ returns or uses MUST BE UNICODE! In this code I opted to use StrConv to achieve Unicode strings, and the APIs are accordingly declared As String, but you can alter the APIs to use the StrPtr result if you like by selecting the API function declarations and Replace " As String" with " As Long". I opted not to do that as I feared I might forget what type of variable is really required, although doing so improves performance. Also, if you see "argb" floating around, it stands for Alpha-blending, Red, Green, and Blue - it is the color "encoding" scheme used by GDI+. I hope this will quickly cover some of the finer points about GDI+, but I can't rival the explainations of the GDI+ documentation: . . . Notes about the example code: Look at the mnuRedraw_Click menu event to see a list of available samples, and uncomment them to view the demo. I did this to encourage you to view the source. For the thumbnail sample, you'll have to insert the filename of a huge file you'd like to view the thumbnail for. There is also a very basic "freehand" curve drawing demo under the file menu [9/4]. Added a rough on demo how to play an animated GIF [9/7]. Added a SaveGrayscale demo with code from Dana Seaman [11/26]. Added a wrapper demo from Dana [11/30]. Added a DrawTextBackColor demo [1/18]. Added a LockBits demo [1/22]. Added two different BMPtoGIF demos [2/6].
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.