YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET

 


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


Using GDI+ with MFC or native C/VC++

 
 

Introduction

If you did a GDI+ sample query on Google, I bet you will get hundreds or thousands of URLs pointing you to a .NET free code. If you go book shop you will see dozens of books talking about GDI+. However, if you try to find information about integrating GDI+ with MFC/ATL/WTL, I bet you will find none (if you could, kindly post the URL!). So, is it impossible or so difficult that it doesn't worth using?

Findings

The answer is: Extremely easy to use GDI+ in MFC/ATL/WTL, or even straight C language. First, I have to admit I have no knowledge about .NET, I am not a fan of Microsoft .NET but rather prefer platform SDK. GDI+ IS NOT solely for .NET, if you plan to use GDI+ on Windows version lower than XP, then you would have to redistribute the GDI+ runtime (here). Don't worry, it is only 1.04 MB, not a xx MB .NET runtime.

So?

  • Add the following line to your stdafx.h
    #include <gdiplus.h>
    using namespace Gdiplus;
    #pragma comment(lib, "gdiplus.lib")
  • Intialize the GDI+ resources. Add this to your CWinApp derived class as member:
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;

    At InitInstance(), add:

    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  • Your application is ready to consume GDI+ now.
  • Upon exit, release GDI+ resources. Add the following line to ExitInstance():
    GdiplusShutdown(gdiplusToken);

As you can see, it is that simple. In general, it should be very easy to port your existing WIN32/MFC/WTL painting code into GDI+. If you ucancode.net why? Consider there is one GDI+ C++ class called RedEyeCorrection, that's right, to correct the red eyes that sometimes occur in flash photographs. If you have at least one year WIN32/MFC experiences, just follow the link here to see more.

I included a demo project to demonstrate the above. Enjoy!

GDI+ is device context handle centric, hence if you can split drawing logic aside from actual drawing code, you will have no problem in porting to GDI+. In some cases, 100 lines of drawing code can be reduced to just 5 lines with GDI+ intensive support of complex drawing exercises. This means mixing ordinary GDI with GDI+ a trivial tucancode.net.

The downloaded project is a standard MFC SDI project, if you have read it (I hope so...), you will find that it is unbelievable simple. Nearly all time, you can simply cut-n-paste source code embedded in MSDN GDI+ to try things out. One tips: if the GDI+ need to load an external file, you can just right click the image in the help and save it, then continue to use the downloaded project to continue testing.

Finally, you do need to have a copy of platform SDK to have necessary GDI+ header, library at your VC++ search path. It is not necessary for the latest version, I am using version Aug'02. GDI+ files can be extracted from CAB_11, if you do not want to install the SDK.


 

 

Copyright ?1998-2022 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net