汇编语言课程设计编写记事本样本.docx

上传人:b****1 文档编号:15113696 上传时间:2023-06-30 格式:DOCX 页数:35 大小:49.48KB
下载 相关 举报
汇编语言课程设计编写记事本样本.docx_第1页
第1页 / 共35页
汇编语言课程设计编写记事本样本.docx_第2页
第2页 / 共35页
汇编语言课程设计编写记事本样本.docx_第3页
第3页 / 共35页
汇编语言课程设计编写记事本样本.docx_第4页
第4页 / 共35页
汇编语言课程设计编写记事本样本.docx_第5页
第5页 / 共35页
汇编语言课程设计编写记事本样本.docx_第6页
第6页 / 共35页
汇编语言课程设计编写记事本样本.docx_第7页
第7页 / 共35页
汇编语言课程设计编写记事本样本.docx_第8页
第8页 / 共35页
汇编语言课程设计编写记事本样本.docx_第9页
第9页 / 共35页
汇编语言课程设计编写记事本样本.docx_第10页
第10页 / 共35页
汇编语言课程设计编写记事本样本.docx_第11页
第11页 / 共35页
汇编语言课程设计编写记事本样本.docx_第12页
第12页 / 共35页
汇编语言课程设计编写记事本样本.docx_第13页
第13页 / 共35页
汇编语言课程设计编写记事本样本.docx_第14页
第14页 / 共35页
汇编语言课程设计编写记事本样本.docx_第15页
第15页 / 共35页
汇编语言课程设计编写记事本样本.docx_第16页
第16页 / 共35页
汇编语言课程设计编写记事本样本.docx_第17页
第17页 / 共35页
汇编语言课程设计编写记事本样本.docx_第18页
第18页 / 共35页
汇编语言课程设计编写记事本样本.docx_第19页
第19页 / 共35页
汇编语言课程设计编写记事本样本.docx_第20页
第20页 / 共35页
亲,该文档总共35页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

汇编语言课程设计编写记事本样本.docx

《汇编语言课程设计编写记事本样本.docx》由会员分享,可在线阅读,更多相关《汇编语言课程设计编写记事本样本.docx(35页珍藏版)》请在冰点文库上搜索。

汇编语言课程设计编写记事本样本.docx

汇编语言课程设计编写记事本样本

华北科技学院

课程设计说明书

课程名称:

汇编语言

 

班级:

机B08-1

姓名:

李鹏飞

 

 

学号:

设计题目:

Win32编写记事本

设计时间:

_6月23日至

指导教师:

一杜杏菁

评语:

评阅成绩:

—评阅教师:

一・课程设计目的

进行程序设计方法和技能的基本训练,巩固在课堂上学到的有关程序设计的基本知识和基本方法,经过实际动手能力的培养,进一步熟悉汇编语言的结构和使用方法,达到能独立阅读.编制和调试一定规模的汇编语言程序的水平。

2.课程设计要求

1.要求编写并调试经过一个小型软件,实现对软件或硬件的操作。

2.遵循模块化、结构化的程序设计方法。

3•要求程序必须正确。

4•程序简明易懂,多运用输入输出提示,出错信息及必要的注释。

5.要求程序结构合理,语句使用得当。

6•适当追求编程技巧和程序运行效率。

3.课程设计题目:

Win32编写记事本

4.课题分析

WINDOW记事本的编写,要求能实现基本菜单框架并打开窗

口,有能力的同学能够编写进行数据录入并保存的代码

五、流程图:

6.程序源代码:

.386

.modelflat^stdcall

optioncasemap:

none

includewindows.inc

includeuser32.inc

includelibuser32.1ib

includelib

kernel32.1ib

include

shell32.inc

includelibshell32.1ib

includecomctl32.inc

includelib

comctl32.1ib

include

comdlg32.inc

includelib

comdlg32.1ib

ICO_MAIN

EQUlOOOh

;图标

IDM_MAIN

EQUh

;菜单

IDA_MAIN

EQUh

;加速键

IDM_NEW

EQU2101h

;新建

IDM_OPEN

EQU2102h

;打开

IDM_SAVE

EQU2103h

保存

IDM_SAVEASEQU2104h

;另存为

IDM_EXIT

EQU2105h

;退出

IDM_UNDO

EQU220lh

;撤销

IDM_CUT

EQU2203h

;剪切

IDM_COPY

EQU2204h

;复制

IDM_PASTE

EQU2205h

;粘贴

IDM_DELETEEQU2206h

;删除

IDM_FIND

EQU2207h

渣找

IDM_REPLACEEQU220Ah

;替换

IDM_SELECTALL

EQU220Bh

;全选

IDM_FONTEQU

230lh;字体

IDM_STATUSBAR

EQU240lh

;状态栏

IDM_HELPEQU

250lh;帮助主题

IDM_ABOUTEQU2502h;关于

IDM_MENUHELP

EQU260lh

;菜单信息

.data?

hlnstancedd?

hWinMaindd?

hMenudd?

hWinStatus

dd?

hWinEditdd?

hFiledd?

hFindDialog

dd?

hRichEditdd?

dwFontColor

dd?

idFindMessage

dd?

stFindFINDREPLACE

>

szFindText

db100dup(?

szReplaceText

dblOOdup(?

szFileName

dbMAX_PATHdup(?

dwOption

dd?

.data

F_STATUSBARequOOOOOOO1h

dllEdit

dbHRichEd20.dlF\0

eixTitle

db“错误”,0

noRichEdit

db”无法找到RichEd20.dll”

className

db"TextEditor",0

captionMain

db”文本编辑器“,0

classEdit

dbuRichEdit20AM,0

fontFace

dbnFixedsys",0

modify

db“你已经改动过啦,要不要存一下?

“,0

filter

db”文本文件0.txt)”,0,叱.txt”,0,”所有文件”,0,”*尹,0,0

defExt

dbntxtn,0

titleFormat

db”%s・我的记事本“,0

errCreateFiledlT咦!

出现i可题了!

蔦0

eirOpenFile

db”咦!

怎么打不开!

”,0

notFound

db“不给力啊,找不到!

”,0

noName

db”还没起名字“,0

timeFormat

db”%02d:

%02d:

%02d”,0

charsFormat

db”字节数:

%dM,0

lineFormat

db”行:

%d”,0

colFormat

db“列:

%d”,0

helpTitledb”帮助”,0

helpTextdb"Sorry!

无法提供任何帮助”,0

aboutTitledb“关于记事本”,0

aboutTextdb“我的记事本”,0ah,0dh,“作者:

李鹏飞”,0ah,0dh,”07

月0旧“,0ah,0dh,0

dwStatusWidthdd100,200,300,400,-1

dwMenuHelpdd0,IDM_MENUHELP,0,0

FINDMSGSTRINGdbucommdlg_FindReplacen,0

.code

_CheckModifyStatePROC

invokeSendMessage,hWinEdit,EM_GETMODIFY,0,0

;获取控件内容是否改变的信息

.ifeax!

=0

invokeMessageBox,hWinMain,addrmodify,addrcaptionMain,\

MB_YESNOCANCELorMBJCONQUESTION

・ifeax=IDYES

callSaveFile

有待改动

.elseifeax==IDCANCEL

moveax,FALSE

ret

.endif

.endif

moveax,TRUEret

_CheckModifyStateENDP

;Richedit的流出操作

_StreamProcOutPROCusesebxediesi

_dwCookie,lpBuffer,NumBytes,pBytes

invokeWriteFile,hFile,lpBuffer,NumBytes,pBytes,0

xoreax,l

;如果ReadFile或WriteFile返回1(成功),则最终eax返回0,说明操作成功

ret

_StreamProcOutENDP

Richedit的流入操作

_StreamProcInPROCusesebxediesi

_dwCookie,lpBuffer,NumBytes,pBytes

invokeReadFile,hFile,lpBuffer,NumBytes,pBytes,0

xoreax,l

;如果ReadFile或WriteFile返回1(成功),则最终eax返回0,说明操作成功

ret

_StreamProcInENDP

;设置字体和字体的颜色

_SetFontPROC_lpszFont,_dwFontSize,_dwColor

local@stCf:

CHARFORMAT

invokeRtlZeroMemory.addr@stCf,sizeof@stCf

;开始填充stCf结构

mov@stCf.cbSize,sizeof@stCf

mov@stCf.dwMask,CFM_SIZEorCFM_FACEor

CFM.BOLDorCFM_COLOR;字段掩码,用来指定结构中哪些

字段是有效的

push_dwFontSize

pop@stCf.yHeight

push_dwColor

pop@stCf.crTextColor

mov@stCf.dwEffects,0

invokelstrcpy.addr@stCf.szFaceName,_lpszFont

invokeSendMessage,hWinEdit,EM_SETTEXTMODE,l,0

;设置工作模式

invoke

SendMessage,hWinEdit,EM_SETCHARFORMAT,SCF_ALL,addr

@stCf;为控件中的全部文本设置指定的格式

ret

_SetFontENDP

;查找文字

_FindTextPROC

local@stFindText:

FINDTEXTEX

;设置查找区域

invokeSendMessage,hWinEdit,EM_EXGETSEL,O,addr@stFindText.chrg

.ifstFind.Flags&FR_DOWN

;向下查找

push@stFindText.chrg.cpMax

pop©stFindText.chrg.cpMin

;将这个选择区域的结束位置用做下一次查找的起始点

.endif

mov@stFindText.chrg.cpMax,-l

;—直查找到全部文本的最后

;设置查找选项

mov@stFindText.lpstrText,offsetszFindText

movecx,stFind.Flags

andecx,FR_MATCHCASEorFR_DOWNor

FR_WHOLEWORD

;查找并把光标设置到找到的文本上

invokeSendMessage,hWinEdit,EM_FINDTEXTEX,ecx,addr

@stFindText;ecx中存储的是搜索选项

.ifeax==-1

movecx,hWinMain

.ifhFindDialog

movecx,hFindDialog

.endif

invokeMessageBox,ecx,addrnotFound,NULL,MB_OKor

MBJCONINFORMATION

.endif

我到文本以后,文本的位置在FINDTEXTEX结构的

chrgText字段中返回,chrgText字段是一个CHARRANGE结构,直接

在EM_EXSETSEL消息中使用它将选择区域设置到找到的文字上

invokeSendMessage,hWinEdit,EM_EXSETSEL,O,addr@stFindText.chrgText

invoke

SendMessage,hWinEdit,EM_SCROLLCARET,NULL,NULL

;卷动文字,以便找到的文本能够出现在用户的视野中

ret

_FindTextENDP

;保存文件,如果没有打开或创立文件则另存为

_SaveFilePROC

local@stES:

EDITSTREAM

.if!

hFile

call_SaveAs

.if!

eax

ret

.endif

.endif

mov@stES.dwCookie,FALSE

;在Richedit的流操作中写文件

mov@stES.dwEnor,NULL

mov@stES.pfnCallback,offset_StreamProcOut

;回调函数

invoke

SendMessage,hWinEdit,EM_STREAMOUT,SF_TEXT,addr

@stES;流出操作,文本格式是简单的文本格式

invokeSendMessage,hWinEdit,EM_SETMODIFY,FALSER;设置修改状态

moveax,TRUE

ret

SaveFileENDP

另存为

_SaveAs

PROC

local

@stOF:

OPENFILENAME

local

@stEs:

EDITSTREAM

invokeRtIZeroMemory.addr@stOF,sizeof@stOF

;显示“保存文件“对话框

;填充stOF结构

mov

@stOF.lStructSize,sizeof@stOF

push

hWinMain

pop

@stOF.hwndOwner

;所属窗口

mov

@stOF.lpstrFilter,offsetfilter

;指定文件名筛选字符串

mov

@stOF.lpstrFile,offsetszFileName

mov

@stOF.nMaxFile,MAX_PATH

;指定IpstrFile参数指向的缓冲区的长度,260

;路径必须存在

mov@stOF.lpstrDefExt,offsetdefExt

;默认扩展名

mov@stOF.lpstrTitle,NULL

;标题为”另存为”

invokeGetSaveFileName.addr@stOF

.ifeax

;创立新文件

invokeCreateFile,addrszFileName,GENERIC_READor

GENERIC_WRITE,\;存取方式:

为读写

FILE_SHARE_READ,\

;共享属性:

允许其它进程同时以读方式打开文件

0,\

;安全属性:

无法被继承

CREATE_ALWAYS,\

;创立新文件,如果文件已经存在则清除原文件

FILE_ATTRIBUTE_NORMAL,\

;文件属性:

普通文件

0

;文件模板句柄

.ifeax!

=INVALID_HANDLE_VALUE

pusheax

.ifhFile

;有打开的文件

invokeCloseHandle,hFile

.endif

popeax

;保存文件

movhFile,eax

;文件句柄

call_SaveFile

call_SetCaption

call_SetStatus

moveax,TRUE

ret

.else

invokeMessageBox,hWinMain,addr

errCreateFile,NULL,MB_OKorMBJCONERROR

.endif

.endif

moveax,FALSE

ret

_SaveAsENDP

;打开及输入文件

_OpenFilePROC

local@stOF:

OPENFILENAME

local@stES:

EDITSTREAM

invokeRtlZeroMemory,addr@stOF,sizeof@stOF

;显示”打开文件”对话框

mov

@stOF.lStructSize,sizeof@stOF

push

hWinMain

pop

@stOF.hwndOwner

mov

@stOF.lpstrFilter,offsetfilter

mov

@stOF.lpstrFile,offsetszFileName

mov

@stOF.nMaxFile,MAX_PATH

mov

@stOF.Flags,OFN_FILEMUSTEXISTor

OFN_PATHMUSTEXIST;文件必须存在

invokeGetOpenFileName,addr@stOF

.ifeax

;创立文件

invokeCreateFile.addrszFileName,GENERIC_READor

GENERIC_WRITE,\

FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_

NORMAL,。

;打开存在的文件,当文件不存在时函数会返回

失收

.ifeax==INVALID_HANDLE_VALUE

invokeMessageBox,hWinMain,addreiTOpenFile,NULL,MB_OKorMB」CONSTOPret

.endif

pusheax

.ifhFile

invokeCloseHandle,hFile

.endif

popeax

movhFile,eax

;读入文件

mov@stES.dwCookie,TRUE

^Richcdit的流操作中读文件

mov@stES.dwError,NULL

mov@stES.pfnCallback,offset_StreamProcIn

invoke

SendMessage,hWinEdit,EM_STREAMIN,SF_TEXT,addr@stES

;流入操作,文本格式是简单的文本格式invoke

SendMessage,hWinEdit,EM_SETMODIFY,FALSE,0;设置修改状态

call_SetCaption

call_SetStatus

.endif

ret

_OpenFileENDP

;选择字体

_ChooseFontPROC

local@stCF:

CHOOSEFONT

invokeRtlZeroMemory.addr@stCF,sizeof@stCF

mov

@stCF.lStructSize,sizeof@stCF

push

hWinMain

p°p

@stCF.hwndOwner

mov

@stCF.lpLogFont,offsetstLogFont

;指定字体的名称和属性

pushdwFontColor

pop@stCF.rgbColors

mov@stCF.Flags,CF_SCREENFONTSor

CF_INITTOLOGFONTSTRUCTorCF_EFFECTS;字体列表中只显示屏幕字体,对话框中显示”效果”复选框

invokeChooseFont,addr@stCF

.ifeax

push

@stCF.rgbColors

pop

dwFontColor

mov

eax,@stCF.iPointSize

;用户选择的字体大小,单位是1/10磅

shl

eax,l

invoke

_SetFont,addr

stLogFont.lfFaceName,eax,@stCF.rgbColors

.endif

ret

ChooseFontENDP

;设置标题栏的显示内容

_SetCaptionPROC

local@szBuffer[1024]:

byte

.ifszFileName

;如果当前是某一文件,则显示文件名

moveax,offsetszFileName

.else

moveax,offsetnoName

;否则显TJX未命名

.endif

invokewsprintf.addr@szBuffer,addrtitleFormat,eax

invokeSetWindowText,hWinMain,addr@szBufferret

_SetCaptionENDP

;设置菜单项,状态栏的状态和信息

_SetStatusPROC

local@stRange:

CHARRANGElocal@dwLines,@dwLine,@dwLineStartlocal@szBuffer[256]:

byte

local@stST:

SYSTEMTIME

;在状态栏显示行列信息

invokeGetWindowTextLength,hWinEdit

invokewsprintf,addr@szBuffer,addrcharsFormat,eax

invokeSendMessage,hWinStatus,SB_SETTEXT,2,addr@szBuffer;总字节数

invokeSendMessage,hWinEdit,EM_EXGETSEL,O,addr@stRange;获取选定区域

invoke

SendMessage,hWinEdit,EM_EXLINEFROMCHAR,0,-l;得知指定的字符位于哪一行中

mov@dwLine,eax

invokeSendMessage,hWinEdit,EM_LINEINDEX,eax,0

;获取指定行的起始字符的位置

mov

ecx,@stRange.cpMin

sub

ecx^eax

inc

ecx

;显示给用户的列号从1开始编号

invokewsprintf.addr@szBuffer,addrcolFormat,ecxinvokeSendMessage,hWinStatus,SB_SETTEXTJ,addr

@szBuffer;光标所在位置的列

inc@dwLine

;显示给用户的行号从1开始

invokewsprintf.addr@szBuffer,addrlineFormat,@dwLine

invokeSendMessage,hWinStatus,SB_SETTEXT,O,addr

@szBuffer;光标所在位置的行

;根据情况改变菜单项的状态

moveax,@stRange.cpMin

.ifeax==@stRange.cpMax

;选中区域为空则复制粘贴删除不可用

invoke

EnableMenuItem,hMenuJDM_COPY,MF_GRAYED

invokeEnableMenuItem,hMenu,IDM_CUT,MF_GRAYED.else

invoke

EnableMenuItem,hMenu,IDM_COPY,MF_ENABLED

invoke

EnableMenuItem,hMenuJDM_CUT,MF_ENABLED

.endif

invokeIsClipboardFormatAvailable,CF_TEXT

;判断剪贴板的格式是否是文本格式

.ifeax

;如果剪贴板有内容则能够粘贴

invoke

EnableMenuItem,hMenu,IDM_PASTE,MF_ENABLED

.else

invoke

EnableMenuItem,hMenu,IDM_PASTE,MF_GRAYED

.endif

invokeGetWindowTextLength,hWinEdit

.ifeax

;如果能够全选

invoke

EnableMenuItem,hMenu,IDM_SELECTALL,MF_ENABLED

.else

invoke

EnableMenuItem,hMenu,IDM_SELECTALL,MF_GRAYED

.endif

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

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2