VC++报告有截图Word格式.docx

上传人:b****7 文档编号:22227311 上传时间:2023-02-03 格式:DOCX 页数:26 大小:698.26KB
下载 相关 举报
VC++报告有截图Word格式.docx_第1页
第1页 / 共26页
VC++报告有截图Word格式.docx_第2页
第2页 / 共26页
VC++报告有截图Word格式.docx_第3页
第3页 / 共26页
VC++报告有截图Word格式.docx_第4页
第4页 / 共26页
VC++报告有截图Word格式.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

VC++报告有截图Word格式.docx

《VC++报告有截图Word格式.docx》由会员分享,可在线阅读,更多相关《VC++报告有截图Word格式.docx(26页珍藏版)》请在冰豆网上搜索。

VC++报告有截图Word格式.docx

了解MFC支持的三种动态链接库:

Win32DLL,MFC常规DLL,MFC扩展库。

掌握封装DLL的基本方法。

二、综合题:

6.卡拉OK点歌管理系统

在本地硬盘库里存放歌曲文件(暂定WAV文件格式)。

按照歌手,歌名(字数),类别进行检索播放。

对歌曲库可以进行管理,如添加,删除等。

计时计费功能。

基本步骤:

实验环境

VC++6.0

Access

实验步骤

基础题

设计一:

改错

程序说明:

本题是一道改错题,根据已经给出的例程1进行改错及完善的操作。

关键问题在于需要素数的存储,该题所给是数组,属于静态分配,最好改为动态的。

本题的主要目的是熟悉VC的编译环境,为下面的题目做铺垫。

程序修改如下:

调试结果如下:

设计二:

数据库连接

本题是使用ACCESS数据库存储学生信息,利用ODBC将MFC界面与ACCESS数据库连接起来,从而可以在可视化界面上显示数据内容并完成查询、添加、编辑和删除的功能。

查询功能是通过将用户输入的文本信息取出,并在数据库中检索对应字段的信息,若检索成功,则在界面上显示相对应的学生信息,否则提示无此学生信息。

添加和编辑都需要使用新的对话框,通过将新对话框中文本框的内容存入数据库学生表中,以实现添加或对现有数据的编辑功能。

删除功能和显示功能大致相同,由于数据是绑定的,无需全表字段检索,很容易实现对指定记录的删除操作。

设计流程图:

调试结果:

程序(查询,添加,删除):

voidCMy2ODBCView:

:

OnBUTTONquery()//查找

{

UpdateData();

//把控件的内容赋给当前记录字段变量

m_strQuery.TrimLeft();

//从左取数

if(m_strQuery.IsEmpty())

{

MessageBox("

Thenumbercannotbeempty!

"

);

//

return;

}

if(m_pSet->

IsOpen())//如果记录集打开,则先关闭

m_pSet->

Close();

m_pSet->

m_strFilter.Format("

studentno=%s"

m_strQuery);

//指定查询条件

m_strSort="

ssex"

;

//按性别小到大排序

Open();

if(!

m_pSet->

IsEOF())//如果打开记录集,有记录(指针不指向队尾)

UpdateData(FALSE);

//自动更新表中控件显示的内容

else

Norecords!

//TODO:

Addyourcontrolnotificationhandlercodehere

}

OnButton1()//增加记录

ADDdlg;

//弹出ADD类窗口

if(dlg.DoModal()==IDOK)//如果弹出并选中“OK”

{

m_pSet->

AddNew();

//队尾增加新记录

m_studentno=dlg.m_sno;

m_ssex=dlg.m_sex;

m_sage=dlg.m_age;

m_saddress=dlg.m_ad;

m_stel=dlg.m_tel;

m_smail=dlg.m_mail;

m_shobby=dlg.m_hobby;

m_sname=dlg.m_name;

Update();

//更新数据

Requery();

//对快照模式有效

//TODO:

OnButton3()//修改

//已下展现旧数据

dlg.m_sno=m_pSet->

m_studentno;

dlg.m_sex=m_pSet->

m_ssex;

dlg.m_age=m_pSet->

m_sage;

dlg.m_ad=m_pSet->

m_saddress;

dlg.m_tel=m_pSet->

m_stel;

dlg.m_mail=m_pSet->

m_smail;

dlg.m_hobby=m_pSet->

m_shobby;

dlg.m_name=m_pSet->

m_sname;

if(dlg.DoModal()==IDOK)//更新

Edit();

}

OnButton2()//删除

CRecordsetStatusstatus;

//结构体状态,记录号、记录总数

GetStatus(status);

//获得当前记录结构体状态信息

Delete();

if(status.m_lCurrentRecord==0)

MoveNext();

MoveFirst();

UpdateData(FALSE);

设计三:

图形编辑

本题是使用MFC实现在界面上绘图的功能,提供一个图形工具界面,让用户能够画出直线,椭圆,多边形等几何元素,结果可以保存并可读出。

关键问题是确定用户选择的图形类型,从而可以调用相应的类库,并将类实例化之后使用其中各种绘图函数。

同时需要记录用户鼠标点击的操作,获取鼠标指针当前的屏幕坐标,确定图形的起始位置和结束位置。

流程

编译结果:

程序:

voidCMy4drawView:

OnLButtonDown(UINTnFlags,CPointpoint)

Addyourmessagehandlercodehereand/orcalldefault

CView:

OnLButtonDown(nFlags,point);

//鼠标动作

m_ptOrigin=point;

//设置起始坐标

on=1;

//按键按下判定字

}

OnLButtonUp(UINTnFlags,CPointpoint)

CClientDCpDC(this);

//客户区绘图函数

if(getshape()==2)//矩形

pDC.SelectStockObject(HOLLOW_BRUSH);

CPenPen(PS_SOLID,1,getcolour());

//创建画笔

pDC.SelectObject(&

Pen);

pDC.Rectangle(m_ptOrigin.x,m_ptOrigin.y,point.x,point.y);

Pen.DeleteObject();

elseif(getshape()==4)

CPenPen(PS_SOLID,1,getcolour());

pDC.Ellipse(m_ptOrigin.x,m_ptOrigin.y,point.x,point.y);

elseif(getshape()==3)

doubler=pow((point.x-m_ptOrigin.x)*(point.x-m_ptOrigin.x)+(point.y-m_ptOrigin.y)*(point.y-m_ptOrigin.y),0.5);

CPointm=point+m_ptOrigin;

m.x/=2;

m.y/=2;

pDC.Ellipse(m.x-r,m.y-r,m.x+r,m.y+r);

elseif(getshape()==1)

pDC.SelectObject(&

pDC.MoveTo(m_ptOrigin);

pDC.LineTo(point.x,point.y);

Pen.DeleteObject();

on=0;

Addyourmessagehandlercodehereand/orcalldefault

OnLButtonUp(nFlags,point);

//定义形参,跨类传递数值colour,width,kind,shape

intCMy4drawView:

getcolour(){CMainFramea;

returna.colour;

doubleCMy4drawView:

getwidth(){CMainFramea;

returna.width;

getkind(){CMainFramea;

returna.kind;

getshape(){CMainFramea;

returna.shape;

OnMouseMove(UINTnFlags,CPointpoint)

CMy4drawDoc*p=GetDocument();

if(getkind()==1)

HCURSORhCursor=SetCursor(AfxGetApp()->

LoadCursor(IDC_CURSOR_pencil));

//设定不同功能对应的光标

elseif(getkind()==2)

LoadCursor(IDC_CURSOR_rubber));

elseif(getkind()==0)

HCURSORhCursor=SetCursor(LoadCursor(NULL,IDC_CROSS));

if(getkind()==1&

&

on==1)

CPennewPen(PS_SOLID,getwidth(),getcolour());

CPen*old=pDC.SelectObject(&

newPen);

pDC.MoveTo(m_ptOrigin);

elseif(getkind()==2&

intclr=RGB(255,255,255);

CPennewpen(PS_SOLID,getwidth()+5,clr);

CPen*oldpen=pDC.SelectObject(&

newpen);

elseif(getshape()==2&

pDC.SetROP2(R2_NOT);

//width=1only!

elseif(getshape()==4&

elseif(getshape()==3&

on==1)//圆

inta=(m_ptOrigin.x)<

(m_ptOrigin.y)?

m_ptOrigin.y:

m_ptOrigin.x;

intb=(point.x)>

(point.y)?

point.y:

point.x;

intc=(point.x)>

doubler0=pow((m_ptOrigin.x-point.x)*(m_ptOrigin.x-point.x)+(m_ptOrigin.y-point.y)*(m_ptOrigin.y-point.y),0.5);

//#include<

math.h>

!

CPointm0=m_ptOrigin+point;

m0.x/=2;

m0.y/=2;

pDC.Ellipse(m0.x-r0,m0.y-r0,m0.x+r0,m0.y+r0);

elseif(getshape()==1&

pDC.SetROP2(R2_NOT);

pDC.LineTo(point);

OnMouseMove(nFlags,point);

设计四:

字符串的操作

voidresult:

OnOK()

//打开文档//

CFileDialogfiledlg(true);

filedlg.m_ofn.lpstrTitle="

OpenText"

filedlg.m_ofn.lpstrFilter="

TextFile(*.txt)\0*.txt\0AllFiles(*.*)\0*.*\0\0"

if(filedlg.DoModal()==IDOK)

CFilefile(filedlg.GetFileName(),CFile:

modeRead);

staticchar*str;

DWORDdword;

dword=file.GetLength();

str=newchar[dword+1];

str[dword]=0;

file.Read(str,dword);

//读取内容//

file.Close();

lenght=dword;

buf=str;

/////////////////////////////////////////////////////////////////////////////

开始计数

total=0;

cwords=0;

ewords=0;

boolisWord=true;

for(inti=0;

i<

lenght;

i++)

if(buf[i]==0x20)

{

isWord=true;

}

elseif(buf[i]>

'

A'

&

buf[i]<

z'

total++;

if(isWord)

{

isWord=false;

ewords++;

}

elseif(buf[i]>

='

0'

buf[i]<

9'

{

total++;

elseif(buf[i]<

0)

cwords++;

isWord=true;

//更新对话框结果//

m_t=total+cwords/2;

m_c=cwords/2;

m_e=ewords;

MessageBox(buf,"

Result"

//显示文本

测试结果:

设计五:

动态链接

Win32,MFC,MFC扩展

了解MFC支持的三种动态链接库:

Win32DLL,MFC常规DLL,MFC扩展库。

步骤:

新建三个不同的DLL工程;

分别封装一些类和函数;

新建一个测试工程对上述库里的函数或类进行调用;

封装一个对话框类到DLL,并新建一个工程调用之。

#include"

.\extendll\dlgext.h"

//主程序

extern"

C"

_declspec(dllexport)intDisplay(inti);

_declspec(dllexport)intSum(inti);

voidCTestdllDlg:

OnButton1()//ExtensionDLL

CDlgExtdlg;

dlg.DoModal();

OnButton2()//NormalDLL

UpdateData();

m_out.Format("

%d"

Display(m_i));

OnButton3()//Win32DLL

UpdateData(TRUE);

m_so=Sum(m_si);

Win32代码:

STDAPIDllUnregisterServer(void)

return_Module.UnregisterServer(TRUE);

_declspec(dllexport)intSum(inti)

intm=0;

for(intj=0;

j<

=i;

j++)

m+=j;

returnm;

//NormalDLL

CRegularDllApptheApp;

_declspec(dllexport)intDisplay(inti)

intm=1;

for(intj=2;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 育儿知识

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1