【VC开源代码栏目提醒】:以下是网学会员为您推荐的VC开源代码-gdi_testView.cpp,希望本篇文章对您学习有所帮助。
// gdi_testView.cpp : Cgdi_testView 类的实现
//
#include "stdafx.h"
#include "gdi_test.h"
#include "gdi_testDoc.h"
#include "gdi_testView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
using namespace Gdiplus;
// Cgdi_testView
IMPLEMENT_DYNCREATE(Cgdi_testView, CView)
BEGIN_MESSAGE_MAP(Cgdi_testView, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
// Cgdi_testView 构造/销毁
Cgdi_testView::Cgdi_testView()
{
// TODO: 在此处添加构造代码
}
Cgdi_testView::~Cgdi_testView()
{
}
BOOL Cgdi_testView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
// 样式
return CView::PreCreateWindow(cs);
}
// Cgdi_testView 绘制
void Cgdi_testView::OnDraw(CDC* pDC)
{
Cgdi_testDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
using namespace Gdiplus;
Graphics graphics(pDC->GetSafeHdc());
// Pen can also be constructed using a brush or another
/*Rect rect(0, 0, 50, 50);
Pen pen(Color(255, 255, 0, 0), 0);
graphics.RotateTransform(10.0f);
graphics.TranslateTransform(300.0f, 300.0f);
graphics.ScaleTransform(3.0f,2.0f);
graphics.DrawRectangle(&pen, rect);
SolidBrush blackBrush(Color(255, 0, 0, 0));
SolidBrush redBrush(Color(255, 255, 0, 0));
Point polyPoints[] = {Point(10, 10), Point(150, 10), Point(100, 75), Point(100, 150)};
GraphicsPath onePath;
onePath.AddPolygon(polyPoints, 4);
Rect rect1(20, 20,50,50);
Rect rect2(80, 80,50,50);
Region region1(rect1);
Region region2(rect2);
region1.Union(&onePath);
region2.Intersect(&onePath);
graphics.FillRegion(&blackBrush,®ion1);
graphics.FillRegion(&redBrush,®ion2);
Pen myPen(Color(255,255,0,0));
graphics.DrawEllipse(&myPen, 0, 0, 100, 50);//绘制一个没有进行坐标变换的椭圆
graphics.ScaleTransform(1.0f, 0.5f); //将Y方向缩放0.5倍。
graphics.TranslateTransform(50.0f, 0.0f, MatrixOrderAppend);//在X方向上平移50个单位。
graphics.RotateTransform(30.0f, MatrixOrderAppend); //将坐标旋转30度。
graphics.DrawEllipse(&myPen, 0, 0, 100, 50); //在进行坐标旋转之后的空间进行绘制。
// Create and set an array of real numbers.
REAL dashVals[4] = { 5.0f, 2.0f, 10.0f, 1.0f};
// 创建画笔对象
Pen pen(Color(255, 0, 0, 0), 5);
// 设置画笔的线型
pen.SetDashPattern(dashVals, 4);
// 利用自定义的线型绘制一条直线
graphics.DrawLine(&pen, 5, 20, 405, 200);
*/
/* HatchBrush hBrush(HatchStyleHorizontal, Color(255, 255, 0, 0), Color(255, 128, 255, 255));
graphics.FillEllipse(&hBrush, 0, 0, 100, 60);*/
/* LinearGradientBrush linGrBrush( Point(0, 10), Point(200, 10), Color(255, 255, 0, 0), Color(255, 0, 0, 255)); // 创建线性渐变的画刷
Pen pen(&linGrBrush);
graphics.DrawLine(&pen, 0, 10, 200, 10);
graphics.FillEllipse(&linGrBrush, 0, 30, 200, 100);*/
/* GraphicsPath path;
path.AddEllipse(0, 0, 140, 70);
// 通过路径对象创建路径渐变画刷.
PathGradientBrush pthGrBrush(&path);
//将路径的中心颜色设置为蓝色
pthGrBrush.SetCenterColor(Color(255, 0, 0, 255));
// 设置路径的边界颜色.
Color colors[] = {Color(255, 0, 255, 255)};
int count = 1;
pthGrBrush.SetSurroundColors(colors, &count);
graphics.FillEllipse(&pthGrBrush, 0, 0, 140, 70);
*/
/* Image image(L"Recolor.bmp"); //创建图像对象
ImageAttributes imageAttributes; //创建图像属性对象
UINT width = image.GetWidth();
UINT height = image.GetHeight();
ColorMap colorMap[1]; //再变换颜色表
// 再变换颜色表中被替换的颜色---不透明红色
colorMap[0].oldColor = Color(255, 255, 0, 0);
//再变换颜色表中替换成的颜色---不透明蓝色
colorMap[0].newColor = Color(255, 0, 0, 255);
//设置颜色属性
imageAttributes.SetRemapTable(1, colorMap, ColorAdjustTypeBitmap);
graphics.DrawImage(&image, 10, 10, width, height); //绘制
//使用再变换颜色表进行绘制
//graphics.DrawImage(&image, Rect(150, 10, width, height),0, 0,width,height,UnitPixel,&imageAttributes);
*/
/* Pen pen(Color(255, 255, 0, 0));
graphics.ResetTransform();
graphics.RotateTransform(30.0f); // World transformation
graphics.DrawEllipse(&pen, 30, 0, 50, 25);
graphics.SetPageUnit(UnitMillimeter); // Page transformation
graphics.DrawEllipse(&pen, 30, 0, 50, 25);
*/
Point point(60, 10);
SolidBrush solidBrush(Color());
Region region1(Rect(50, 0, 50, 150));
Region region2(Rect(0, 50, 150, 50));
// 创建两个区域的并集
region1.Union(®ion2);
if(region1.IsVisible(point, &graphics))
{
// The point is in the region. Use an opaque brush.
solidBrush.SetColor(Color(255, 255, 0, 0));
}
else
{
// The point is not in the region. Use a semitransparent brush.
solidBrush.SetColor(Color(64, 255, 0, 0));
}
graphics.FillRegion(&solidBrush, ®ion1);
/*
// 创建一个简单多边形的路径
Point polyPoints[] = {Point(10, 10), Point(150, 10), Point(100, 75), Point(100, 150)};
GraphicsPath path;
path.AddPolygon(polyPoints, 4);
// 使用路径参数创建一个区域,
Region region(&path);
// 绘制区域轮廓
Pen pen(Color(255, 0, 0, 0));
graphics.DrawPath(&pen, &path);
// 设置图形对象的剪辑区域
graphics.SetClip(®ion);
// 绘制字符串
FontFamily fontFamily(L"黑体");
Font font(&fontFamily, 36, FontStyleBold, UnitPixel);
SolidBrush solidBrush(Color(255, 255, 0, 0));
graphics.DrawString(L"一个剪辑区域", 20, &font, PointF(15, 25), &solidBrush);
graphics.DrawString(L"一个剪辑区域", 20, &font, PointF(15, 68), &solidBrush);
*/
/* WCHAR string[] = L"在一个矩形框内绘制文本字符串.";
FontFamily fontFamily(L"宋体");
Font font(&fontFamily, 12, FontStyleBold, UnitPoint);
RectF rectF(30.0f, 10.0f, 100.0f, 122.0f);
SolidBrush solidBrush(Color(255, 0, 0, 255));
graphics.DrawString(string, -1, &font, rectF, NULL, &solidBrush);
Pen pen(Color(255, 0, 0, 0));
graphics.DrawRectangle(&pen, rectF);
*/
/* WCHAR string[150] = L"\t语文\t数学\t英语\n";
wcscat(string, L"张三\t95\t88\t91\n");
wcscat(string, L"李四\t98\t84\t90\n");
wcscat(string, L"王五\t42\t76\t98\n");
wcscat(string, L"赵六\t65\t73\t92\n");
FontFamily fontFamily(L"宋体");
Font font(&fontFamily, 12, FontStyleRegular, UnitPoint);
RectF rectF(10.0f, 10.0f, 320.0f, 100.0f);
StringFormat stringFormat;
SolidBrush solidBrush(Color(255, 0, 0, 255));
REAL tabs[] = {100.0f, 80.0f, 80.0f};
stringFormat.SetTabStops(0.0f, 3, tabs);
graphics.DrawString(stri
上一篇:
gdi_testDoc.cpp
下一篇:
产品定价因素分析MBA论文:以印度移动应用程序定价分析为例