急求一段MFC代码+解释
选修课老师要求我们交段MFC代码作为本学期的专业要求如下:1,是一段完整的代码2,每句要有注释3,要求有3页纸4,内容不限谁会啊,谢谢了本人不会MFC...
选修课老师要求我们交段MFC代码作为本学期的专业
要求如下:
1,是一段完整的代码
2,每句要有注释
3,要求有3页纸
4,内容不限
谁会啊,谢谢了
本人不会MFC 展开
要求如下:
1,是一段完整的代码
2,每句要有注释
3,要求有3页纸
4,内容不限
谁会啊,谢谢了
本人不会MFC 展开
3个回答
展开全部
是一段MFC代码吧?还有就是3页的概念怎么算呢?用A4纸5号宋体字单倍行距?这样的行么?
// GreyLryDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ImgProcess.h"
#include "GreyLryDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGreyLryDlg dialog
CGreyLryDlg::CGreyLryDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGreyLryDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGreyLryDlg)
m_fA = 1.5f;
m_fB = 32.0f;
//}}AFX_DATA_INIT
m_bDragging = FALSE;
}
void CGreyLryDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGreyLryDlg)
DDX_Text(pDX, IDC_EDIT_A, m_fA);
DDX_Text(pDX, IDC_EDIT_B, m_fB);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGreyLryDlg, CDialog)
//{{AFX_MSG_MAP(CGreyLryDlg)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_EN_KILLFOCUS(IDC_EDIT_A, OnKillfocusEditA)
ON_EN_KILLFOCUS(IDC_EDIT_B, OnKillfocusEditB)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGreyLryDlg message handlers
BOOL CGreyLryDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
pWndShow = GetDlgItem(IDC_STATIC_COORD);
pDCShow = pWndShow->GetDC();
pWndShow->GetClientRect(&m_rectShow);
// 设置接受鼠标事件的有效区域
m_rectShow.top += 45;
m_rectShow.left += 30;
m_rectShow.bottom = m_rectShow.top + 256;
m_rectShow.right = m_rectShow.left + 256;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CGreyLryDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CString str;
int x1, y1, x2, y2;
pWndShow->UpdateWindow();
pDCShow->SetBkMode(TRANSPARENT);
CPen *pPenOld, PenRed, PenBlue;
PenRed.CreatePen(PS_SOLID, 2, RGB(255,0,0));
PenBlue.CreatePen(PS_SOLID, 2, RGB(0,0,255));
// 选中当前红色画笔,并保存以前的画笔
pPenOld = pDCShow->SelectObject(&PenRed);
// 绘制坐标轴
pDCShow->MoveTo(10,0);
pDCShow->LineTo(10,281); // 垂直坐标轴
pDCShow->LineTo(300,281); // 水平水平轴
// 绘制X轴箭头
pDCShow->LineTo(290,276);
pDCShow->MoveTo(300,281);
pDCShow->LineTo(290,286);
// 绘制Y轴箭头
pDCShow->MoveTo(5,10);
pDCShow->LineTo(10,0);
pDCShow->LineTo(15,10);
// 绘制坐标值
str = "0";
pDCShow->TextOut(1, 282, str);
str = "255";
pDCShow->TextOut(266, 282, str);
pDCShow->TextOut(11, 11, str);
// 更改成蓝色画笔
pDCShow->SelectObject(&PenBlue);
// 计算直线和坐标轴的两交点坐标
if (m_fA >= 0) // 斜率大于0
{
if (((m_fA * 255 + m_fB) >= 0) && (m_fB < 255))
{
if (m_fB < 0)
{
x1 = (int) (- m_fB/m_fA + 0.5);
y1 = 0;
}
else
{
x1 = 0;
y1 = (int) (m_fB + 0.5);
}
if ((m_fA * 255 + m_fB) > 255)
{
x2 = (int) ((255- m_fB)/m_fA + 0.5);
y2 = 255;
}
else
{
x2 = 255;
y2 = (int) (255* m_fA + m_fB + 0.5);
}
}
else if(((m_fA * 255 + m_fB) < 0))
{
x1 = 0;
y1 = 0;
x2 = 255;
y2 = 0;
}
else
{
x1 = 0;
y1 = 255;
x2 = 255;
y2 = 255;
}
}
else // 斜率小于0
{
if ((m_fB > 0) && (255* m_fA + m_fB < 255))
{
if (m_fB > 255)
{
x1 = (int) ((255- m_fB)/m_fA + 0.5);
y1 = 255;
}
else
{
x1 = 0;
y1 = (int) (m_fB + 0.5);
}
if ((m_fA * 255 + m_fB) < 0)
{
x2 = (int) (- m_fB/m_fA + 0.5);
y2 = 0;
}
else
{
x2 = 255;
y2 = (int) (255* m_fA + m_fB + 0.5);
}
}
else if (m_fB <=0)
{
x1 = 0;
y1 = 0;
x2 = 255;
y2 = 0;
}
else
{
x1 = 0;
y1 = 255;
x2 = 255;
y2 = 255;
}
}
// 显示直线两端点坐标
str.Format("(%d, %d)", x1, y1);
pDCShow->TextOut(x1 + 10, 280 - y1 + 1, str);
str.Format("(%d, %d)", x2, y2);
pDCShow->TextOut(x2 + 10, 280 - y2 + 1, str);
// 绘制用户指定的线性变换直线
pDCShow->MoveTo(x1 + 10, 280 - y1);
pDCShow->LineTo(x2 + 10, 280 - y2);
// 恢复以前的画笔
pDCShow->SelectObject(pPenOld);
PenRed.DeleteObject();
PenBlue.DeleteObject();
// 绘制边框
pDCShow->MoveTo(10,25);
pDCShow->LineTo(265,25);
pDCShow->LineTo(265,281);
// Do not call CDialog::OnPaint() for painting messages
}
void CGreyLryDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_rectShow.PtInRect(point))
{
// 转换坐标
m_ptStart.x = m_ptEnd.x = point.x - m_rectShow.left + 10;
m_ptStart.y = m_ptEnd.y = point.y - m_rectShow.top + 25;
m_bDragging = TRUE;
}
CDialog::OnLButtonDown(nFlags, point);
}
void CGreyLryDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_bDragging)
{
// 判断当前光标是否在绘制区域
if (m_rectShow.PtInRect(point))
{
m_ptEnd.x = point.x - m_rectShow.left + 10;
m_ptEnd.y = point.y - m_rectShow.top + 25;
if (m_ptStart.x != m_ptEnd.x)
{
// 转换坐标
m_ptStart.x = m_ptStart.x - 10;
m_ptStart.y = 280 - m_ptStart.y;
m_ptEnd.x = m_ptEnd.x - 10;
m_ptEnd.y = 280 - m_ptEnd.y;
// 计算斜率和截距
m_fA = (float) (m_ptEnd.y - m_ptStart.y) / (m_ptEnd.x - m_ptStart.x);
m_fB = m_ptStart.y - m_fA * m_ptStart.x;
UpdateData(FALSE);
}
Invalidate();
}
else // 用户在绘制区域外放开鼠标左键
{
int nDrawModeOld = pDCShow->SetROP2(R2_NOTXORPEN); // 设置绘制方式为异或模式
CPen* pPenOld, PenNew;
PenNew.CreatePen(PS_DOT, 1, RGB(0,0,0));
pPenOld = pDCShow->SelectObject(&PenNew);
pDCShow->MoveTo(m_ptStart);
pDCShow->LineTo(m_ptEnd);
pDCShow->SelectObject(pPenOld); // 选回以前的画笔
pDCShow->SetROP2(nDrawModeOld); // 恢复成以前的绘制模式
PenNew.DeleteObject();
}
m_bDragging = FALSE; // 重置拖动状态
::ReleaseCapture(); // 释放鼠标
}
CDialog::OnLButtonUp(nFlags, point);
}
void CGreyLryDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_rectShow.PtInRect(point))
{
SetCapture(); // 捕捉鼠标
::SetCursor(::LoadCursor(NULL, IDC_CROSS));
if (m_bDragging)
{
int nDrawModeOld = pDCShow->SetROP2(R2_NOTXORPEN);
CPen* pPenOld, PenNew;
PenNew.CreatePen(PS_DOT, 1, RGB(0,0,0));
pPenOld = pDCShow->SelectObject(&PenNew);
pDCShow->MoveTo(m_ptStart);
pDCShow->LineTo(m_ptEnd);
// 转换坐标
m_ptEnd.x = point.x - m_rectShow.left + 10;
m_ptEnd.y = point.y - m_rectShow.top + 25;
// 绘制橡皮筋线
pDCShow->MoveTo(m_ptStart);
pDCShow->LineTo(m_ptEnd);
pDCShow->SelectObject(pPenOld); // 选回以前的画笔
pDCShow->SetROP2(nDrawModeOld); // 恢复成以前的绘制模式
PenNew.DeleteObject();
}
}
else
{
if (m_bDragging)
::SetCursor(::LoadCursor(NULL, IDC_NO));
else
ReleaseCapture();
}
CDialog::OnMouseMove(nFlags, point);
}
void CGreyLryDlg::OnKillfocusEditA()
{
// TODO: Add your control notification handler code here
UpdateData();
InvalidateRect(CRect(0,0,350,320));
}
void CGreyLryDlg::OnKillfocusEditB()
{
// TODO: Add your control notification handler code here
UpdateData();
InvalidateRect(CRect(0,0,350,320));
}
// GreyLryDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ImgProcess.h"
#include "GreyLryDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGreyLryDlg dialog
CGreyLryDlg::CGreyLryDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGreyLryDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGreyLryDlg)
m_fA = 1.5f;
m_fB = 32.0f;
//}}AFX_DATA_INIT
m_bDragging = FALSE;
}
void CGreyLryDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGreyLryDlg)
DDX_Text(pDX, IDC_EDIT_A, m_fA);
DDX_Text(pDX, IDC_EDIT_B, m_fB);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGreyLryDlg, CDialog)
//{{AFX_MSG_MAP(CGreyLryDlg)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_EN_KILLFOCUS(IDC_EDIT_A, OnKillfocusEditA)
ON_EN_KILLFOCUS(IDC_EDIT_B, OnKillfocusEditB)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGreyLryDlg message handlers
BOOL CGreyLryDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
pWndShow = GetDlgItem(IDC_STATIC_COORD);
pDCShow = pWndShow->GetDC();
pWndShow->GetClientRect(&m_rectShow);
// 设置接受鼠标事件的有效区域
m_rectShow.top += 45;
m_rectShow.left += 30;
m_rectShow.bottom = m_rectShow.top + 256;
m_rectShow.right = m_rectShow.left + 256;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CGreyLryDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CString str;
int x1, y1, x2, y2;
pWndShow->UpdateWindow();
pDCShow->SetBkMode(TRANSPARENT);
CPen *pPenOld, PenRed, PenBlue;
PenRed.CreatePen(PS_SOLID, 2, RGB(255,0,0));
PenBlue.CreatePen(PS_SOLID, 2, RGB(0,0,255));
// 选中当前红色画笔,并保存以前的画笔
pPenOld = pDCShow->SelectObject(&PenRed);
// 绘制坐标轴
pDCShow->MoveTo(10,0);
pDCShow->LineTo(10,281); // 垂直坐标轴
pDCShow->LineTo(300,281); // 水平水平轴
// 绘制X轴箭头
pDCShow->LineTo(290,276);
pDCShow->MoveTo(300,281);
pDCShow->LineTo(290,286);
// 绘制Y轴箭头
pDCShow->MoveTo(5,10);
pDCShow->LineTo(10,0);
pDCShow->LineTo(15,10);
// 绘制坐标值
str = "0";
pDCShow->TextOut(1, 282, str);
str = "255";
pDCShow->TextOut(266, 282, str);
pDCShow->TextOut(11, 11, str);
// 更改成蓝色画笔
pDCShow->SelectObject(&PenBlue);
// 计算直线和坐标轴的两交点坐标
if (m_fA >= 0) // 斜率大于0
{
if (((m_fA * 255 + m_fB) >= 0) && (m_fB < 255))
{
if (m_fB < 0)
{
x1 = (int) (- m_fB/m_fA + 0.5);
y1 = 0;
}
else
{
x1 = 0;
y1 = (int) (m_fB + 0.5);
}
if ((m_fA * 255 + m_fB) > 255)
{
x2 = (int) ((255- m_fB)/m_fA + 0.5);
y2 = 255;
}
else
{
x2 = 255;
y2 = (int) (255* m_fA + m_fB + 0.5);
}
}
else if(((m_fA * 255 + m_fB) < 0))
{
x1 = 0;
y1 = 0;
x2 = 255;
y2 = 0;
}
else
{
x1 = 0;
y1 = 255;
x2 = 255;
y2 = 255;
}
}
else // 斜率小于0
{
if ((m_fB > 0) && (255* m_fA + m_fB < 255))
{
if (m_fB > 255)
{
x1 = (int) ((255- m_fB)/m_fA + 0.5);
y1 = 255;
}
else
{
x1 = 0;
y1 = (int) (m_fB + 0.5);
}
if ((m_fA * 255 + m_fB) < 0)
{
x2 = (int) (- m_fB/m_fA + 0.5);
y2 = 0;
}
else
{
x2 = 255;
y2 = (int) (255* m_fA + m_fB + 0.5);
}
}
else if (m_fB <=0)
{
x1 = 0;
y1 = 0;
x2 = 255;
y2 = 0;
}
else
{
x1 = 0;
y1 = 255;
x2 = 255;
y2 = 255;
}
}
// 显示直线两端点坐标
str.Format("(%d, %d)", x1, y1);
pDCShow->TextOut(x1 + 10, 280 - y1 + 1, str);
str.Format("(%d, %d)", x2, y2);
pDCShow->TextOut(x2 + 10, 280 - y2 + 1, str);
// 绘制用户指定的线性变换直线
pDCShow->MoveTo(x1 + 10, 280 - y1);
pDCShow->LineTo(x2 + 10, 280 - y2);
// 恢复以前的画笔
pDCShow->SelectObject(pPenOld);
PenRed.DeleteObject();
PenBlue.DeleteObject();
// 绘制边框
pDCShow->MoveTo(10,25);
pDCShow->LineTo(265,25);
pDCShow->LineTo(265,281);
// Do not call CDialog::OnPaint() for painting messages
}
void CGreyLryDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_rectShow.PtInRect(point))
{
// 转换坐标
m_ptStart.x = m_ptEnd.x = point.x - m_rectShow.left + 10;
m_ptStart.y = m_ptEnd.y = point.y - m_rectShow.top + 25;
m_bDragging = TRUE;
}
CDialog::OnLButtonDown(nFlags, point);
}
void CGreyLryDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_bDragging)
{
// 判断当前光标是否在绘制区域
if (m_rectShow.PtInRect(point))
{
m_ptEnd.x = point.x - m_rectShow.left + 10;
m_ptEnd.y = point.y - m_rectShow.top + 25;
if (m_ptStart.x != m_ptEnd.x)
{
// 转换坐标
m_ptStart.x = m_ptStart.x - 10;
m_ptStart.y = 280 - m_ptStart.y;
m_ptEnd.x = m_ptEnd.x - 10;
m_ptEnd.y = 280 - m_ptEnd.y;
// 计算斜率和截距
m_fA = (float) (m_ptEnd.y - m_ptStart.y) / (m_ptEnd.x - m_ptStart.x);
m_fB = m_ptStart.y - m_fA * m_ptStart.x;
UpdateData(FALSE);
}
Invalidate();
}
else // 用户在绘制区域外放开鼠标左键
{
int nDrawModeOld = pDCShow->SetROP2(R2_NOTXORPEN); // 设置绘制方式为异或模式
CPen* pPenOld, PenNew;
PenNew.CreatePen(PS_DOT, 1, RGB(0,0,0));
pPenOld = pDCShow->SelectObject(&PenNew);
pDCShow->MoveTo(m_ptStart);
pDCShow->LineTo(m_ptEnd);
pDCShow->SelectObject(pPenOld); // 选回以前的画笔
pDCShow->SetROP2(nDrawModeOld); // 恢复成以前的绘制模式
PenNew.DeleteObject();
}
m_bDragging = FALSE; // 重置拖动状态
::ReleaseCapture(); // 释放鼠标
}
CDialog::OnLButtonUp(nFlags, point);
}
void CGreyLryDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_rectShow.PtInRect(point))
{
SetCapture(); // 捕捉鼠标
::SetCursor(::LoadCursor(NULL, IDC_CROSS));
if (m_bDragging)
{
int nDrawModeOld = pDCShow->SetROP2(R2_NOTXORPEN);
CPen* pPenOld, PenNew;
PenNew.CreatePen(PS_DOT, 1, RGB(0,0,0));
pPenOld = pDCShow->SelectObject(&PenNew);
pDCShow->MoveTo(m_ptStart);
pDCShow->LineTo(m_ptEnd);
// 转换坐标
m_ptEnd.x = point.x - m_rectShow.left + 10;
m_ptEnd.y = point.y - m_rectShow.top + 25;
// 绘制橡皮筋线
pDCShow->MoveTo(m_ptStart);
pDCShow->LineTo(m_ptEnd);
pDCShow->SelectObject(pPenOld); // 选回以前的画笔
pDCShow->SetROP2(nDrawModeOld); // 恢复成以前的绘制模式
PenNew.DeleteObject();
}
}
else
{
if (m_bDragging)
::SetCursor(::LoadCursor(NULL, IDC_NO));
else
ReleaseCapture();
}
CDialog::OnMouseMove(nFlags, point);
}
void CGreyLryDlg::OnKillfocusEditA()
{
// TODO: Add your control notification handler code here
UpdateData();
InvalidateRect(CRect(0,0,350,320));
}
void CGreyLryDlg::OnKillfocusEditB()
{
// TODO: Add your control notification handler code here
UpdateData();
InvalidateRect(CRect(0,0,350,320));
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询