Click here to Skip to main content
15,867,308 members
Articles / Desktop Programming / MFC
Article

Macro to initialize GDI+ in VC6.0 MFC projects

Rate me:
Please Sign up or sign in to vote.
4.80/5 (29 votes)
20 Apr 2003CPOL1 min read 169K   990   49   27
A simple macro that adds all the code necessary to initialize the GDI+ libraries in an MFC 6.0 application

Introduction

I have started to use GDI+ with MFC in VC++ 6.0 and got tired of always having to remember to add the GDI+ startup code and header and library files to my project. So I decided to write a simple VS macro that would do all this for me.

What's added?

In stdafx.h file the following lines are added:

// GdiPlus -- Added by the GdiPlus macro
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib, "Gdiplus.lib")

In the <AppName>.h header file the following lines are added:

// GdiPlus -- Added by the GdiPlus macro
protected:
    ULONG_PTR m_gdiplustoken;

And if the application's ExitInstance() function is not already declared, a declaration is also added in the virtual functions section.

// GdiPlus -- Added by the GdiPlus macro
public:
virtual int ExitInstance();

In the <AppName>.cpp source file, the following lines are added to the InitInstance() function.

// GdiPlus -- Added by the GdiPlus macro
GdiplusStartupInput gdiplusstartupinput;
GdiplusStartup (&m_gdiplusToken, &gdiplusstartupinput, NULL);

And, in the ExitInstance() function, which is added if it is not already present, the following lines are added:

// GdiPlus -- Added by the GdiPlus macro
GdiplusShutdown(m_gdiplusToken);

How to install

Simply save the GdiPlus.dsm file in your <Visual Studio>/Common/MSDev98/Macros/ folder. Then, in Dev Studio, select the Tools menu, Macro dialog. On the Macro dialog click the Options button to show an extra four buttons. Click the Loaded Files button to bring up another dialog. Scroll down the list of macro files until you find GdiPlus. Select the check box for GdiPlus and Bob's your uncle.

That's it! I hope someone finds this useful because I sure do!

Updates

  • April 21, 2003 - Minor bug fix. Thanks to Larry Desonier

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
President
Canada Canada
Father of two, brother of two, child of two.
Spouse to one, uncle to many, friend to lots.
Farmer, carpenter, mechanic, electrician, but definitely not a plumber.
Likes walks with the wife, board games, card games, travel, and camping in the summer.
High school graduate, college drop-out.
Hobby programmer who knows C++ with MFC and the STL.
Has dabbled with BASIC, Pascal, Fortran, COBOL, C#, SQL, ASM, and HTML.
Realized long ago that programming is fun when there is nobody pressuring you with schedules and timelines.

Comments and Discussions

 
GeneralLicensing for commercial application Pin
will626219-Oct-10 5:09
will626219-Oct-10 5:09 
GeneralRe: Licensing for commercial application Pin
PJ Arends20-Oct-10 7:09
professionalPJ Arends20-Oct-10 7:09 
GeneralRe: Licensing for commercial application Pin
will626216-Nov-10 5:13
will626216-Nov-10 5:13 
GeneralDownload GDI+ version 1.1 Pin
pubududilena23-May-04 17:52
pubududilena23-May-04 17:52 
GeneralRe: Download GDI+ version 1.1 Pin
RYU^^27-Sep-05 19:47
RYU^^27-Sep-05 19:47 
GeneralRe: Download GDI+ version 1.1 Pin
Sheng Jiang 蒋晟6-Apr-07 6:54
Sheng Jiang 蒋晟6-Apr-07 6:54 
GeneralUnknown error Pin
shiggity s28-Mar-04 15:48
shiggity s28-Mar-04 15:48 
GeneralRe: Unknown error Pin
PJ Arends28-Mar-04 16:16
professionalPJ Arends28-Mar-04 16:16 
GeneralGDIplus.dll Pin
vimalk5-Feb-04 20:32
vimalk5-Feb-04 20:32 
GeneralRe: GDIplus.dll Pin
PJ Arends6-Feb-04 6:48
professionalPJ Arends6-Feb-04 6:48 
GeneralRe: GDIplus.dll Pin
waelahmed27-Mar-04 23:15
waelahmed27-Mar-04 23:15 
GeneralRe: GDIplus.dll Pin
PJ Arends28-Mar-04 16:20
professionalPJ Arends28-Mar-04 16:20 
GeneralUsing makro inside a dll Pin
jung-kreidler8-Oct-03 21:31
jung-kreidler8-Oct-03 21:31 
GeneralI get some errors Pin
stealth kid19-Jun-03 4:00
stealth kid19-Jun-03 4:00 
GeneralRe: I get some errors Pin
PJ Arends19-Jun-03 10:24
professionalPJ Arends19-Jun-03 10:24 
GeneralRe: I get some errors Pin
nastanet19-Apr-04 22:05
nastanet19-Apr-04 22:05 
GeneralRe: I get some errors Pin
PJ Arends19-Apr-04 22:16
professionalPJ Arends19-Apr-04 22:16 
GeneralRe: I get some errors Pin
Fransiscusherry16-Oct-05 19:33
Fransiscusherry16-Oct-05 19:33 
GeneralWhy not use a simple smart type Pin
Rama Krishna Vavilala15-Jan-03 11:15
Rama Krishna Vavilala15-Jan-03 11:15 
GeneralRe: Why not use a simple smart type Pin
wangwanxin1@163.net17-Jan-05 23:47
susswangwanxin1@163.net17-Jan-05 23:47 
GeneralYep... Pin
Jason Troitsky (was Hattingh)23-Dec-02 7:51
Jason Troitsky (was Hattingh)23-Dec-02 7:51 
GeneralWhere Can I found more GDI+ materials Pin
Ning Cao22-Dec-02 20:11
Ning Cao22-Dec-02 20:11 
GeneralRe: Where Can I found more GDI+ materials Pin
PJ Arends23-Dec-02 9:49
professionalPJ Arends23-Dec-02 9:49 
GeneralRe: Where Can I found more GDI+ materials Pin
ptfoof1-May-04 15:30
ptfoof1-May-04 15:30 
GeneralGraphics hardware acceleration with GDI+ Pin
Giles10-Dec-02 3:04
Giles10-Dec-02 3:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.