一个汇编版记事本源代码
转载
一个汇编版记事本源代码,只是不知道GB2312_CHARSET常数该为多少
;********************************************************************
; 用下列命令进行编译和链接:
; ml /c /coff win322-1.asm
; rc win322-1.rc
; link /subsystem:windows win322-1.obj win322-1.res
;********************************************************************
; 使用各种资源----记事本程序的编写
;==================================================
.486
.model flat,stdcall
option casemap : none
;********************************************************************
;include=============================================
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
include \masm32\include\comdlg32.inc
includelib \masm32\lib\comdlg32.lib
include \masm32\include\comctl32.inc
includelib \masm32\lib\comctl32.lib
include \masm32\include\gdi32.inc
includelib \masm32\lib\gdi32.lib
include \masm32\include\shell32.inc
includelib \masm32\lib\shell32.lib
;********************************************************************
CDN_FILEOK equ CDN_FIRST-0005h
CDN_INITDONE equ CDN_FIRST - 0
CDN_SELCHANGE equ CDN_FIRST - 1
OFN_ENABLESIZING equ 00800000h
IDM_MENUHELP1 equ 700
IDM_MENUHELP2 equ 701
IDM_MENUHELP3 equ 702
IDM_MENUHELP4 equ 703
IDM_MENUHELP5 equ 704
IDM_MENUHELP6 equ 705
GB2312_CHARSET equ 1
IDC_MAIN equ 100
IDM_MAIN equ 200
IDA_MAIN equ 300
DLG_MAIN equ 400
DLG_GOTO equ 1000
IDC_RICHEDIT equ 1010
IDM_NEW equ 101
IDM_OPEN equ 102
IDM_SAVE equ 103
IDM_SAVE_AS equ 104
IDM_PAGE_SETUP equ 105
IDM_PRINT equ 106
IDM_EXIT equ 107
IDM_UNDO equ 108
IDM_CUT equ 109
IDM_COPY equ 110
IDM_PASTE equ 111
IDM_DEL equ 112
IDM_FIND equ 113
IDM_FIND_NEXT equ 114
IDM_REPLACE equ 115
IDM_GOTO equ 116
IDM_CHECK_ALL equ 117
IDM_TIME_DATE equ 118
IDM_LINE_WRAP equ 119
IDM_FONT equ 120
IDM_STATUS_BAR equ 121
IDM_HELP equ 122
IDM_ABOUT_NOTEPAD equ 123
IDM_TOOL_BAR equ 124
ID_EDIT equ 500
IDC_PREVIEW equ 600
ID_STATUSBAR equ 800
ID_WINMAIN equ 900
ID_OK equ 201
ID_CANCEL equ 202
;******************************************************************
OFNOTIFYEX struct
hdr NMHDR <>
lpOpenFileName OPENFILENAME <>
lpsf dword ?
lpIdItem dword ?
OFNOTIFYEX ends
;********************************************************************
.data?
hInstance dd ?
hWinMain dd ?
hMenu dd ?
hEdit dd ?
hEdit2 dd ?
hIcon dd ?
SetPaste dd ?
@hDlg dd ?
@hEdit dd ?
hClipboard dd ?
lpOldProc dd ?
_lpMem dd ?
_flag db ?
_JFlag dd ?
hFile dd ?
hHeap dd ?
hHeap2 dd ?
lpHeap dd ?
lpPrintBuffer dd ?
lpNumByte dd ?
lpVirtualMem dd ?
FrId dd ?
hFind dd ?
lpFindMem dd ?
dwFindNext dd ?
hReplace dd ?
hStatusBar dd ?
hToolbarWnd dd ?
oldEditProc dd ?
hDlg dd ?
hDc dd ?
hFont dd ?
@dwHighSize dd ?
@dwLowSize dd ?
szPrinter dd MAX_PATH dup (?)
szFileName dd MAX_PATH dup (?)
lpBuff0 dd 1024 dup (?)
lpBuff1 dd 1024 dup (?)
szFindText dd MAX_PATH dup (?)
szReplaceText dd MAX_PATH dup (?)
logfont LOGFONT <?>
.data
stFr FINDREPLACE <sizeof FINDREPLACE,0,0,FR_DOWN or FR_HIDEWHOLEWORD,szFindText,szReplaceText,sizeof szFindText,sizeof szReplaceText,0,0,0>
stButton equ this byte
TBBUTTON <STD_FILENEW,IDM_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,-1>
TBBUTTON <STD_FILEOPEN,IDM_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,-1>
TBBUTTON <STD_FILESAVE,IDM_SAVE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,-1>
TBBUTTON <0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,-1>
TBBUTTON <STD_PRINT,IDM_PRINT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,-1>
TBBUTTON <0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,-1>
TBBUTTON <STD_COPY,IDM_COPY,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,-1>
TBBUTTON <STD_CUT,IDM_CUT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,-1>
TBBUTTON <STD_PASTE,IDM_PASTE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,-1>
TBBUTTON <0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,-1>
TBBUTTON <STD_FIND,IDM_FIND,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,-1>
TBBUTTON <STD_REPLACE,IDM_REPLACE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,-1>
TBBUTTON <0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,-1>
TBBUTTON <STD_HELP,IDM_HELP,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,-1>
TBBUTTON <0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,-1>
.const
szClassName db "MYNotepad",0
szDefCaption db "无标题",0
szCaption db "记事本",0
szNotCaption db "无标题",0
szFilter db "文本文档案(*.txt)",0,"*.txt",0,"ASM文档(*.asm)",0,"*.asm",0,"ALL FILE(*.*)",0,"*.*",0,0
szSaveYesOrNo db "你的文件%s已经修改过,是否保存文档?",0
szDefExt db "txt",0
szSaveDialog db "保存",0
szSaveAs db "另存为",0
szClass db "EDIT",0
szErrPerson db "错误",0
StatusBarCount dd 400,-1
szSetText db "请选择文件进行预览",0
szExisting db "文件 %s 已经存在,确定要覆盖它吗?",0
szLnCol db "Ln %d,Col%d",0
FINDMSGSTR db "commdlg_FindReplace",0
szMenuHelp dd 0,IDM_MENUHELP1,0,0
ceshistr db "%s",0
ceshi db "%d",0
chengong db "记事本完成了,谢谢使用",0
szTextOut db "指定行超出控件文本行数",0
szNotFound db "找不到%s",0
szTime db "%d:%02d %04d-%02d-%02d",0
szAbout1 db "模拟记事本程序",0
szAbout2 db "kiki-------梁越洋",0
szFont db "宋体",0
szApi db "该功能还在修改中,暂不提供",0
szHelp db "怎么不会用要看帮助文件?不会吧!!都说模拟记事本拉,肯定是象记事本那样子使用拉:-)",0
;********************************************************************
.code
;********************************************************************
_SetFont proc uses ebx esi edi
invoke CreateFont,logfont.lfHeight,logfont.lfWidth,logfont.lfEscapement,\
logfont.lfOrientation,logfont.lfWeight,dword ptr logfont.lfItalic,\
dword ptr logfont.lfUnderline,dword ptr logfont.lfStrikeOut,\
dword ptr logfont.lfCharSet,dword ptr logfont.lfOutPrecision,\
dword ptr logfont.lfClipPrecision,dword ptr logfont.lfQuality,\
dword ptr logfont.lfPitchAndFamily,offset logfont.lfFaceName
.if eax
mov hFont,eax
invoke SendMessage,hEdit,WM_SETFONT,hFont,TRUE
.endif
ret
_SetFont endp
;********************************************************************
_ChooseFont proc uses ebx esi edi
local @stCF:CHOOSEFONT
invoke RtlZeroMemory,addr @stCF,sizeof CHOOSEFONT
mov @stCF.lStructSize,sizeof CHOOSEFONT
push hInstance
pop @stCF.hInstance
push hWinMain
pop @stCF.hWndOwner
mov @stCF.lpLogFont,offset logfont
mov @stCF.Flags,CF_NOOEMFONTS or CF_SCREENFONTS or CF_INITTOLOGFONTSTRUCT or CF_TTONLY
invoke ChooseFont,addr @stCF
.if eax
mov eax,@stCF.iPointSize
shl eax,1
invoke _SetFont
.endif
ret
_ChooseFont endp
;********************************************************************
Dlg_Proc proc uses ebx esi edi _hDlg,_uMsg,_wParam,_lParam
local @hDlgEdit
local @szDlgCount
mov eax,_uMsg
.if eax == WM_CLOSE
invoke DestroyWindow,_hDlg
.elseif eax == WM_COMMAND
mov eax,_wParam
.if ax == ID_OK
invoke GetDlgItemInt,_hDlg,IDC_RICHEDIT,0,0
push eax
invoke GetDlgItem,_hDlg,IDC_RICHEDIT
invoke SendMessage,hEdit,EM_GETLINECOUNT,0,0
pop ecx
.if ecx > eax
invoke MessageBox,0,offset szTextOut,0,MB_OK
.else
mov eax,ecx
dec eax
invoke SendMessage,hEdit,EM_LINEINDEX,eax,0
invoke SendMessage,hEdit,EM_SETSEL,eax,eax
invoke SendMessage,hEdit,EM_SCROLLCARET,0,0
invoke SendMessage,_hDlg,WM_CLOSE,0,0
.endif
.elseif ax == ID_CANCEL
invoke SendMessage,_hDlg,WM_CLOSE,0,0
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
Dlg_Proc endp
;********************************************************************
EditWndProc proc _hWnd,_uMsg,_wParam,_lParam
mov eax,_uMsg
.if (eax == WM_KEYDOWN) || (eax == WM_KEYUP)
call _SetState
.elseif eax == WM_LBUTTONDOWN || eax == WM_LBUTTONUP
call _SetState
.endif
invoke CallWindowProc,oldEditProc,_hWnd,_uMsg,_wParam,_lParam
ret
EditWndProc endp
;********************************************************************
_TestSf proc uses ebx esi edi _address,_count,_address2
mov ecx,_count
mov esi,_address
mov edi,_address2
.repeat
mov al,byte ptr [esi]
.if al >="A" && al <= "Z"
add al,20h
.endif
mov bl,byte ptr [edi]
.if bl >="A" && bl <= "Z"
add bl,20h
.endif
dec ecx
inc esi
inc edi
sub al,bl
.break .if al != 0
.until ecx == 0
.if !ecx && ZERO?
mov eax,TRUE
jmp @f
.endif
mov eax,FALSE
@@:
and stFr.Flags,not FR_MATCHCASE
ret
_TestSf endp
;********************************************************************
_FindReplace proc uses ebx esi edi
local @stRange:CHARRANGE
local @LowSize,@HighSize,@Flags,@dwReturn
invoke SendMessage,hEdit,EM_GETSEL,addr @stRange.cpMin,addr @stRange.cpMax
mov eax,@stRange.cpMax
mov @stRange.cpMin,eax
invoke GetWindowTextLength,hEdit
inc eax
mov @HighSize,eax
invoke VirtualAlloc,NULL,eax,MEM_COMMIT or MEM_RESERVE,PAGE_READWRITE
mov lpFindMem,eax
invoke GetWindowText,hEdit,lpFindMem,@HighSize
invoke lstrlen,offset szFindText
inc eax
mov @LowSize,eax
mov ebx,@stRange.cpMin
mov @Flags,ebx
@@:
push ebx
invoke GetWindowTextLength,hEdit
cmp eax,0
jz _NotF
pop ebx
add ebx,lpFindMem
mov esi,ebx
mov edi,offset szFindText
.if !(stFr.Flags & FR_MATCHCASE)
invoke _TestSf,esi,@LowSize,edi
.if eax
jmp @f
.endif
.endif
cld
mov ecx,@LowSize
repe cmpsb
.if ecx == 0 && ZERO?
jmp @f
.else
inc @Flags
mov ebx,@Flags
mov edx,@HighSize
sub edx,@LowSize
.if ebx <= edx
jmp @b
.else
jmp _NotF
.endif
.endif
@@: mov edx,@Flags
add edx,@LowSize
dec edx
invoke SendMessage,hEdit,EM_SETSEL,@Flags,edx
mov @dwReturn,1
jmp _End
_NotF: invoke wsprintf,offset lpBuff1,offset szNotFound,offset szFindText
invoke MessageBox,hWinMain,offset lpBuff1,offset szCaption,MB_OK
mov @dwReturn,0
_End: invoke VirtualFree,lpFindMem,0,MEM_DECOMMIT or MEM_RELEASE
invoke RtlZeroMemory,offset lpBuff1,sizeof lpBuff1
mov lpFindMem,0
mov dwFindNext,-1
mov eax,@dwReturn
ret
_FindReplace endp
;********************************************************************
_FindReplace2 proc uses ebx esi edi
local @LowSize,@HighSize,@Flags,@dwReturn
local @stRange:CHARRANGE
invoke SendMessage,hEdit,EM_GETSEL,addr @stRange.cpMin,addr @stRange.cpMax
mov eax,@stRange.cpMin
mov @stRange.cpMax,eax
invoke GetWindowTextLength,hEdit
inc eax
mov @HighSize,eax
invoke VirtualAlloc,NULL,eax,MEM_COMMIT or MEM_RESERVE,PAGE_READWRITE
mov lpFindMem,eax
invoke GetWindowText,hEdit,lpFindMem,@HighSize
invoke lstrlen,offset szFindText
inc eax
mov @LowSize,eax
mov ebx,@stRange.cpMax
sub ebx,@LowSize
inc ebx
mov @Flags,ebx
@@:
&n, bsp; cmp ebx,-1
jle _Err
add ebx,lpFindMem
mov esi,ebx
mov edi,offset szFindText
.if !(stFr.Flags & FR_MATCHCASE)
invoke _TestSf,esi,@LowSize,edi
.if eax
jmp @f
.endif
.endif
cld
mov ecx,@LowSize
repe cmpsb
.if (ecx == 0) && ZERO?
jmp @f
.else
dec @Flags
mov ebx,@Flags
.if ebx >= 0
jmp @b
.endif
jmp _Err
.endif
@@:
mov edx,@Flags
add edx,@LowSize
dec edx
invoke SendMessage,hEdit,EM_SETSEL,@Flags,edx
mov @dwReturn,1
jmp _Ex
_Err: invoke wsprintf,offset lpBuff1,offset szNotFound,offset szFindText
invoke MessageBox,hWinMain,offset lpBuff1,offset szCaption,MB_OK
mov @dwReturn,0
_Ex:
invoke VirtualFree,lpFindMem,0,MEM_DECOMMIT or MEM_RELEASE
invoke RtlZeroMemory,offset lpBuff1,sizeof lpBuff1
mov lpFindMem,0
mov dwFindNext,-1
mov eax,@dwReturn
ret
_FindReplace2 endp
;********************************************************************
_pfnCall proc uses ebx esi edi _dwCookie,_HeapMem,_dwNumByte,_lpNumByte
.if _dwCookie
invoke WriteFile,hFile,_HeapMem,_dwNumByte,_lpNumByte,0
.else
invoke ReadFile,hFile,_HeapMem,_dwNumByte,_lpNumByte,0
.endif
ret
_pfnCall endp
;********************************************************************
_CheckModify proc uses ebx esi edi
invoke SendMessage,hEdit,EM_GETMODIFY,0,0
.if eax
invoke wsprintf,offset lpBuff0,offset szSaveYesOrNo,offset szFileName
invoke MessageBox,hWinMain,offset lpBuff0,offset szCaption,MB_YESNOCANCEL
.if eax == IDYES
call _SaveFile
mov eax,1
.elseif eax == IDNO
mov eax,-1
.endif
.else
mov eax,0
.endif
ret
_CheckModify endp
;********************************************************************
_PageSetup proc uses ebx esi edi
local @stPage : PAGESETUPDLG
invoke RtlZeroMemory,addr @stPage,sizeof @stPage
mov @stPage.lStructSize,sizeof PAGESETUPDLG
push hWinMain
pop @stPage.hwndOwner
invoke PageSetupDlg,addr @stPage
.if eax && @stPage.hDevMode
mov eax,@stPage.hDevMode
mov eax,[eax]
invoke wsprintf,offset szPrinter,offset ceshistr,eax
.endif
ret
_PageSetup endp
;********************************************************************
_PrintDc proc uses ebx esi edi
local @PrintSize
local @Doc : DOCINFO
invoke CreateDC,NULL,offset szPrinter,NULL,NULL
mov hDc,eax
.if hDc
.if szPrinter
invoke GetWindowTextLength,hEdit
inc eax
mov @PrintSize,eax
invoke GetProcessHeap
.if eax && (eax < 0C0000000H)
mov hHeap2,eax
.endif
invoke HeapAlloc,hHeap2,HEAP_GENERATE_EXCEPTIONS or HEAP_NO_SERIALIZE or\
HEAP_ZERO_MEMORY,@PrintSize
.if eax && (eax < 0c0000000h)
mov lpPrintBuffer,eax
.endif
invoke GetWindowText,hEdit,lpPrintBuffer,@PrintSize
invoke StartDoc,hDc,NULL
invoke StartPage,hDc
invoke TextOut,hDc,10,10,lpPrintBuffer,@PrintSize
invoke EndPage,hDc
invoke EndDoc,hDc
invoke HeapFree,hHeap2,NULL,lpPrintBuffer
invoke RtlZeroMemory,offset szPrinter,sizeof szPrinter
.endif
.endif
ret
_PrintDc endp
;********************************************************************
_MadeApplication proc uses ebx esi edi
invoke CreateWindowEx,0,offset szClass,NULL,\
WS_CHILD OR WS_VISIBLE OR ES_MULTILINE OR ES_WANTRETURN or WS_DLGFRAME\
OR WS_VSCROLL or ES_NOHIDESEL or ES_AUTOHSCROLL or WS_HSCROLL,\
0,0,0,0,hWinMain,ID_EDIT,hInstance,NULL
mov hEdit,eax
invoke SendMessage,hEdit,EM_LIMITTEXT,0,0
invoke CreateFont,-16,0,0,\
0,FW_THIN,FALSE,\
FALSE,FALSE,\
GB2312_CHARSET,OUT_CHARACTER_PRECIS,\
CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY,\
FF_MODERN,offset szFont
.if eax
mov hFont,eax
invoke SendMessage,hEdit,WM_SETFONT,hFont,TRUE
.endif
invoke SetClipboardViewer,hWinMain
mov hClipboard,eax
invoke CreateStatusWindow,SBARS_SIZEGRIP or WS_CHILD or WS_VISIBLE,0,hWinMain,ID_STATUSBAR
mov hStatusBar,eax
invoke SendMessage,hStatusBar,SB_SETPARTS,2,offset StatusBarCount
invoke CreateToolbarEx,hWinMain,TBSTYLE_FLAT or WS_CHILD or WS_VISIBLE or TBSTYLE_TOOLTIPS or CCS_ADJUSTABLE,\
ID_WINMAIN,0,HINST_COMMCTRL,IDB_STD_SMALL_COLOR,offset stButton,15,0,0,0,0,sizeof TBBUTTON
mov hToolbarWnd,eax
invoke GetCommandLine
mov esi,eax
mov edi,offset szFileName
_1: lodsb
_2:
cmp al,22H
jz _5
_3: or al,al
jz _4
cmp al,20h
jz _1
mov [edi],al
inc edi
lodsb
cmp al,20h
jz _4
jmp _3
_5: lodsb
cmp al,22H
jz _1
jmp _5
_4:
.if szFileName
mov _JFlag,1
jmp near ptr _IsJpAddress
.endif
_6 equ THIS BYTE
ret
_MadeApplication endp
;********************************************************************
_SetState proc uses ebx esi edi
local @wParam,@lParam
local @stRg:CHARRANGE
local @LineIn,@Length
local @Buffer
invoke SendMessage,hEdit,EM_GETSEL,addr @stRg.cpMin,addr @stRg.cpMax
invoke SendMessage,hEdit,EM_LINEFROMCHAR,-1,0
mov @LineIn,eax
invoke SendMessage,hEdit,EM_LINEINDEX,eax,0
mov edx,@stRg.cpMin
sub edx,eax
inc edx
inc @LineIn
invoke wsprintf,offset lpBuff1,offset szLnCol,edx,@LineIn
invoke SendMessage,hStatusBar,SB_SETTEXT,1,offset lpBuff1
invoke RtlZeroMemory,offset lpBuff1,sizeof lpBuff1
mov eax,@stRg.cpMin
.if eax == @stRg.cpMax
invoke EnableMenuItem,hMenu,IDM_CUT,MF_GRAYED
invoke EnableMenuItem,hMenu,IDM_COPY,MF_GRAYED
invoke EnableMenuItem,hMenu,IDM_DEL,MF_GRAYED
.if hToolbarWnd
invoke SendMessage,hToolbarWnd,TB_ENABLEBUTTON,IDM_CUT,FALSE
invoke SendMessage,hToolbarWnd,TB_ENABLEBUTTON,IDM_COPY,FALSE
.endif
.else
invoke EnableMenuItem,hMenu,IDM_CUT,MF_ENABLED
invoke EnableMenuItem,hMenu,IDM_COPY,MF_ENABLED
invoke EnableMenuItem,hMenu,IDM_DEL,MF_ENABLED
.if hToolbarWnd
invoke SendMessage,hToolbarWnd,TB_ENABLEBUTTON,IDM_CUT,TRUE
invoke SendMessage,hToolbarWnd,TB_ENABLEBUTTON,IDM_COPY,TRUE
.endif
.endif
invoke SendMessage,hEdit,EM_CANUNDO,0,0
.if eax
invoke EnableMenuItem,hMenu,IDM_UNDO,MF_ENABLED
.else
invoke EnableMenuItem,hMenu,IDM_UNDO,MF_GRAYED
.endif
invoke SendMessage,hEdit,EM_GETMODIFY,0,0
.if eax
invoke EnableMenuItem,hMenu,IDM_SAVE,MF_ENABLED
invoke EnableMenuItem,hMenu,IDM_SAVE_AS,MF_ENABLED
.if hToolbarWnd
invoke SendMessage,hToolbarWnd,TB_ENABLEBUTTON,IDM_SAVE,TRUE
.endif
.else
invoke EnableMenuItem,hMenu,IDM_SAVE,MF_GRAYED
invoke EnableMenuItem,hMenu,IDM_SAVE_AS,MF_GRAYED
.if hToolbarWnd
invoke SendMessage,hToolbarWnd,TB_ENABLEBUTTON,IDM_SAVE,FALSE
.endif
.endif
ret
_SetState endp
;********************************************************************
_ReSize proc uses ebx esi edi
local stRect : RECT
local @stRect : RECT
local @Width,@Height,@Temp
invoke GetClientRect,hWinMain,addr stRect
mov eax,stRect.right
sub eax,stRect.left
mov @Width,eax
mov eax,stRect.bottom
sub eax,stRect.top
mov @Height,eax
invoke IsWindowVisible,hStatusBar
.if eax
invoke MoveWindow,hStatusBar,0,0,0,0,TRUE
invoke GetWindowRect,hStatusBar,addr @stRect
mov eax,@stRect.bottom
sub eax,@stRect.top
sub @Height,eax
.endif
invoke IsWindowVisible,hToolbarWnd
.if eax
invoke SendMessage,hToolbarWnd,TB_AUTOSIZE,0,0
invoke GetWindowRect,hToolbarWnd,addr @stRect
mov eax,@stRect.bottom
sub eax,@stRect.top
mov stRect.top,eax
sub @Height,eax
.endif
invoke MoveWindow,hEdit,stRect.left,stRect.top,@Width,@Height,TRUE
ret
_ReSize endp
;********************************************************************
_OpenHook proc uses ebx esi edi _hDlg,_uMsg,_wParam,_lParam
local @FilePath[MAX_PATH]:BYTE
local @hFile,@ReadFileNum
local @ReadMem [2046]:BYTE
mov eax,_uMsg
.if eax == WM_NOTIFY
mov esi,_lParam
assume esi : ptr NMHDR
.if [esi].code == CDN_FILEOK
.elseif [esi].code == CDN_INITDONE
invoke GetParent,_hDlg
mov @hDlg,eax
invoke GetDlgItem,_hDlg,IDC_PREVIEW
mov @hEdit,eax
invoke SendMessage,@hEdit,WM_SETTEXT,0,offset szSetText
.elseif [esi].code == CDN_SELCHANGE
invoke SendMessage,@hDlg,CDM_GETFILEPATH,MAX_PATH,addr @FilePath
invoke CreateFile,addr @FilePath,GENERIC_READ,FILE_SHARE_READ,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
mov @hFile,eax
.if eax == INVALID_HANDLE_VALUE
xor eax,eax
ret
.endif
invoke ReadFile,@hFile,addr @ReadMem,2046,addr @ReadFileNum,NULL
invoke SendMessage,@hEdit,WM_SETTEXT,0,addr @ReadMem
.endif
invoke CloseHandle,@hFile
.endif
assume esi : nothing,edi : nothing
xor eax,eax
ret
_OpenHook endp
;********************************************************************
_OpenFile proc uses ebx esi edi
local stOpenFile:OPENFILENAME
.if hFile
invoke CloseHandle,hFile
.endif
invoke RtlZeroMemory,addr stOpenFile,sizeof OPENFILENAME
mov stOpenFile.lStructSize,sizeof OPENFILENAME
push hWinMain
pop stOpenFile.hWndOwner
mov stOpenFile.Flags,OFN_ENABLESIZING or OFN_FILEMUSTEXIST or \
OFN_PATHMUSTEXIST or OFN_HIDEREADONLY or \
OFN_EXPLORER or OFN_ENABLETEMPLATE or OFN_ENABLEHOOK
push hInstance
pop stOpenFile.hInstance
mov stOpenFile.lpTemplateName,DLG_MAIN
mov stOpenFile.lpfnHook,offset _OpenHook
mov stOpenFile.lpstrFilter,offset szFilter
mov stOpenFile.nMaxFile,MAX_PATH
mov stOpenFile.lpstrFile,offset szFileName
invoke GetOpenFileName,addr stOpenFile
.if eax
_IsJpAddress equ THIS byte
invoke CreateFile,offset szFileName,GENERIC_READ or GENERIC_WRITE,\
FILE_SHARE_READ OR FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
.if eax == INVALID_HANDLE_VALUE
invoke GetLastError
.if eax
invoke wsprintf,offset lpBuff1,offset ceshi,eax
invoke MessageBox,NULL,offset lpBuff1,offset lpBuff1,MB_OK
.endif
jmp @f
.endif
mov hFile,eax
.if hFile
invoke SetWindowText,hWinMain,offset szFileName
.endif
invoke GetFileSize,hFile,addr @dwHighSize
add eax,4
mov @dwLowSize,eax
invoke VirtualAlloc,NULL,@dwLowSize,MEM_COMMIT or MEM_RESERVE,PAGE_READWRITE
.if eax
mov lpVirtualMem,eax
.endif
invoke _pfnCall,0,lpVirtualMem,@dwLowSize,offset lpNumByte
invoke SetWindowText,hEdit,lpVirtualMem
invoke VirtualFree,lpVirtualMem,0,MEM_DECOMMIT or MEM_RESERVE
invoke CloseHandle,hFile
.endif
@@: .if _JFlag
mov _JFlag,0
jmp near ptr _6
.else
ret
.endif
_OpenFile endp
;********************************************************************
_SaveFile proc uses ebx esi edi
local stOF : OPENFILENAME
local dwSize
.if szFileName
jmp _CreateFile
.endif
invoke RtlZeroMemory,addr stOF,sizeof OPENFILENAME
push hWinMain
pop stOF.hWndOwner
mov stOF.lStructSize,sizeof OPENFILENAME
mov stOF.lpstrFilter,offset szFilter
mov stOF.lpstrFile,offset szFileName
mov stOF.nMaxFile,MAX_PATH
mov stOF.lpstrTitle,offset szSaveDialog
mov stOF.Flags,OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST
invoke GetSaveFileName,addr stOF
.if eax
_CreateFile: invoke CreateFile,offset szFileName,GENERIC_READ or GENERIC_WRITE,NULL,\
NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
.if eax == INVALID_HANDLE_VALUE
jmp @f
.endif
mov hFile,eax
invoke GetWindowTextLength,hEdit
inc eax
mov dwSize,eax
invoke GetProcessHeap
.if eax && (eax < 0C0000000H)
mov hHeap,eax
.endif
invoke HeapAlloc,hHeap,HEAP_GENERATE_EXCEPTIONS or HEAP_NO_SERIALIZE or\
HEAP_ZERO_MEMORY,dwSize
.if eax && (eax < 0c0000000h)
mov lpHeap,eax
.endif
pop ecx
invoke GetWindowText,hEdit,lpHeap,dwSize
invoke _pfnCall,1,lpHeap,dwSize,offset lpNumByte
invoke CloseHandle,hFile
invoke HeapFree,hHeap,NULL,lpHeap
invoke SendMessage,hEdit,EM_SETMODIFY,FALSE,0
.endif
@@: ret
_SaveFile endp
;********************************************************************
_WndProc proc uses ebx esi edi hWnd,uMsg,wParam,lParam
local @lpCL
local @stPt:PAINTSTRUCT
local stRt:RECT
local @stRange:CHARRANGE
local @stTime:SYSTEMTIME
local @wHour,@wMinute,@wYear,@wMonth,@wDay
mov eax,uMsg
.if eax == WM_CLOSE
call _CheckModify
.if (eax == 1) || (eax == 0) || (eax == -1)
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
invoke ChangeClipboardChain,hWinMain,hClipboard
.endif
.elseif eax == WM_CREATE
mov eax,hWnd
mov hWinMain,eax
mov stFr.hWndOwner,eax
push hInstance
pop s, tFr.hInstance
invoke RegisterWindowMessage,addr FINDMSGSTR
mov FrId,eax
invoke _MadeApplication
call _ReSize
invoke SetWindowLong,hEdit,GWL_WNDPROC,offset EditWndProc
mov oldEditProc,eax
.elseif eax == WM_PAINT
invoke BeginPaint,hWnd,addr @stPt
invoke EndPaint,hWnd,addr @stPt
.elseif eax == WM_COMMAND
mov eax,wParam
.if ax == IDM_OPEN
call _CheckModify
cmp eax,-1
jz @f
invoke SendMessage,hEdit,EM_GETMODIFY,0,0
.if !eax
@@: call _OpenFile
.endif
.elseif ax == IDM_NEW
invoke SendMessage,hEdit,EM_GETMODIFY,0,0
.if eax
invoke wsprintf,offset lpBuff0,offset szSaveYesOrNo,offset szFileName
invoke MessageBox,hWinMain,offset lpBuff0,offset szCaption,MB_YESNOCANCEL
.if eax == IDYES
call _SaveFile
.elseif eax == IDCANCEL
jmp @f
.endif
.endif
invoke SetWindowText,hWinMain,offset szNotCaption
invoke SendMessage,hEdit,EM_SETSEL,0,-1
invoke SendMessage,hEdit,WM_CLEAR,0,0
.if hFile
invoke CloseHandle,hFile
invoke RtlZeroMemory,offset szFileName,sizeof szFileName
.endif
invoke SendMessage,hEdit,EM_SETMODIFY,FALSE,0
invoke _SetState
@@:
.elseif ax == IDM_SAVE
call _SaveFile
call _SetState
.elseif ax == IDM_SAVE_AS
mov szFileName,0
call _SaveFile
call _SetState
.elseif ax == IDM_EXIT
invoke SendMessage,hWnd,WM_CLOSE,0,0
.elseif ax == IDM_TIME_DATE
invoke GetLocalTime,addr @stTime
movzx eax,@stTime.wHour
mov @wHour,eax
movzx eax,@stTime.wMinute
mov @wMinute,eax
movzx eax,@stTime.wYear
mov @wYear,eax
movzx eax,@stTime.wMonth
mov @wMonth,eax
movzx eax,@stTime.wDay
mov @wDay,eax
invoke RtlZeroMemory,offset lpBuff1,sizeof lpBuff1
invoke wsprintf,offset lpBuff1,offset szTime,@wHour,@wMinute,@wYear,@wMonth,@wDay
invoke SendMessage,hEdit,EM_REPLACESEL,TRUE,offset lpBuff1
invoke RtlZeroMemory,offset lpBuff1,sizeof lpBuff1
.elseif ax == IDM_STATUS_BAR
invoke GetMenuState,hMenu,IDM_STATUS_BAR,MF_BYCOMMAND
.if eax & MF_CHECKED
invoke CheckMenuItem,hMenu,IDM_STATUS_BAR,MF_UNCHECKED
invoke ShowWindow,hStatusBar,SW_HIDE
.else
invoke CheckMenuItem,hMenu,IDM_STATUS_BAR,MF_CHECKED
invoke ShowWindow,hStatusBar,SW_SHOWNORMAL
.endif
call _ReSize
.elseif ax == IDM_CHECK_ALL
invoke SendMessage,hEdit,EM_SETSEL,0,-1
.elseif ax == IDM_COPY
invoke SendMessage,hEdit,WM_COPY,0,0
.elseif ax == IDM_CUT
invoke SendMessage,hEdit,WM_CUT,0,0
.elseif ax == IDM_PASTE
invoke SendMessage,hEdit,WM_PASTE,0,0
.elseif ax == IDM_UNDO
invoke SendMessage,hEdit,EM_UNDO,0,0
.elseif ax == IDM_DEL
invoke SendMessage,hEdit,WM_CLEAR,0,0
.elseif ax == IDM_FIND
and stFr.Flags,not FR_DIALOGTERM
invoke FindText,addr stFr
.if eax
mov hFind,eax
.endif
.elseif ax == IDM_FIND_NEXT
.if stFr.Flags & FR_DOWN
or stFr.Flags,FR_DOWN
invoke _FindReplace
.else
and stFr.Flags,not FR_DOWN
invoke _FindReplace2
.endif
.elseif ax == IDM_REPLACE
and stFr.Flags,not FR_DIALOGTERM
invoke ReplaceText,offset stFr
.if eax
mov hReplace,eax
.endif
.elseif ax == IDM_TOOL_BAR
invoke GetMenuState,hMenu,IDM_TOOL_BAR,MF_BYCOMMAND
.if eax & MF_CHECKED
invoke CheckMenuItem,hMenu,IDM_TOOL_BAR,MF_UNCHECKED
invoke ShowWindow,hToolbarWnd,SW_HIDE
.else
invoke CheckMenuItem,hMenu,IDM_TOOL_BAR,MF_CHECKED
invoke ShowWindow,hToolbarWnd,SW_SHOWNORMAL
.endif
call _ReSize
.elseif ax == IDM_GOTO
invoke CreateDialogParam,hInstance,DLG_GOTO,hWinMain,offset Dlg_Proc,NULL
mov hDlg,eax
invoke SendDlgItemMessage,hDlg,IDC_RICHEDIT,EM_LIMITTEXT,12,0
.elseif ax == IDM_PAGE_SETUP
call _PageSetup
.elseif ax == IDM_PRINT
call _PrintDc
.elseif ax == IDM_FONT
invoke _ChooseFont
.elseif ax == IDM_ABOUT_NOTEPAD
invoke ShellAbout,hWinMain,offset szAbout1,offset szAbout2,hIcon
.elseif ax == IDM_HELP
invoke MessageBox,hWinMain,offset szHelp,offset chengong,MB_OK
.elseif ax == IDM_LINE_WRAP
invoke GetMenuState,hMenu,IDM_LINE_WRAP,MF_BYCOMMAND
.if eax & MF_CHECKED
invoke EnableMenuItem,hMenu,IDM_STATUS_BAR,MF_ENABLED
invoke CheckMenuItem,hMenu,IDM_STATUS_BAR,MF_CHECKED
invoke ShowWindow,hStatusBar,SW_SHOWNORMAL
invoke CheckMenuItem,hMenu,IDM_LINE_WRAP,MF_UNCHECKED
invoke SendMessage,hEdit,EM_GETMODIFY,0,0
.if eax
mov _flag,1
.endif
invoke GetWindowTextLength,hEdit
inc eax
push eax
invoke GlobalAlloc,GPTR,eax
mov _lpMem,eax
pop ecx
invoke GetWindowText,hEdit,_lpMem,ecx
invoke GetClientRect,hWinMain,addr stRt
invoke DestroyWindow,hEdit
invoke CreateWindowEx,0,offset szClass,NULL,\
WS_CHILD OR WS_VISIBLE OR ES_MULTILINE OR ES_WANTRETURN\
OR WS_VSCROLL or ES_NOHIDESEL or ES_AUTOHSCROLL or WS_HSCROLL,\
stRt.left,stRt.top,stRt.right,stRt.bottom,hWinMain,ID_EDIT,hInstance,NULL
mov hEdit,eax
invoke SendMessage,hEdit,EM_LIMITTEXT,0,0
invoke SetWindowText,hEdit,_lpMem
invoke GlobalFree,_lpMem
.if _flag
invoke SendMessage,hEdit,EM_SETMODIFY,TRUE,0
mov _flag,0
.endif
invoke SetFocus,hEdit
invoke _SetFont
.else
invoke CheckMenuItem,hMenu,IDM_STATUS_BAR,MF_UNCHECKED
invoke EnableMenuItem,hMenu,IDM_STATUS_BAR,MF_GRAYED
invoke ShowWindow,hStatusBar,SW_HIDE
invoke CheckMenuItem,hMenu,IDM_LINE_WRAP,MF_CHECKED
invoke SendMessage,hEdit,EM_GETMODIFY,0,0
.if eax
mov _flag,1
.endif
invoke GetWindowTextLength,hEdit
inc eax
push eax
invoke GlobalAlloc,GPTR,eax
mov _lpMem,eax
pop ecx
invoke GetWindowText,hEdit,_lpMem,ecx
invoke GetClientRect,hWinMain,addr stRt
invoke DestroyWindow,hEdit
invoke CreateWindowEx,0,offset szClass,NULL,\
WS_CHILD OR WS_VISIBLE OR ES_MULTILINE OR ES_WANTRETURN\
OR WS_VSCROLL or ES_NOHIDESEL,\
stRt.left,stRt.top,stRt.right,stRt.bottom,hWinMain,ID_EDIT,hInstance,NULL
mov hEdit,eax
invoke SendMessage,hEdit,EM_LIMITTEXT,0,0
invoke SetWindowText,hEdit,_lpMem
invoke GlobalFree,_lpMem
.if _flag
invoke SendMessage,hEdit,EM_SETMODIFY,TRUE,0
mov _flag,0
.endif
invoke SetFocus,hEdit
invoke _SetFont
.endif
call _ReSize
.elseif ax == ID_EDIT
call _SetState
.endif
.elseif eax == WM_SIZE
call _ReSize
.elseif eax == WM_MENUSELECT
invoke MenuHelp,WM_MENUSELECT,wParam,lParam,lParam,hInstance,hStatusBar,offset szMenuHelp
.elseif eax == FrId
.if stFr.Flags & FR_DIALOGTERM
mov hFind,0
.elseif stFr.Flags & FR_REPLACE
.if stFr.Flags & FR_DOWN
invoke _FindReplace
.else
invoke _FindReplace2
.endif
invoke SendMessage,hEdit,EM_GETSEL,addr @stRange.cpMin,addr @stRange.cpMax
mov eax,@stRange.cpMin
.if eax != @stRange.cpMax
invoke SendMessage,hEdit,EM_REPLACESEL,TRUE,offset szReplaceText
.endif
.elseif stFr.Flags & FR_REPLACEALL
.while TRUE
.if stFr.Flags & FR_DOWN
or stFr.Flags,FR_DOWN
invoke _FindReplace
.else
and stFr.Flags,not FR_DOWN
invoke _FindReplace2
.endif
.break .if eax == 0
invoke SendMessage,hEdit,EM_GETSEL,addr @stRange.cpMin,addr @stRange.cpMax
mov eax,@stRange.cpMin
.if eax != @stRange.cpMax
invoke SendMessage,hEdit,EM_REPLACESEL,TRUE,offset szReplaceText
.endif
.endw
.elseif stFr.Flags & FR_DOWN
or stFr.Flags,FR_DOWN
invoke _FindReplace
invoke SendMessage,hEdit,EM_SCROLLCARET,0,0
.else
and stFr.Flags,not FR_DOWN
invoke _FindReplace2
invoke SendMessage,hEdit,EM_SCROLLCARET,0,0
.endif
.elseif eax == WM_INITMENU
call _SetState
.elseif eax == WM_ACTIVATE
mov eax,wParam
.if (ax == WA_ACTIVE) || (ax == WA_CLICKACTIVE)
invoke SetFocus,hEdit
invoke SendMessage,hEdit,EM_SCROLLCARET,0,0
.endif
.elseif eax == WM_NOTIFY
mov ebx,lParam
.if [ebx+NMHDR.code] == TTN_NEEDTEXT
assume ebx : ptr TOOLTIPTEXT
mov eax,[ebx].hdr.idFrom
mov [ebx].lpszText,eax
push hInstance
pop [ebx].hInst
assume ebx : nothing
.endif
.elseif eax == WM_DRAWCLIPBOARD
invoke IsClipboardFormatAvailable,CF_TEXT
.if eax
invoke EnableMenuItem,hMenu,IDM_PASTE,MF_ENABLED
.else
invoke EnableMenuItem,hMenu,IDM_PASTE,MF_GRAYED
.endif
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
xor eax,eax
_OEN: ret
_WndProc endp
;********************************************************************
_WinMain proc
local stWndClass:WNDCLASSEX
local stMsg:MSG
local @hAccelerators
invoke InitCommonControls
invoke GetModuleHandle,NULL
mov hInstance,e, ax
invoke LoadMenu,hInstance,IDM_MAIN
mov hMenu,eax
invoke LoadAccelerators,hInstance,IDA_MAIN
mov @hAccelerators,eax
invoke RtlZeroMemory,addr stWndClass,sizeof WNDCLASSEX
push hInstance
pop stWndClass.hInstance
invoke LoadIcon,hInstance,IDC_MAIN
mov hIcon,eax
mov stWndClass.hIcon,eax
mov stWndClass.hIconSm,eax
invoke LoadCursor,0,IDC_ARROW
mov stWndClass.hCursor,eax
mov stWndClass.cbSize,sizeof WNDCLASSEX
mov stWndClass.lpfnWndProc,offset _WndProc
mov stWndClass.lpszClassName,offset szClassName
mov stWndClass.style,CS_HREDRAW or CS_VREDRAW
mov stWndClass.hbrBackground,COLOR_BTNFACE+1
invoke RegisterClassEx,addr stWndClass
invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,offset szCaption,\
WS_OVERLAPPEDWINDOW,100,80,600,\
400,NULL,hMenu,hInstance,NULL
.if eax
mov hWinMain,eax
.else
ret
.endif
invoke ShowWindow,hWinMain,SW_SHOWNORMAL
invoke UpdateWindow,hWinMain
.while TRUE
invoke GetMessage,addr stMsg,NULL,0,0
.break .if eax == 0
invoke TranslateAccelerator,hWinMain,@hAccelerators,addr stMsg
.if eax == 0
invoke TranslateMessage,addr stMsg
invoke DispatchMessage,addr stMsg
.endif
.endw
ret
_WinMain endp
;********************************************************************
start: call _WinMain
invoke ExitProcess,NULL
end start