Click here to Skip to main content
Click here to Skip to main content

Starting with GDI+

By , 12 Mar 2003
 

Sample Image - StartingGDIPlus.jpg

Introduction

I've been using GDI+ for about a week now, and I must say it is a welcome upgrade. I am working on a paint program, and a lot of things I thought I would have to write myself are now built in, meaning I get them "for free". The upside and the downside are, I guess, the same - things I want my program to do are now a lot easier to accomplish, making it easier both for me, and anyone else wanting to write something similar.

Before I get started, let me thank all the people who helped me get started with GDI+ by letting me know it existed, and where to get it. Parts of the information given here are taken verbatim from the thread where these things were discussed on the CodeProject lounge. Of course, all the cool things are written by me :0)

First things first. You need to get GDI+ installed before you can use it. It is found in the Feb 2001 Microsoft Platform SDK. If you don't download the SDK (or get it on CD) then shame on you. Every release of the SDK includes cool new stuff, such as updates to the WTL. Anyhow, I forgive you if you go to ftp.microsoft.com, and download it NOW. If all you want is GDI+, the files are in psdk-common.11.cab (at least that's what I was told, I downloaded the whole thing).

The files you need are:

  • the dll : gdiplus.dll
  • the library : gdiplus.lib
  • the header files : gdiplus*.h
  • the help files: gdicpp.chm & gdicpp.chi

Don't forget to make sure you set Visual C++ to point to the .h files in the includes, and the .lib file in the directories. Also put gdiplus.lib in your list of libraries by choosing Project/Settings/Link and entering it into the object/library modules area. To set your include and library directories, go to Tools/Options/Directories

To get your application to work with GDI+, do the following:

  • in stdafx.h, add:
    #include <gdiplus.h>
    (at the bottom, before the #endif)
  • in your application class, add the member:
    ULONG_PTR m_gdiplusToken;
    ULONG_PTR is a typedef for unsigned __int64. I usually don't like to use typedefs, but in this case I'll make an exception...
  • in InitInstance, add:
    // Initialize GDI+
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

    I'd love to tell you how all this works, but I'm afraid Microsoft are not currently shipping the source, just headers and a dll.
     

  • in ExitInstance, add:
    Gdiplus::GdiplusShutdown(m_gdiplusToken);

I'll mention at this point that you have the option of prefacing all your commands with GdiPlus::, or you can simply put

using namespace GdiPlus; 

at the head of your code. The rest of my examples will assume you have included this command first, and will not preface commands as such. So now we have a program that initialises GDI+, this is probably a good place to discuss how GDI+ actually works. As you may be aware, GDI works with the concept of a device context. Typically you would draw a box using GDI like this:

(in your OnPaint handler)

CPaintDC dc(this); // Creates a device context for the client area, which
                   // also erases the area to be drawn.

CPen MyPen, * pOldPen;
CBrush MyBrush, * pOldBrush;<BR>
<BR><BR><BR><BR>// A red pen, one pixel wide
MyPen.Create(1, PS_SOLID, RGB(255,0,0));

// Selecting an object returns the old one
// we need to catch and return it to avoid memory leaks
pOldPen = dc.SelectObject(&MyPen);       
                                          
// A Blue brush                                         
MyBrush.CreateSolidBrush(RGB(0, 0, 255)); 
pOldBrush = dc.SelectObject(&MyBrush);

// Finally, we have our device context set up with our pen and brush and can
// use them to draw. <BR>
<BR><BR>//Draws a rectangle that is red on the outside, filled in blue 
dc.Rectangle(0, 0, 200, 200); 
dc.SelectObject(pOldPen);
dc.SelectObject(pOldBrush);

The main thing to understand is that I select a pen or brush and it remains there until I select another, and that the opportunities to leak memory are many, and not exactly easy to debug. In contrast the GDI+ model revolves around creating a graphics object, like so:

CPaintDC dc(this);
Graphics graphics(dc.hdc); 
Now this object is holding our DC until we destroy or release it, and we use this object to manipulate our device context. All the functions take the pen or brush they use, meaning no memory leaks, and ease of writing code that draws in more than one colour. Before presenting an example, let me point out one more exciting thing about GDI+. In GDI we used COLORREF as a variable that held a colour. It was a typedef for a DWORD, and a COLORREF was built using the RGB macro. Colours could be retrieved using GetRValue, GetGValue and GetBValue. In contrast, GDI+ uses the COLOR class, which takes four values to contruct - the extra being alpha. If you are not familiar with the concept of alpha transparency, imagine you are looking through a stained glass window. The colours of the glass affect what you see behind the glass, but the degree to which they obscure your vision depends on how thick the glass is. Alpha transparency similarly blends the colour you use to draw with the colour of the canvas beneath it. Colors in GDI+ are ARGB, the alpha value is specified first. So to draw a line we can do the following:
Pen MyPen(Color(255, 0, 255, ));  // A green pen, with full alpha
graphics.DrawLine(&pen, 0, 0, 200, 100);

GDI+ also dispenses with the idea of a current position: in GDI we used MoveTo(point), followed by LineTo(point). Now we specify both points at once.

I've provided an example program designed to facilitate experimentation by giving you the necessary framework to play with some code, and also to run and see how alpha works, if you've not seen this before. The drawing code creates a pattern in red and blue, then draws over with green, then magenta, and the alpha value fades first up and down, then from left to right.

The OnPaint method of the example program looks like this:

using namespace Gdiplus;

CPaintDC dc(this);

Graphics graphics(dc.m_hDC);

// Pen can also be constructed using a brush or another
//pen. There is a second parameter - a width which defaults to 1.0f
Pen blue (Color(255, 0, 0, 255));

Pen red (Color(255, 255, 0, 0));
int y = 256;
for (int x = 0; x < 256; x += 5)
{
	graphics.DrawLine(&blue, 0, y, x, 0);
	graphics.DrawLine(&red, 256, x, y, 256);  
	y -= 5;
}		
for (y = 0; y < 256; y++)
{
	Pen pen(Color(y, 0, 255,0));
	// A green pen with shifting alpha 
	graphics.DrawLine(&pen, 0, y, 256, y); 
	// The sleep is to slow it down so you can watch the effect 
	Sleep(20);
}		
for (x = 0; x  < 256;  x++)
{
	Pen pen(Color(x, 255, 0, 255));
	// A green pen with shifting alpha 
	graphics.DrawLine(&pen, x, 100, x, 200);
	// The sleep is to slow it down so you can watch the effect
	Sleep(20); 
}

This marks the end of my first GDI+ tutorial. My aim was simply to get you up and running - to show you how to set up a program to use GDI+ and explain some basic concepts about the way it is set up. My next tutorial will be on using brushes - with GDI+ you can make a brush display a gradient, or even be textured with a bitmap. Stay tuned - the real coolness is about to begin...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Christian Graus
Software Developer (Senior)
Australia Australia
Member
Programming computers ( self taught ) since about 1984 when I bought my first Apple ][. Was working on a GUI library to interface Win32 to Python, and writing graphics filters in my spare time, and then building n-tiered apps using asp, atl and asp.net in my job at Dytech. After 4 years there, I've started working from home, at first for Code Project and now for a vet telemedicine company. I owned part of a company that sells client education software in the vet market, but we sold that and now I work for the new owners.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralResize large image on windows mobile 6memberMayur Dhamanwala27 Apr '08 - 2:39 
I am writing a .Net application which runs on windows mobile 6 (PDAs) having 128 mb RAM. The application needs to resize jpeg images (of size >= 4 mb) to thumbnails for further processing. The application just throws outofmemory exception as soon as I try to create a Bitmap of the original image. Is there any method to resize image on windows mobile platform? Any help will be appreciated?
 
Mayur
GeneralThankssussLaura4 Dec '07 - 0:30 
Your example has been very useful for me. Thank you for your time and your effort.
QuestionCapturing screenmemberabc_nus_student27 Nov '07 - 23:00 

Hi
I am trying to capture the screen of a particular application and send it to another custom made window.
How do I do this?
Possibe solutions could be....
1. hooking all GDI API using Detours, this process would be quite tedious....and I am getting scared looking at the sheer number of APIs I may have to hook
2. There is a CopyRect function from x1,y1 to x2,y2 that I could use...but this isnt solving much...cuz If i minimize the application window the other custom made window just shows the image within the co-ordinates (x1,y1 and x2,y2) of the screen....
 
Is there any other way this could be done?
I was reading about WM_PAINT....i dunno if this could lead anywhere....
 
Thanks In advance!Smile | :)
GeneralThanks!memberLeslie Sanford29 Sep '07 - 19:07 
Sometimes you find an article that tells you exactly what you need to get past a hurdle and get on your way. This was exactly what I needed. Good job.
GeneralFiles needed urgentlymemberHakunaMatada7 Aug '07 - 0:37 
Hi,
 
I am in dire need of the below mentioned files and could not find a download for the Platform SDK which supports VC++6. If possible, could you please send me the files at bikash.rai[@]gmail.com. I would remain forever grateful.
 
the dll : gdiplus.dll
the library : gdiplus.lib
the header files : gdiplus*.h
the help files: gdicpp.chm & gdicpp.chi
 
Thank you.

 
---
Beer | [beer] Hakuna-Matata Beer | [beer]
It means no worries for the rest of your days...
It's our problem free, Philosophy

Jig | [Dance]
 
"I think my response was 'What idiot dreamed this up?'" -- Mary Ann Davidson, Oracle's chief security officer, in typical blunt manner, remembering her reaction to the company's scheme to brand its databases as "unbreakable."

QuestionSetPageUnit methodmemberTulio8 Jul '07 - 15:25 
Hi,
I'm starting to work with GDI+ and I tried to draw a 100x100 millimeters square with this code:
 
graphics.SetPageUnit(UnitMillimeter);
Pen bluePen(Color(255, 0, 0, 255), 0.0f);
graphics.DrawRectangle(&bluePen, 1.0f, 1.0f, 100.0f, 100.0f);
 
To my surprise, the size of the square on the screen is 106x106 millimeters.
SetPageUnit shouldn’t take care about converting world to page to device conversions?
How can I get the correct size on my screen?
 
Thanks!

GeneralType mistakemembermonteiz21 May '07 - 22:50 
Hey man,
thanks for your article, i find it truly useful.
 
Just one thing: please fix the P in GdiPlus, turn it to Gdiplus or a lot of easy people like me will keep on wasting time searching for a "namespace does not exist" on google! Wink | ;)
 
Try google this:
 
"error C2871 GdiPlus namespace"
 
All of them come from your article! Hihihi Smile | :)
 
Ciao!
 
Montezuma
Generalamembersimona_onesti13 Feb '07 - 23:25 
I want to create some clases
 
ssss

GeneralRe: astaffChristian Graus14 Feb '07 - 9:28 
OK, is this a general programming question, or a question about the article ? I don't even understand the question. you want to know how to create a class ? Surely not ?

 
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog

GeneralPlease help me : Facing one problemmemberasdasd@yahoo.com6 Dec '06 - 19:41 
am using GDI+ for bitmap image compression .
I have used this code. but when i complie it...error occurs as follow
 

gdiplus.lib(imagingguds.obj) : fatal error LNK1103: debugging information corrupt; recompile module
 
I am getting the reason since i am new to GDI+
Please help me

GeneralRe: Please help me : Facing one problemstaffChristian Graus14 Feb '07 - 9:29 
Looks like your lib file is corrupt, I'd download it again.

 
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog

GeneralGDI +memberan_handsome1 Dec '06 - 22:47 
i have a problem with GDI+.
who can explain to me ,please?
Why did VC++ say that "Graphics" Class undefine,although i added GDI+ into VC Librabry and included Gdiplus header file?
GeneralRe: GDI +staffChristian Graus14 Feb '07 - 9:29 
I suspect because you're not using the GDIPlus namespace.

 
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog

QuestionError in compiling this program(VC++ 6.0)memberDhananjayak0212 Aug '06 - 23:52 
I'm using Visual C++ 6.0
 
I have Downloaded and installed the Platform SDK Redistributable: GDI+ (File Name: gdiplus_dnld.exe Version: 3102.1360 ) to the computer.But I cannot compile GDI+ included project that have given in this article.It says that no such directory or file.The error code is given below.
 

 
Compiling resources...
Compiling...
StdAfx.cpp
d:\_thisara\gdi_c++\gdi++\stdafx.h(22) : fatal error C1083: Cannot open include file: 'gdiplus.h': No such file or directory
Error executing cl.exe.
 
Please tell me what else I have to do inorder to proceed with GDI+
 
Thanks
 
Thisara

 

ENTC
UoM

AnswerRe: Error in compiling this program(VC++ 6.0)staffChristian Graus13 Aug '06 - 0:50 
How old is the PSDK you are using ? The PSDK has not worked with VC6 ( which is 3 versions old and no longer supported ) for some time. Probably this is the reason you're getting this error.

 
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog

GeneralRe: Error in compiling this program(VC++ 6.0)memberDhananjayak0213 Aug '06 - 5:12 
Dear Christian,
 
Thank you for taking time to look into my matter.
 
The PSDK im using is Windows SDK - Windows Server 2003.I have installed all the components availble there(Core SDK ,Internet Development SDK, IIS SDK, MDAC SDK, Windows Installer SDK, WMI SDK ,Windows Media Services SDK).
 
Anyway,Little while ago, I gave the directories of include files and Lib files (Tools >> Options >> Directories).Before that when the first error message came(in original question) I have not given the directories.
 
Now... there were 16 errors which are shown below. I cannot resolve them.most of them are errors of "gdiplusinit.h" which is given by the SDK.pls tell me what's wrong here..

--------------------Configuration: Starting GDIPlus - Win32 Debug--------------------
Compiling...
StdAfx.cpp
f:\program files_2\microsoft sdk\include\gdiplusinit.h(32) : error C2065: 'ULONG_PTR' : undeclared identifier
f:\program files_2\microsoft sdk\include\gdiplusinit.h(32) : error C2065: 'token' : undeclared identifier
f:\program files_2\microsoft sdk\include\gdiplusinit.h(32) : error C2165: 'left-side modifier' : cannot modify pointers to data
f:\program files_2\microsoft sdk\include\gdiplusinit.h(32) : error C2071: 'NotificationHookProc' : illegal storage class
f:\program files_2\microsoft sdk\include\gdiplusinit.h(33) : error C2146: syntax error : missing ')' before identifier 'token'
f:\program files_2\microsoft sdk\include\gdiplusinit.h(33) : error C2165: 'left-side modifier' : cannot modify pointers to data
f:\program files_2\microsoft sdk\include\gdiplusinit.h(33) : error C2071: 'NotificationUnhookProc' : illegal storage class
f:\program files_2\microsoft sdk\include\gdiplusinit.h(33) : error C2059: syntax error : ')'
f:\program files_2\microsoft sdk\include\gdiplusinit.h(86) : error C2059: syntax error : 'const'
f:\program files_2\microsoft sdk\include\gdiplusinit.h(95) : error C2146: syntax error : missing ')' before identifier 'token'
f:\program files_2\microsoft sdk\include\gdiplusinit.h(95) : warning C4229: anachronism used : modifiers on data are ignored
f:\program files_2\microsoft sdk\include\gdiplusinit.h(95) : error C2182: 'GdiplusShutdown' : illegal use of type 'void'
f:\program files_2\microsoft sdk\include\gdiplusinit.h(95) : error C2059: syntax error : ')'
f:\program files_2\microsoft sdk\include\gdiplusflat.h(2639) : warning C4229: anachronism used : modifiers on data are ignored
f:\program files_2\microsoft sdk\include\gdiplusflat.h(2639) : error C2440: 'initializing' : cannot convert from 'int' to 'enum Gdiplus::Status'
Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
f:\program files_2\microsoft sdk\include\gdiplusflat.h(2644) : error C2146: syntax error : missing ')' before identifier 'token'
f:\program files_2\microsoft sdk\include\gdiplusflat.h(2644) : warning C4229: anachronism used : modifiers on data are ignored
f:\program files_2\microsoft sdk\include\gdiplusflat.h(2644) : error C2182: 'GdiplusNotificationUnhook' : illegal use of type 'void'
f:\program files_2\microsoft sdk\include\gdiplusflat.h(2644) : error C2059: syntax error : ')'
Error executing cl.exe.
 
Starting GDIPlus.exe - 16 error(s), 3 warning(s)
 

Regards
 
Dhananjaya

 

ENTC
UoM

GeneralRe: Error in compiling this program(VC++ 6.0)memberDhananjayak0213 Aug '06 - 5:40 
Dear Christian,
 
Now the problem is OK..
 
I inserted following code in StdAfx.h just above #include "gdiplus.h" as sugested in a earlier thread.Now all the things are OK.
 
#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#endif

 
Thanks
 

ENTC
UoM

GeneralRe: Error in compiling this program(VC++ 6.0)staffChristian Graus13 Aug '06 - 11:37 
Looks like that #define is what's needed to make the newer SDK work with VC6 then. Either way, VC6 is unsupported ( and also really bad ). You should really consider a move to VS.NET - surely VS2002 would be fairly cheap to buy on ebay or something.

 
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog

GeneralRe: Error in compiling this program(VC++ 6.0)memberyv312 Nov '08 - 8:28 
I Rose | [Rose] VC6
QuestionAdding a GIF image in VC++ 6.0memberDhananjayak0212 Aug '06 - 4:19 

 
Hi..
 
Please tell me a way to insert/add a GIF image in VC++ 6.0. And also I want to change the image's position (In XY Coordinates) and to rotate the Image in specified angles.
 
I need someones help in the above matter...
 
Can I use GDI+ in Visual Studio 6.0 Programming(VC++)? I don't know much details about GDI+.
 

Thanks
 

Dhananjaya
 

 

ENTC
UoM

AnswerRe: Adding a GIF image in VC++ 6.0staffChristian Graus13 Aug '06 - 0:51 
You can use GDI+ with VC6, but you need to get ahold of an older PSDK in order to do so.
 
I have an article on CP on rotating images with GDI+. As you're drawing the image, the position of the image is entirely up to you.

 
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog

GeneralRe: Adding a GIF image in VC++ 6.0 [modified]memberDhananjayak0214 Aug '06 - 3:23 
Hi,
 
I was able to start working with GDI+ in VC++ 6.0 after the discussion with you. I tried to insert a image to my main frame using "Image" in GDI+. But a runtime error (unhandled exception) is occuring when im going to run the program.The details are as follows.
 
I have included "gdiplus.h" in StdAfx.h. There were no issue on that.But the problem started when i tried to insert a image using the guidelines given in following msdn link(.Drawing, Positioning, and Cloning Images - GDI+)
 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/AboutGDIPlus/IntroductiontoGDIPlus/OverviewofGDIPlus.asp
 

 
As per that methode I used the following code:
 
CPaintDC dc(this);
Graphics myGraphics(dc.m_hDC);
 

Image myImage(L"robot.gif"); // this line creates the problem
myGraphics.DrawImage(&myImage, 20, 10);

The program Built & compiled successfully.But didn't run.It gaves a error.
 
When I insert that code to a .NET project the error message says that ;"Unhandled exception at 0x7c9105f8 in tttdk.exe: 0xC0000005: Access violation reading location 0x00000010."
When I break it , it shows the location of the error in the following cpp file.
 
D:\VS\VC\atlmfc\src\atl\atls\allocate.cpp

..
 
...
 
CAtlTraceCategory *CAtlAllocator::GetCategory(int iCategory) const
 
{
 
if(iCategory == m_pProcess->CategoryCount())
 
return NULL;
 

 
ATLASSERT((iCategory < m_pProcess->CategoryCount()) || (iCategory == -1));
 
CAtlTraceCategory *pCategory = NULL;
 
if(iCategory >= 0)
 
{
 
BYTE *pb = reinterpret_cast(m_pProcess) + m_pProcess->MaxSize(); // this is the location of the error
 
pCategory = reinterpret_cast(pb) - iCategory - 1;
 
}
 
return pCategory;
 
}
 
.....
 
.........

 
Please help me regarding the above matter ASAP.My intention was to make a Image object and manupulate its posision and orientation.
 

Thisara
 

 

-- modified at 10:11 Monday 14th August, 2006
 

ENTC
UoM

GeneralRe: Adding a GIF image in VC++ 6.0staffChristian Graus14 Aug '06 - 10:18 
The big question would be, can you do *anything* with GDI+ ? Because, you're using an unsupported SDK, it's entirely possible that it's all linking, but it's still never going to work. The code looks fine, so I'd imagine the best remedy would be to get a decent ( up to date and supported ) compiler, unless you can get a really old PSDK so you can work with VC6.

 
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog

QuestionNothing appears on the DLG?memberbadtiger5 Aug '06 - 20:04 
My project is almost same with yours,but nothing appear on the dialog face at the beginning,seveal seconds later,OK and CANCEL buttons turn up.what's the problem?
 
Every body could do anything they want, unless fools.

AnswerRe: Nothing appears on the DLG?staffChristian Graus6 Aug '06 - 0:24 
I guess you need to look at ( and possibly post ) the bits that are different.

 
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog

AnswerRe: Nothing appears on the DLG?memberSarath.10 Feb '07 - 7:48 
Seems you forgot to Initialize GDI Plus
 
Christain has written this code in the App class. please check it
 
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
 
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin


General"some" errorsmemberdenishernandez14 Feb '06 - 16:28 
hello
I'm using cximage and dcmtk in a convert app and some errors in cximage take me to gdiplus.h(one thing take you to other)
but get this errors iqual that when compile your app in code project, I'll appreciate your help. thanks
 
Compiling...
StdAfx.cpp
c:\dicom\gdi++files\gdiplusinit.h(32) : error C2065: 'ULONG_PTR' : undeclared identifier
c:\dicom\gdi++files\gdiplusinit.h(32) : error C2065: 'token' : undeclared identifier
c:\dicom\gdi++files\gdiplusinit.h(32) : error C2165: 'left-side modifier' : cannot modify pointers to data
c:\dicom\gdi++files\gdiplusinit.h(32) : error C2071: 'NotificationHookProc' : illegal storage class
c:\dicom\gdi++files\gdiplusinit.h(33) : error C2146: syntax error : missing ')' before identifier 'token'
c:\dicom\gdi++files\gdiplusinit.h(33) : error C2165: 'left-side modifier' : cannot modify pointers to data
c:\dicom\gdi++files\gdiplusinit.h(33) : error C2071: 'NotificationUnhookProc' : illegal storage class
c:\dicom\gdi++files\gdiplusinit.h(33) : error C2059: syntax error : ')'
c:\dicom\gdi++files\gdiplusinit.h(86) : error C2059: syntax error : 'const'
c:\dicom\gdi++files\gdiplusinit.h(95) : error C2146: syntax error : missing ')' before identifier 'token'
c:\dicom\gdi++files\gdiplusinit.h(95) : warning C4229: anachronism used : modifiers on data are ignored
c:\dicom\gdi++files\gdiplusinit.h(95) : error C2182: 'GdiplusShutdown' : illegal use of type 'void'
c:\dicom\gdi++files\gdiplusinit.h(95) : error C2059: syntax error : ')'
Error executing cl.exe.
 
convertfromdcm.exe - 12 error(s), 1 warning(s)

GeneralRe: "some" errorsmemberChristian Graus15 Feb '06 - 13:40 
You probably don't have a recent platform SDK installed, and you're probaby using VC6.0. If this is the case, download and install the latest platform SDK.

 
Christian Graus - Microsoft MVP - C++
GeneralRe: "some" errorsmemberbadtiger5 Aug '06 - 20:08 
have this a try:
add these code into "stdafx.h".
#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#endif
 

 
Every body could do anything they want, unless fools.

GeneralRe: "some" errorsmemberDhananjayak0213 Aug '06 - 5:37 
thanks a lot ... your hint worked....
 

 

ENTC
UoM

QuestionVisual C++ 6.0?memberPaolo Pasquali18 Jul '05 - 4:47 
Dear Christian,
 
unfortunately, after sucessfully starting using GDI+ thanks
to you in 2003 using Visual C++ 6.0, now I'm not able anymore to compile
anything (not even your example), and I fear because of some service pack
installed in the meantime...
I tried to uninstall all platform SDKs and reinstall the February 2003
Edition one (it says on the Microsoft pages that this is the last one
supporting VC++6.0), but with no success (even after having to order the CD
from Microsoft, since the download is not supported anymore)...
On a machine where no SDK at all had ever been installed also no success
after installing the February 2003 Edition, and I fear to make it even more complicate if I try also with the SDK you suggest. Any clue?
Shall I really swith to a more recent Visual Studio version?
 
Thanks a lot in advance!
Regards,
Paolo Pasquali
AnswerRe: Visual C++ 6.0?memberChristian Graus18 Jul '05 - 12:57 
There are a million reasons why you should dump VC6. Standards conformance would be the main one. Having said that, I'm stuck in a VC6 project at the moment, and I just downloaded and installed the latest SDK, no problems that I can see. Microsoft not offering support does not mean it won't work.

 
Christian Graus - Microsoft MVP - C++
GeneralRe: Visual C++ 6.0?memberPaolo Pasquali22 Jul '05 - 4:50 
Thanks a lot!
Btw: I finally succeeded in compiling, but only by explicitely type-defining myself the ULONG_PTR type...
GeneralRe: Visual C++ 6.0?memberarmentage15 Aug '05 - 4:39 
Actually I've run in to many problems trying to use the "Windows2003" PSDK (the latest and greatest) on VC6. There is some difference in linker output that makes VC6 compiled binaries unable to link with the latest PSDK .libs. I haven't been able to find any leads on resolving the problem, but circa-2003 (not windows2003) PSDKs still seem to work fine, and the latest SDK additions have been frills I can do without. This is a case where lack of MS support [b]DOES[/b] suck Frown | :(
 
I'm in the same boat as you - can't switch to VC7 because the big boss won't "fix what ain't broke".

GeneralRe: Visual C++ 6.0?memberChristian Graus15 Aug '05 - 13:18 
armentage wrote:
Actually I've run in to many problems trying to use the "Windows2003" PSDK (the latest and greatest) on VC6.
 
That's because the last SDK to support VC6 was Feb 2003.
 
armentage wrote:
This is a case where lack of MS support [b]DOES[/b] suck
 
Why would they keep supporting a compiler they don't sell anymore, and that frankly, is crap ?
 
armentage wrote:
I'm in the same boat as you - can't switch to VC7 because the big boss won't "fix what ain't broke".
 
Actually, I am using VC2005 most of the time, VS.NET2003 for most of the rest, and VC6 for one project, which I am about to convert to VC2005. Your boss is wrong, it IS broke, it's limiting what you can do, all the more because the C++ implimentation you have is crap. The longer you use it, the greater the cost of moving your code base to real C++.

 
Christian Graus - Microsoft MVP - C++
GeneralRe: Visual C++ 6.0?memberarmentage16 Aug '05 - 3:18 
Can you point out any specific grievances with VC6? What makes it "Crap" C++?
GeneralRe: Visual C++ 6.0?memberChristian Graus16 Aug '05 - 13:25 
Terrible STL implimentation.   No Koenig lookup.   Many, many other places where it deviates from the standard.   One example off the top of my head
 
for (int i =0; i < 10; ++i)
{
// do something
}
 
for (int i =0; i < 12; ++i)
{
// do something else
}
 
This is valid C++, but VC6 won't compile it.
 
Another:
 
std::vector<int>::iterator it = myVec.begin();
 
while(it != myVec.end())
{
int * i = it; //   This is not valid C++, but VC6 allows it.
 
++it;
}
 
The list goes on and on.   If you read CUJ, they have a column on ways compilers deviate from the standard, in the VC6 days, every month they found 2-3 problems.   VC7 on the other hand is astounding in the leap they took from non-C++ to standards conformance, and it just keeps getting better.

 
Christian Graus - Microsoft MVP - C++
AnswerRe: Visual C++ 6.0?memberbob1697230 Oct '05 - 8:03 
I found that life is much better if you install an older SDK and put it first in your paths in VC6 and then install the February Platform 2003 SDK in a different directory and place it's paths after the first one. I use the SDK that comes on the samples disk in the book...
 
Programming Server-Side Applications for Microsoft® Windows® 2000
by Jason Clark and Jeffrey Richter
 
I have tried just putting the February 2003 SDK on new machines without the other one installed and nothing seems to work right in VC6. However, the older SDK does not have GDI+ so I've been forced to limp along this way for a while.
 
Good luck

GeneralSweetmemberbob1697211 Jun '05 - 19:43 
The strings align perfectly with the bounding rectangles using MM_ISOTROPIC scaling when using something like...
 
graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
 
look out Adobe!
 
The fonts just had a mind of their own on the screen with GDI.
(Before someone crucifies me...yes, there was a constant from WinNT on up for LOGFONT
lf.lfQuality=ANTIALIASED_QUALITY|PROOF_QUALITY;
that seemed to antialias fine but it did not align correctly with the bounding rectangle... or any rectangle, line, circle for that matter... when scaling using MM_ISOTROPIC)
 
Performance suffers a bit but you can't argue with the accuracy. This is a godsend from Microsoft.
 
Thanks for your posting on how to make it a reality for those of us still scratching our heads about whether to embrace the .NET stuff. This will give me something to play with while I suffer the agony of playing with the Visual Studio 2005 Beta 2. (Where oh where has my VC++ 6.0 gone?) (But for GDI...good riddens!)
GeneralSubmissions are Outstanding.membersreejith ss nair17 Mar '05 - 20:29 
Dear Chris,
 
All your article in GDI+ are outstanding. Really i got interested in doing something in GDI+. You have such a massive potential in GDI. i mean, its is real blessing for you. Actually i have a doubt on GDI. and infact i don't have your mail id to ask directly. That's why i am just using a thred to reach you.
 
We have a project like Microsoft project Planner ( MS project). our project also a client server project.
 
name of o ur project is 'Planner'. So name itself describes that it is something to do with visualization. Really it is for data visualization.
To be conzise, we have a list of records in database and in planner we are drwaing some shapes using that data. So our entire interface will look like microsoft project planner.
 
i am doing lot of custom painting and exploiting lot GDI classes to visualize the data. Now we have a requiremt to make this windows application as a web based peoject. Here also i need to visualize data. I mean i need to draw shaped based on records avilable.
 
tell me chris,
What is the fecibility of the project.
If i want to go ahead with this project, what i need do ? where i will get some help ? Is there any way to get Image files from data ?
 
your comment is most appriciable.
 

 
Sreejith Nair
[ My Articles ]
GeneralRe: Submissions are Outstanding.memberChristian Graus20 Mar '05 - 11:33 
The only issue with a web based project is to remeber the seperation between client and server. So long as your image files are on the server end, or can be uploaded, there's no reason you can't process/create/display images with GDI+ just as you would with a WinForms app.
 
Christian
 
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
GeneralRe: Submissions are Outstanding.membersreejith ss nair20 Mar '05 - 16:49 
This is clear. But Chris, if we have images in server then we can easily send that image to clients side. right. If so, i can create images and send it to sever. But my main issues is 'how will i create an image from a collection of data. Please direct me some helpful urls or any documentations.Big Grin | :-D
 
Sreejith Nair
[ My Articles ]
GeneralRe: Submissions are Outstanding.memberChristian Graus20 Mar '05 - 16:54 
sreejith ss nair wrote:
if we have images in server then we can easily send that image to clients side
 
correct
 
sreejith ss nair wrote:
But my main issues is 'how will i create an image from a collection of data.
 
I'm not sure how this changes because you've gone to a web based system. Don't you have this code already ? And either way, what you're asking is not clear. What sort of image do you want ? That is, what do you want to put on it ? What you want to do is use the API calls that draw boxes/text/shapes/etc, in such a way that they represent your data.

 
Christian
 
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
GeneralRe: Submissions are Outstanding.membersreejith ss nair20 Mar '05 - 17:45 
Dear Christian,
 
Now i have a winform which will create few custom movable label on my application. And my winform have a panel control (panel paint method overrided). I am dragging and drouping the above custom controls into my panel. To be simple, my project is like microsoft project 2000.
Now i would like to get the screen shot of this form (only the panel area). so one solution for this issue is keep some screen shot when user runns winform and serve that image when user get into web application.
 

 
Sreejith Nair
[ My Articles ]
GeneralRe: Submissions are Outstanding.memberChristian Graus20 Mar '05 - 17:48 
OK - the labels were written by you, so their onpaint methods will contain the code you need to build your bitmaps Smile | :)

 
Christian
 
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
GeneralRe: Submissions are Outstanding.membersreejith ss nair20 Mar '05 - 18:00 
Yes Chris, But the issue is , the location of the lable will be changing everytime on each user updation. so if somebody want to see the panel on web, it will show only the last image which takes from that winform. But it may or maynot be the latest updated one. That's why i thought of creating the images directly from database.
And now i am not sure how will i do this in web.
 
Sreejith Nair
[ My Articles ]
GeneralRe: Submissions are Outstanding.memberChristian Graus20 Mar '05 - 18:04 
sreejith ss nair wrote:
it will show only the last image which takes from that winform.
 
I'm saying don't bother with trying to catch things off a form, that's a hack. Your controls already have the code you need to paint your images, you can't stop the problem that your controls will look the same until a postback. So, generate them on the fly each time, using the data and state of your web app, and the painting code from your controls. The only issue is time and size of images going back and forth.

 
Christian
 
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
GeneralRe: Submissions are Outstanding.membersreejith ss nair20 Mar '05 - 18:14 
Chris, sorry to disturb you again. This is my first web application. So i am not sure about the page state changes and related handling methods. Chris, can you give me an over all picture (skeleton) of my web application. ie, where i will start and which are the interfaces or controls(i am using panel in windows) are best to hold custom painted controls in web application.
And to get on fly data, what method of postback i need to follow..
 
Sreejith Nair
[ My Articles ]
GeneralRe: Submissions are Outstanding.memberChristian Graus21 Mar '05 - 10:55 
What do you mean by 'on the fly data' ? To show images, you need to store them on disc on your server, then create an img tag in your page that points to the image. If you're creating them for temporary use, you probably need to use guids or something for names, and store the names for deletion in a cleanup stage ( given that you can't guarentee postback ).
 
Basically, a web page exists as an immutable entity - it goes out, and that's it. When the user interacts with the page, you'll get a postback, and a chance to change the page before it goes out again.

 
Christian
 
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
GeneralRe: Submissions are Outstanding.memberMarcus_225 Apr '05 - 3:16 
Christian Graus wrote:
To show images, you need to store them on disc on your server, then create an img tag in your page that points to the image
 

Actually you don't have to store the pictures on disc (but makes it a lot easier).
 
Solution 1 (which is not an answer to Christian Graus but to the threadcreator).
Give every picture a unique name as they are and set the img tag to that image. Either delete the file after it has been retrived by the client or for example delete all pictures more tha 1 day.
 
Solution 2.
Don't create a image on the disk. Instead write a unique id in the img tag src="GetImage.aspx?ImageId=qwerty123456" and in the call to GetImage.aspx create the image and send it back in the response as a bytearray. This obvioly means you have to store the data needed to create the picture somewhere.
 
Sorry for the .Net aspx code, but merly an example on how to do it.
 

//FM = an object that handles files (stored on disc or in memory), can also be used to create objects
 
FM.CreatePicture(params);
 

context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ContentType = "application/unknown";
context.Response.AddHeader("Content-Disposition", "attachment; filename="+ context.Server.UrlEncode(FM.FileName));
context.Response.BinaryWrite( FM.FileContent ); //FM.FileContent = byte[]
 

 
FM has to be created but not stored

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 13 Mar 2003
Article Copyright 2001 by Christian Graus
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid