📄 notepro.asm
字号:
sub ebx,7
mov edi,4190h
.while TRUE
add ebx,7
invoke GetPrivateProfileString,addr szSecName1,ebx,\
NULL,addr szBuffer2,MAX_PATH,addr szBuffer1
.break .if eax == 0
inc edi
invoke InsertMenu,hMenu,IDM_FILE_RECENT_DELLIST,\
MF_BYCOMMAND,edi,addr szBuffer2
.endw
ret
_GetRecentlyFile endp
;>>>>>>>>>>>>将当前文件加入文件列表>>>>>>>>>>>>>>
_SaveRecentlyFile proc
local @Find :DWORD
invoke _GetFilePath
mov ebx,offset szKeyName1
mov esi,offset szFileName
mov edi,ebx
add edi,63
;*********必免加入重复记录****************
.while ebx<=edi
invoke GetPrivateProfileString,addr szSecName1,ebx,\
NULL,addr szBuffer2,MAX_PATH,addr szBuffer1
.if eax != 0
mov ecx,offset szBuffer2
invoke lstrcmp,esi,ecx
.if eax == 0
sub ebx,7
mov @Find,TRUE
.break
.else
add ebx,7
.endif
.else
.break
.endif
.endw
.if @Find != TRUE
mov ebx,offset szKeyName1
add ebx,56
.endif
;***********将原先记录后移************
.while ebx>=offset szKeyName1
invoke GetPrivateProfileString,addr szSecName1,ebx,\
NULL,addr szBuffer2,MAX_PATH,addr szBuffer1
.if eax == 0
sub ebx,7
.elseif
add ebx,7
invoke WritePrivateProfileString,addr szSecName1,ebx,\
addr szBuffer2,addr szBuffer1
sub ebx,14
.endif
.endw
invoke WritePrivateProfileString,addr szSecName1,addr szKeyName1,\
addr szFileName,addr szBuffer1
ret
_SaveRecentlyFile endp
;>>>>>>>>>>>>>>>>>>清空历史文件菜单>>>>>>>>>>>>>>>>>>>>>>>>>
_DeleteMenu proc
mov ebx,4190h
.while TRUE
inc ebx
invoke DeleteMenu,hMenu,ebx,MF_BYCOMMAND
.break .if eax == 0
.endw
ret
_DeleteMenu endp
;>>>>>>>>>>>>>>>>>清空INI文件中的历史文件表>>>>>>>>>>>>>>>>>>>>>>>
_DeleteFileKey proc
invoke _GetFilePath
mov ebx,offset szKeyName1
sub ebx,7
.while TRUE
add ebx,7
invoke WritePrivateProfileString,addr szSecName1,ebx,\
NULL,addr szBuffer1
.break .if eax == 0
.endw
ret
_DeleteFileKey endp
;>>>>>>>>>>>>>>>>>>>>>>获得命令行参数的个数>>>>>>>>>>>>>>>>>>>>>>>>>>
_argc proc
local @dwArgc
pushad
mov @dwArgc,0
invoke GetCommandLine
mov esi,eax
cld
_argc_loop:
lodsb
or al,al
jz _argc_end
cmp al,CHAR_BLANK
jz _argc_loop
dec esi
inc @dwArgc
_argc_loop1:
lodsb
or al,al
jz _argc_end
cmp al,CHAR_BLANK
jz _argc_loop ;参数结束
cmp al,CHAR_DELI
jnz _argc_loop1 ;继续处理参数内容
@@:
lodsb
or al,al
jz _argc_end
cmp al,CHAR_DELI
jnz @B
jmp _argc_loop1
_argc_end:
popad
mov eax,@dwArgc
ret
_argc endp
;>>>>>>>>>>>>>返回指定编号的命令行参数>>>>>>>>>>>>
_argv proc _dwArgv,_lpReturn,_dwSize
local @dwArgv,@dwFlag
pushad
inc _dwArgv
mov @dwArgv,0
mov edi,_lpReturn
invoke GetCommandLine
mov esi,eax
cld
_argv_loop:
lodsb
or al,al
jz _argv_end
cmp al,CHAR_BLANK
jz _argv_loop
dec esi
inc @dwArgv
mov @dwFlag,FALSE
mov eax,_dwArgv
cmp eax,@dwArgv
jnz @F
mov @dwFlag,TRUE
@@:
_argv_loop1:
lodsb
or al,al
jz _argv_end
cmp al,CHAR_BLANK
jz _argv_loop ;参数结束
cmp al,CHAR_DELI
jz _argv_loop2
cmp _dwSize,1
jle @F
cmp @dwFlag,TRUE
jne @F
stosb
dec _dwSize
@@:
jmp _argv_loop1 ;继续处理参数内容
_argv_loop2:
lodsb
or al,al
jz _argv_end
cmp al,CHAR_DELI
jz _argv_loop1
cmp _dwSize,1
jle @F
cmp @dwFlag,TRUE
jne @F
stosb
dec _dwSize
@@:
jmp _argv_loop2
_argv_end:
xor al,al
stosb
popad
ret
_argv endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>初始化>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_Init proc
; 注册“查找”对话框消息,初始化“查找”对话框的结构
;****************************************************
mov stFind.lStructSize,sizeof stFind
push hWinMain
pop stFind.hWndOwner
mov stFind.Flags,FR_DOWN
mov stFind.lpstrFindWhat,offset szFindText
mov stFind.wFindWhatLen,sizeof szFindText
mov stFind.lpstrReplaceWith,offset szReplaceText
mov stFind.wReplaceWithLen,sizeof szReplaceText
invoke RegisterWindowMessage,addr FINDMSGSTRING
mov idFindMessage,eax
;*******************创建各控件************************
invoke CreateToolbarEx,hWinMain,\
WS_VISIBLE or WS_CHILD or TBSTYLE_FLAT or TBSTYLE_TOOLTIPS,\
1,0,HINST_COMMCTRL,IDB_STD_SMALL_COLOR,offset stToolbar,\
NUM_BUTTONS,0,0,0,0,sizeof TBBUTTON
mov hToolBar,eax
invoke CreateStatusWindow,WS_CHILD or WS_VISIBLE or SBS_SIZEGRIP,
NULL,hWinMain,ID_StatusBar
mov hStatus,eax
invoke _GetRichEdit
;******************取命令行参数************************
invoke _argc
.if eax > 1
invoke _argv,1,addr szFileName,sizeof szFileName
invoke _OpenTheFile
.else
invoke _SetCaption
.endif
ret
_Init endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>打开文件>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_OpenFile proc
invoke RtlZeroMemory,addr stOF,sizeof stOF
mov stOF.lStructSize,sizeof stOF
push hWinMain
pop stOF.hWndOwner
push hInstance
pop stOF.hInstance
mov stOF.lpstrFilter,offset szFilter
mov stOF.lpstrFile,offset szFileName
mov stOF.nMaxFile,MAX_PATH
mov stOF.Flags,OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or \
OFN_ENABLEHOOK or OFN_ENABLETEMPLATE or \
OFN_HIDEREADONLY or OFN_EXPLORER
mov stOF.lpTemplateName,DLG_TXT ;对话框模板
mov stOF.lpfnHook,offset _OFNHookProcTxt ;对话框窗口过程
invoke GetOpenFileName,addr stOF
.if eax
invoke _OpenTheFile
.endif
ret
_OpenFile endp
;>>>>>>>>>>>>>>>>>>>>>>打开szFileName中指定的文件>>>>>>>>>>>>>>>>>>>>>>>>>>
_OpenTheFile proc
local @stES:EDITSTREAM
invoke CreateFile,addr szFileName,GENERIC_READ or GENERIC_WRITE,\
FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
.if eax == INVALID_HANDLE_VALUE
invoke CreateFile,addr szFileName,GENERIC_READ,\
FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
.if eax == INVALID_HANDLE_VALUE
invoke MessageBox,hWinMain,addr szErrOpenFile,NULL,\
MB_OK or MB_ICONSTOP
ret
.endif
.endif
push eax
.if hFile
invoke CloseHandle,hFile
.endif
pop eax
mov hFile,eax
mov @stES.dwCookie,TRUE
mov @stES.dwError,NULL
mov @stES.pfnCallback,offset _ProcStream
invoke SendMessage,hEdit,EM_STREAMIN,SF_TEXT,addr @stES
invoke SendMessage,hEdit,EM_SETMODIFY,FALSE,0
invoke _SetCaption
invoke _SaveRecentlyFile
ret
_OpenTheFile endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>保存文件>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_SaveFile proc
local @stES:EDITSTREAM
.if ! hFile
call _SaveAs
.if ! eax
ret
.endif
.endif
invoke SetFilePointer,hFile,0,NULL,FILE_BEGIN
invoke SetEndOfFile,hFile
mov @stES.dwCookie,FALSE
mov @stES.dwError,NULL
mov @stES.pfnCallback,offset _ProcStream
invoke SendMessage,hEdit,EM_STREAMOUT,SF_TEXT,addr @stES
invoke SendMessage,hEdit,EM_SETMODIFY,FALSE,0
mov eax,TRUE
ret
_SaveFile endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>文件另存>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_SaveAs proc
local @stOF:OPENFILENAME
local @stES:EDITSTREAM
invoke RtlZeroMemory,addr @stOF,sizeof @stOF
mov @stOF.lStructSize,sizeof @stOF
push hWinMain
pop @stOF.hWndOwner
mov @stOF.lpstrFilter,offset szFilter
mov @stOF.lpstrFile,offset szFileName
mov @stOF.nMaxFile,MAX_PATH
mov @stOF.Flags,OFN_PATHMUSTEXIST
mov @stOF.lpstrDefExt,offset szDefExt
mov @stOF.lpstrTitle,offset szSaveCaption
invoke GetSaveFileName,addr @stOF
.if eax
invoke CreateFile,addr szFileName,GENERIC_READ or GENERIC_WRITE,\
FILE_SHARE_READ,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
.if eax != INVALID_HANDLE_VALUE
push eax
.if hFile
invoke CloseHandle,hFile
.endif
pop eax
mov hFile,eax
call _SaveFile
call _SetCaption
invoke _SaveRecentlyFile
mov eax,TRUE
ret
.else
invoke MessageBox,hWinMain,addr szErrCreateFile,NULL,MB_OK or MB_ICONERROR
.endif
.endif
mov eax,FALSE
ret
_SaveAs endp
;>>>>>>>>>>>>>>>>>>>>>>>>>RichEdit控件的回调函数>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcStream proc uses ebx edi esi _dwCookie,_lpBuffer,_dwBytes,_lpBytes
.if _dwCookie
invoke ReadFile,hFile,_lpBuffer,_dwBytes,_lpBytes,0
.else
invoke WriteFile,hFile,_lpBuffer,_dwBytes,_lpBytes,0
.endif
xor eax,eax
ret
_ProcStream endp
;>>>>>>>>>>>>>>>>>>>>>>>创建工具栏的分栏>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_CreateTBParts proc
local @dwSBParts[8] :DWORD
local @stWinRect :RECT
invoke GetClientRect,hWinMain,addr @stWinRect
mov eax,@stWinRect.right
sub eax,470
mov [@dwSBParts + 0], eax ; pixels from left
add eax,100
mov [@dwSBParts + 4], eax ; pixels from left
add eax,100
mov [@dwSBParts + 8], eax ; pixels from left
add eax,100
mov [@dwSBParts + 12], eax ; pixels from left
add eax,38
mov [@dwSBParts + 16], eax
add eax,38
mov [@dwSBParts + 20], eax
add eax,38
mov [@dwSBParts + 24], eax
add eax,38
mov [@dwSBParts + 28], eax
invoke SendMessage,hStatus,SB_SETPARTS,8,addr @dwSBParts
invoke _SetStatusStatus
invoke _SetToolStatus
ret
_CreateTBParts endp
;>>>>>>>>>>>>>>>>>>>调整编辑框位置和大小>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_EditSize proc
local @stWinRect :RECT
local @stTBRect :RECT
local @stSBRect :RECT
invoke GetClientRect,hWinMain,addr @stWinRect
invoke GetClientRect,hToolBar,addr @stTBRect
invoke GetClientRect,hStatus,addr @stSBRect
mov eax,@stWinRect.bottom
sub eax,2
.if !bTool
mov @stTBRect.bottom,2
.elseif
sub eax,@stTBRect.bottom
add @stTBRect.bottom,2
.endif
.if bStatus
sub eax,@stSBRect.bottom
.endif
mov @stSBRect.bottom,eax
invoke MoveWindow,hEdit,0,@stTBRect.bottom,@stWinRect.right,@stSBRect.bottom,TRUE
ret
_EditSize endp
;>>>>>>>>>>>>>>>>>>>>>>判断编辑框内容是否有改变>>>>>>>>>>>>>>>>>>>>>>>>>
_CheckModify proc
invoke SendMessage,hEdit,EM_GETMODIFY,0,0
.if eax
invoke MessageBox,hWinMain,addr szModify,addr szCaption,\
MB_YESNOCANCEL or MB_ICONQUESTION
.if eax == IDYES
call _SaveFile
.elseif eax == IDNO
mov eax,TRUE
.elseif eax == IDCANCEL
xor eax,eax
.endif
.else
mov eax,TRUE
.endif
ret
_CheckModify endp
;>>>>>>>>>>>>>>>>>>>>>>>>>设置字体及字体颜色>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -