Home:
www.maxss.net
Email:
MAXSS.NET@163.com
GDI is a new generation of graphics equipment interfaces launched by Microsoft, which is powerful. It is no longer like traditional GDI to be seriously frustrated, GDI has many new features (such as supporting alpha, gradient filling, anti-aliasing, etc.), and has object-oriented characteristics, which makes developers more convenient and more image. GDI development. For more detailed introduction to GDI , you can check the columns in MSDN.
However, currently use GDI in the BCB environment requires certain settings and steps to successfully compile and link. I will make a brief description with BCB6 as an example:
1. Establish a compiled link environment: GDI is mainly called through gdiplus.dll, and BCB does not directly provide a static link library corresponding to GDIPLUS.DLL, so we need to build it yourself. If you don't find file gdiplus.dll in your own computer, you can download it to Microsoft's official website. Then copy a copy into its own engineering directory, then use the tool Implib supplied by BCB to generate a corresponding static link library: IMPLIB GDIPLUS.LIB GDIPLUS.DLL Remember to add GDIPLUS.LIB to the project (using BCB "Project -> Add to project ... "command). (Note: These two articles need to be saved in the project directory)
2, modify compilation options: Open the BCB menu "Project-> Options", click the "Directories / Conditionals" page, add a "strict" compile option in "Condition Defines:", if there are multiple semicolons, " Separate.
3, add the following in the .cpp file "#pragma hdrstop" Add: #include
4, the statement block "#pragma package (smart_init) in .CPP file" #pragma package (smart_init) Add the following: Using NameSpace Gdiplus; (see the source code example after)
5, finally pay attention to introducing GDI header files in .h file: #include
6. Now you can develop GDI -based development. Below is an example of a simple animation effect that I have a rotating square: (Note: You need to add a Timer control and set its interval property to 50)
Unit1.h:
/ / -------------------------------------------------------------------------------------------- ---------------------------
#ifndef unit1h
#define unit1h
/ / -------------------------------------------------------------------------------------------- ---------------------------
#include
/ / -------------------------------------------------------------------------------------------- --------------------------- Class TFORM1: Public TFORM
{
__published: // Ide-management Components
TTIMER * TIMER1;
Void __fastcall time1timer (TOBJECT * Sender);
PRIVATE: // user declarations
GDIPLUS :: GDIPLUSSTARTUPINPUT GDIPLUSSTARTUPINPUT
Ulong_ptr gdiplustoken;
Public: // user declarations
__fastcall tform1 (tComponent * Owner);
__fastcall ~ tform1 (void);
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
Extern package tform1 * form1;
/ / -------------------------------------------------------------------------------------------- ---------------------------
#ENDIF
Unit1.cpp:
/ / -------------------------------------------------------------------------------------------- ---------------------------
#include
#pragma HDRSTOP
#include
Using std :: min;
Using std :: max;
#include "unit1.h"
/ / -------------------------------------------------------------------------------------------- ---------------------------
#pragma package (smart_init)
#pragma resource "* .dfm"
TFORM1 * FORM1;
Using namespace gdiplus;
/ / -------------------------------------------------------------------------------------------- ---------------------------
__fastcall tform1 :: tform1 (tComponent * Owner)
: TFORM (OWNER)
{
Doublebuffered = true;
// Initialize GDI
GDIPLUSSTARTUP (& gdiplustoken, & gdiplusstartupinput, null);
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
__fastcall tform1 :: ~ tform1 ()
{
// Closed GDI
GDIPLUSSHUTDOWN (GDIPLUSTOKEN);
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
Void __fastcall tform1 :: Timer1Timer (TOBJECT * SENDER)
{
Const static int ox = 200, io = 200;
Const Static Real C = 140;
Const Static Real Pi = 3.14;
STATIC real offset = 0;
Point P [4]; Real K [4];
/ / Generate a new coordinate value of a positive form
For (int i = 0; i <4; i )
{
K [I] = OFFSET (PI / 2) * i;
P [I] .x = (int) OX C * SIN (K [I]);
p [i] .y = (int) OY C * COS (k [i]);
}
GDIPLUS :: Graphics G (Canvas-> Handle);
g.setsmoothingmode (smoothingmodehighquaalog); // high quality, low speed
/ / Re-filled background
Solidbrush Brush (Color :: Color (0, 0));
Pen Pen (Color :: Color (255, 255, 0), 3);
G. FillRectangle (& Brush, 0, 0, ClientWidth, ClientHeight);
GDIPLUS :: Point Point1 (p [0] .x, p [0] .y);
GDIPLUS :: Point Point2 (p [1] .x, p [1] .y);
GDIPLUS :: Point Point3 (p [2] .x, p [2] .y);
GDIPLUS :: Point Point4 (p [3] .x, p [3] .y);
GDIPLUS :: Point Point5 (p [0] .x, p [0] .y);
// Square in the new coordinate painting
GDIPLUS :: Point Points [] = {Point1, Point2, Point3, Point4, Point5};
g.drawlines (& Pen, Points, 5);
OFFSET = 0.1;
}
/ / -------------------------------------------------------------------------------------------- ---------------------------