 |
|
 |
when building the sample with VS2010 you need to define in your project settings GDIPVER=0x0110
Project | MFC_GDI_PLUS Properties - C++ Preprocessor, Preprocessor Definitions
GDIPVER=0x0110 is GDI+ 1.1 which ships with Windows Vista (and later), but for installing your application on older versions of Windows you can get the latest GDI redistributable from Microsoft Downloads (see link)
http://www.microsoft.com/download/en/details.aspx?id=18909[^]
modified on Wednesday, September 14, 2011 5:48 AM
|
|
|
|
 |
|
 |
Despite what others may claim, finding a quick sample of the relevant include files and initialization code for gdiplus in mfc C++ was not trivial.
MSDN links broken or obsolete. MSDN search yielded nothing.
So, while there may be more detailed posts elsewhere, this one was short and to the point and solved the main problem of "what files do I have to include and how do I get access to gdiplus in an mfc project".
Cheers,
|
|
|
|
 |
|
|
 |
|
 |
If you are using GDI+ inside a DLL, you will probably have to suppress the background thread. You can do this by adding:
GdiplusStartupOutput gdiSO;
gdiSO.SuppressBackgroundThread = TRUE;
Just before the call to GdiplusStartup(...)
and also setting the notification hook, by using:
ULONG_PTR gdiHookToken;
gdiSO.NotificationHook(gdiHookToken);
and
gdiSO.NotificationUnhook(gdiHookToken);
just before GdiplusShutdown(...)
I was not able to register the DLL until I did these steps.
|
|
|
|
 |
|
 |
Actually, that would need to be set on the GDI+ startup input object:
GdiplusStartupInput gdiSI;
gdiSI.SuppressBackgroundThread = TRUE;
|
|
|
|
 |
|
 |
Hi, everyone.
In my dll project, I wanted to called the gdi+. But, it didn't work. Could you tell me how to deal with this problem as detailed as possible?
Thanks.
|
|
|
|
 |
|
 |
Here's what you will need to do. In your DLL's source perform the following steps:
Add some member variables to your DLL's header:
// Variables for GDI+ resource management.
GdiplusStartupInput m_gdiplusStartupInput;
GdiplusStartupOutput m_gdiplusStartupOutput;
ULONG_PTR m_gdiplusToken;
ULONG_PTR m_gdiplusHookToken;
Then, write code like this for your DLL's InitInstance:
// CImageModLibApp initialization
BOOL CMyLibApp::InitInstance()
{
// Disable background thread since we are a DLL.
m_gdiplusStartupInput.SuppressBackgroundThread = TRUE;
// Initialize GDI+ resources.
Gdiplus::Status status = GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, &m_gdiplusStartupOutput);
ASSERT(Ok == status);
if(Ok != status)
{
LOG(Log::DBG2, "GDI+ Initialization Failure: " << status);
return FALSE;
}
// Set the notification hooks since we are a DLL.
m_gdiplusStartupOutput.NotificationHook(&m_gdiplusHookToken);
CWinApp::InitInstance();
return TRUE;
}
Finally, write something like this in your DLL's ExitInstance:
BOOL CMyLibApp::ExitInstance()
{
// Release the GDI+ notification hook.
m_gdiplusStartupOutput.NotificationUnhook(m_gdiplusHookToken);
// Release GDI+ resources.
GdiplusShutdown(m_gdiplusToken);
CWinApp::ExitInstance();
return TRUE;
}
Hopefully that will do the trick for you.
Greg
|
|
|
|
 |
|
 |
I started using GDI+ recently; here is some code sample which describes a problem I am facing
Bitmap * m_pSelectedImage;
// Create a Bitmap object
m_pSelectedImage = Bitmap::FromStream(m_pStream);
All my drawing etc happens here
..
…
At some point, I want to DELETE that file that the stream was created from
_unlink(“Image.jpg”); FAILS with a return -1, indicating a sharing violation
BUT I if I just LOAD the file from disk, then _unlink() it, it works fine, that is if the
// Create a Bitmap object
m_pSelectedImage = Bitmap::FromStream(m_pStream);
is NOT executed, although I am trying to delete and NUL the Bitmap object before calling _unlink();
delete m_pSelectedImage;
m_pSelectedImage = NULL;
Any help will be appreciated
Cheers
Alex
|
|
|
|
 |
|
 |
1. You can try WIN32 API ::DeleteFile().
2. Normally, how you create a stream out of a file:
2.1 Open file.
2.2 Get file size.
2.3 Create memory stream based on global handle with the size.
2.4 Copy the file content into the memory stream.
2.5 CLOSE THE FILE (Or you can delete now as the file is no longer open).
2.6 ...do your stuff.
3. On heavy usage scenario:
3.1 Create a simple COM object that implement IStream.
3.2 Implement IStream using file mapping API.
3.3 After all your stuff, at FinalRelease() (or any apppropriate), close the mapped file and just delete (or whatever...) it.
4. There are several other ways to do the same, such as Shell API or even issue system command.
Good day!
|
|
|
|
 |
|
 |
Hello TW
Thanks for your explanation and details, I have resolved the problem in the mean time - the problem was in that I was creating TWO Bitmap pointers to the same file and only deleting one of them, hence the file on disk was still locked.
The way of actual deleting the file was NOT the problem (I could not even delete it while my function was executing by using Windows Explorer - it was locked by the 2nd instance of the Bitmap pointer.
Thanks again
Alex
|
|
|
|
 |
|
|
 |
|
 |
Thanks alot dude! TW... MSDN sucked big time.
|
|
|
|
 |
|
 |
Here's some quote from the GDI+ documentation in MSDN:
Purpose
Microsoft® Windows® GDI+ is a class-based application programming interface (API) for C/C++ programmers....
Developer Audience
The GDI+ C++ class-based interface is designed for use by C/C++ programmers...
Hmmm.... now can u dig that suckaaaa!
Tanzim Husain
|
|
|
|
 |
|
 |
I just came across here, and wonder why you check codeguru.com here:
http://codeguru.com/gdi/index.shtml
there are 11 C++ articles on GDI+ usage...
|
|
|
|
 |
|
|
 |
|
 |
Are you some kind of stupid? You can readn't the link in the article? Well, typical Microsoft die hard fan, blind folded programmer.
|
|
|
|
 |
|
 |
TW wrote:
Are you some kind of stupid? You can readn't the link in the article? Well, typical Microsoft die hard fan, blind folded programmer.
I read the text in the article:
GDI+ is exposed through conventional C APIs, but there's also a set of C++ classes that encapsulates its functionality. Unfortunately, the GDI+ classes are not written in the style of MFC, instead they are named with the .NET Framework conventions. Nevertheless, they can be easily used in MFC apps. To use GDI+, you have to include the gdiplus.h header file and link with gdiplus.lib. You also have to initialize the library before calling any of its functions. The GDI+ feature can be easily redistributed. GDI+ is standard on Windows XP. For Windows 98, Windows Me, Windows NT® 4.0, and Windows 2000, you can simply copy GdiPlus.DLL into your app's directory.
GDI+ uses a different programming model from GDI. Instead of selecting brushes and pens into a device context, in GDI+ you pass the pen or brush into every drawing command. Graphics elements are no longer drawn with both the pen and brush together; they are outlined and filled using separate functions (such as DrawRectangle and FillRectangle).
And the example that followed. Seemed rather easy to use, to me.
Marc
Latest AAL Article
My blog
Join my forum!
|
|
|
|
 |
|
 |
The links yields this:
Location Cannot Be Found
We apologize for the inconvenience, but the location you are seeking cannot be found. If you are looking for a particular document, please try one of the following areas:
Vaclav
|
|
|
|
 |
|
|
 |
|
 |
Thanks
|
|
|
|
 |
 | goods  |  | Anonymous | 21:21 14 Jun '03 |
|
|
 |
|
 |
This is a good introduction but rather incomplete. I would like to see in the article more details on about mixing GDI and GDI+ calls in the same drawing routine like getting a Graphics object from a CDC* and things like that!
|
|
|
|
 |
|
 |
Why are 99.9% of GDI+ samples in .NET language?
Cause that's what MS wants you to use - Doh!
C++ is for old people, with rickety minds, C# is for young, voluptuous, nubile thinkers...
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
|
|
|
|
 |
|
 |
.NET is a simple language, but for larger projects it is really a pain in the a**, you need to lots of DLLs and sub-projects for each control in order to be able to handle it.
I tried a few times to make my projects using C#, but every time I messed up in the generated code.
|
|
|
|
 |
|
 |
Mario M. wrote:
.NET is a simple language
.NET is not a language.
And C# version 2.0 will be much richer than C++.
Mario M. wrote:
but for larger projects it is really a pain in the a**, you need to lots of DLLs and sub-projects for each control in order to be able to handle it.
For each control? Could you give an example? I rarely have to deal with references, unless they're to assemblies in my own project. I've never had a problem with this.
Marc
Latest AAL Article
My blog
Join my forum!
|
|
|
|
 |