MFC学习笔记

本文是关于MFC的二维变化实验的学习笔记,详细介绍了如何在Visual Studio 2013环境下添加类(如CPoint2、CRGB、CALine等)、实现图形绘制、添加图标响应程序的步骤,包括类向导的使用、函数的添加以及响应函数的编写。同时提醒注意不同版本VS中类文件名的处理和命名规范。
摘要由CSDN通过智能技术生成

MFC 二维变化实验**

注:本人使用为2013版本VS
版本不同会导致有些内在文件不同,可根据自己版本进行更改
#今日收获
1、了解了添加类的方法
2、学习了使用类向导添加命令或者实验
3、学会了添加图标相应

第一步:添加类

1、首先我们要进行二维变化的前提是要进行图形的绘制,所以我们要添加如下三个类。
CPoint2、CRGB、CALine
具体步骤:
类向导->添加类-类名称
在13版本中会直接将.h和.cpp 文件前的C去掉,但是在更高的版本如19版本中则需要手动删除.h和.cpp前的C
代码如下:
RGB.h

#pragma once
class CRGB
{
   
public:
	CRGB();
	~CRGB();
	CRGB(double red, double green, double blue, double alpha = 0.0);
	void Normalize();
	friend CRGB operator*(double scalar, const CRGB &c);
	friend CRGB operator+(const CRGB &c0, const CRGB &c1);
	friend CRGB operator-(const CRGB &c0, const CRGB &c1);
	double red;
	double green;
	double blue;
	double alpha;
};

RGB.cpp

#include "RGB.h"


CRGB::~CRGB()
{
   
}

CRGB::CRGB()
{
   
	red = 1.0;
	green = 1.0;
	blue = 1.0;
	alpha = 1.0;
}
CRGB::CRGB(double red, double green, double blue, double alpha)
{
   
	this->red = red;
	this->green = green;
	this->blue = blue;
	this->alpha = alpha;
}
void CRGB::Normalize()
{
   
	red = (red < 0.0) ? 0.0 : ((red > 1.0) ? 1.0 : red);
	green = (green < 0.0) ? 0.0 : ((green > 1.0) ? 1.0 : green);
	blue = (blue < 0.0) ? 0.0 : ((blue > 1.0) ? 1.0 : blue);
}
CRGB operator *(double scalar, const CRGB &c)
{
   
	CRGB color;
	color.red = scalar * c.red;
	color.green = scalar * c.green;
	color.blue = scalar * c.blue;
	return color;
}
CRGB operator+(const CRGB &c0, const CRGB &c1)
{
   
	CRGB color;
	color.red = c0.red + c1.red;
	color.green = c0.green + c1.green;
	color.blue = c0.blue + c1.blue;
	return color;
}
CRGB operator-(const CRGB &c0, const CRGB &c1)
{
   
	CRGB color;
	color.red = c0.red - c1.red;
	color.green = c0.green - c1.green;
	color.blue = c0.blue - c1.blue;
	return color;
}


Point2.h

#include "RGB.h"
class CPoint2
{
   
public:
	CPoint2();
	~CPoint2();
	CPoint2(int x, int y);
	CPoint2(int x, int y, CRGB c);
	int x, y;
	CRGB c;
};

Point2.cpp

#include "Point2.h"

CPoint2::~CPoint2()
{
   
}
CPoint2::CPoint2()
{
   
	x = 0;
	y = 0;
	c = CRGB(0.0, 0.0, 0.0);
}
CPoint2::CPoint2(int x, int y)
{
   
	this->x = x;
	this->y = y;

}
CPoint2::CPoint2(int x, int y, CRGB c)
{
   
	this->x = x;
	this->y = y;
	this->c = c;
}

ALine.h

#pragma once
#include "stdafx.h"
#include "Point2.h"

class CALine
{
   
public:
	CALine();
	~CALine();
	void MoveTo(CDC* pDC, CPoint2 p0);
	void MoveTo(CDC* pDC, int x, int y, CRGB c0);
	void LineTo(CDC* pDC, CPoint2 p1);
	void LineTo(CDC* pDC, int x, int y, CRGB c1);
	CRGB LinearInterp(double t, double tStart, double tEnd, CRGB cStart, CRGB cEnd);
private:
	CPoint2 P0;
	CPoint2 P1;
};

ALine.cpp

#include "ALine.h"
#include"RGB.h"
#define COLOR(c) int(RGB(c.red*255,c.green*255,c.blue*255))
CALine::CALine()
{
   
}
CALine::~CALine()
{
   
	this
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值