首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

关于GDI+画线.闪的厉害,该如何处理

2012-02-26 
关于GDI+画线.闪的厉害用GDI+画的一线条//------------------------------------#ifndefuMainH#defineuMai

关于GDI+画线.闪的厉害
用GDI+画的一线条
//------------------------------------


#ifndef   uMainH
#define   uMainH
//---------------------------------------
#include   <Classes.hpp>
#include   <Controls.hpp>
#include   <StdCtrls.hpp>
#include   <Forms.hpp>

#include   <math.hpp>
#include   <Menus.hpp>
#include   <ExtCtrls.hpp>
#include   <algorithm>
using   std::min;
using   std::max;
#include   <gdiPlus.h>
using   namespace   Gdiplus;

//---------------------------------------
class   TfrmMain   :   public   TForm
{
__published://   IDE-managed   Components
    TTimer   *Timer1;
    void   __fastcall   FormMouseMove(TObject   *Sender,   TShiftState   Shift,   int   X,
                    int   Y);
private://   User   declarations
        ULONG_PTR   m_GdiplusToken;
        Gdiplus::GdiplusStartupInput   m_GdiplusStartupInput;

public://   User   declarations
        __fastcall   TfrmMain(TComponent*   Owner);
        __fastcall   ~TfrmMain(void);
};
//---------------------------------------
extern   PACKAGE   TfrmMain   *frmMain;
//---------------------------------------
#endif


cpp
#include   <vcl.h>
#include   "math.h "
#pragma   hdrstop
#include   "uMain.h "

//---------------------------------------
#pragma   package(smart_init)
#pragma   resource   "*.dfm "
TfrmMain   *frmMain;

//---------------------------------------
__fastcall   TfrmMain::TfrmMain(TComponent*   Owner)
                :   TForm(Owner)
{
        //   init   GDI+
        GdiplusStartup(&m_GdiplusToken,   &m_GdiplusStartupInput,   NULL);
        //
}
//---------------------------------------
__fastcall   TfrmMain::~TfrmMain(void)
{
        GdiplusShutdown(m_GdiplusToken);   //   Close   GDI+
}
//---------------------------------------


void   __fastcall   TfrmMain::FormMouseMove(TObject   *Sender,   TShiftState   Shift,
            int   X,   int   Y)
{
                  const   static   int   OX   =   0,   OY   =   0;
const   static   REAL   C   =   140;

static   REAL   offset   =   0;
POINT   p[4];
REAL   k[4];

//   生成正文形四角的新坐标值
for   (int   i=0;   i   <   2;   i++)
{
      p[i].x   =   (int)(OX+X)   ;
p[i].y   =   (int)(OY+i*250);


}
Gdiplus::Graphics   g(Canvas-> Handle);
g.SetSmoothingMode(SmoothingModeHighQuality);   //高画质、低速
  //   重新填充背景
SolidBrush   brush(Color::Color(1,1,1));
Pen   pen(Color::Color(255,   0,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);
    Gdiplus::Point   points[]   =   {point1,   point2,   point3,   point4,   point5};
g.DrawLines(&pen,   points,   2);

}

随鼠标拖动,,很闪
帮我看看哦


[解决办法]
加一句Form1-> DoubleBuffer=true;
[解决办法]
帮顶

热点排行