📄 jsb.asm
字号:
.386
.model flat,stdcall
option casemap:none
include JSB.Inc
.code
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
; invoke InitCommonControls
mov iccex.dwSize,sizeof INITCOMMONCONTROLSEX ;prepare common control structure
mov iccex.dwICC,ICC_DATE_CLASSES
invoke InitCommonControlsEx,addr iccex
invoke LoadMenu,hInstance,IDM_MENU
mov hMenu,eax
invoke LoadLibrary,addr RichEditDLL
mov hRichEdDLL,eax
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
push eax
invoke FreeLibrary,hRichEdDLL
pop eax
invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style,CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc,OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,DLGWINDOWEXTRA
push hInst
pop wc.hInstance
mov wc.hbrBackground,NULL
mov wc.lpszMenuName,IDM_MENU
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov hIcon,eax
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx,addr wc
invoke CreateDialogParam,hInstance,IDD_DLG,NULL,addr WndProc,NULL
mov hWnd,eax
invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd
.while TRUE
invoke GetMessage,addr msg,NULL,0,0
.break .if !eax
invoke IsDialogMessage,hFind,addr msg
.if !eax
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
.endif
.endw
mov eax,msg.wParam
ret
WinMain endp
StreamInProc proc hFile:DWORD,pBuffer:DWORD,NumBytes:DWORD,pBytesRead:DWORD
invoke ReadFile,hFile,pBuffer,NumBytes,pBytesRead,0
xor eax,1
ret
StreamInProc endp
StreamOutProc proc hFile:DWORD,pBuffer:DWORD,NumBytes:DWORD,pBytesWritten:DWORD
invoke WriteFile,hFile,pBuffer,NumBytes,pBytesWritten,0
xor eax,1
ret
StreamOutProc endp
SetWinCaption proc
LOCAL buffer[sizeof AppName+3+MAX_PATH]:BYTE
LOCAL buffer1[4]:BYTE
;Add filename to windows caption
invoke lstrcpy,addr buffer,addr AppName
mov eax,' - '
mov dword ptr buffer1,eax
invoke lstrcat,addr buffer,addr buffer1
invoke lstrcat,addr buffer,addr FileName
invoke SetWindowText,hWnd,addr buffer
ret
SetWinCaption endp
SaveFile proc lpFileName:DWORD
LOCAL hFile:DWORD
LOCAL editstream:EDITSTREAM
invoke CreateFile,lpFileName,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
.if eax!=INVALID_HANDLE_VALUE
mov hFile,eax
;stream the text to the file
mov editstream.dwCookie,eax
mov editstream.pfnCallback,offset StreamOutProc
invoke SendMessage,hREd,EM_STREAMOUT,SF_TEXT,addr editstream
invoke CloseHandle,hFile
;Set the modify state to false
invoke SendMessage,hREd,EM_SETMODIFY,FALSE,0
invoke _SetStatus
mov eax,FALSE
.else
invoke MessageBox,hWnd,addr SaveFileFail,addr AppName,MB_OK
mov eax,TRUE
.endif
ret
SaveFile endp
SaveEditAs proc
LOCAL ofn:OPENFILENAME
LOCAL buffer[MAX_PATH]:BYTE
;Zero out the ofn struct
invoke RtlZeroMemory,addr ofn,sizeof ofn
;Setup the ofn struct
mov ofn.lStructSize,sizeof ofn
push hWnd
pop ofn.hwndOwner
push hInstance
pop ofn.hInstance
mov ofn.lpstrFilter,offset EditFilterString
mov buffer[0],0
lea eax,buffer
mov ofn.lpstrFile,eax
mov ofn.nMaxFile,sizeof buffer
mov ofn.Flags,OFN_FILEMUSTEXIST or OFN_HIDEREADONLY or OFN_PATHMUSTEXIST or OFN_OVERWRITEPROMPT
mov ofn.lpstrDefExt,NULL
;Show save as dialog
invoke GetSaveFileName,addr ofn
.if eax
invoke SaveFile,addr buffer
.if !eax
;The file was saved
invoke lstrcpy,addr FileName,addr buffer
invoke SetWinCaption
invoke _SetStatus
mov eax,FALSE
.endif
.else
mov eax,TRUE
.endif
ret
SaveEditAs endp
SaveEdit proc
;Check if filrname is (Untitled)
invoke lstrcmp,addr FileName,addr NewFile
.if eax
invoke SaveFile,addr FileName
.else
invoke SaveEditAs
.endif
ret
SaveEdit endp
WantToSave proc
LOCAL buffer[512]:BYTE
LOCAL buffer1[2]:BYTE
invoke SendMessage,hREd,EM_GETMODIFY,0,0
.if eax
invoke lstrcpy,addr buffer,addr WannaSave
invoke lstrcat,addr buffer,addr FileName
mov ax,'?'
mov word ptr buffer1,ax
invoke lstrcat,addr buffer,addr buffer1
invoke MessageBox,hWnd,addr buffer,addr AppName,MB_YESNOCANCEL or MB_ICONQUESTION
.if eax==IDYES
invoke SaveEdit
.elseif eax==IDNO
mov eax,FALSE
.else
mov eax,TRUE
.endif
.endif
ret
WantToSave endp
OpenEdit proc
LOCAL ofn:OPENFILENAME
LOCAL hFile:DWORD
LOCAL editstream:EDITSTREAM
LOCAL buffer[MAX_PATH]:BYTE
LOCAL chrg:CHARRANGE
;Zero out the ofn struct
invoke RtlZeroMemory,addr ofn,sizeof ofn
;Setup the ofn struct
mov ofn.lStructSize,sizeof ofn
push hWnd
pop ofn.hwndOwner
push hInstance
pop ofn.hInstance
mov ofn.lpstrFilter,offset EditFilterString
mov buffer[0],0
lea eax,buffer
mov ofn.lpstrFile,eax
mov ofn.nMaxFile,sizeof buffer
mov ofn.lpstrDefExt,NULL
mov ofn.Flags,OFN_FILEMUSTEXIST or OFN_HIDEREADONLY or OFN_PATHMUSTEXIST
;Show the Open dialog
invoke GetOpenFileName,addr ofn
.if eax
;Open the file
invoke CreateFile,addr buffer,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
.if eax!=INVALID_HANDLE_VALUE
mov hFile,eax
;Copy buffer to FileName
invoke lstrcpy,addr FileName,addr buffer
;stream the text into the richedit control
push hFile
pop editstream.dwCookie
mov editstream.pfnCallback,offset StreamInProc
invoke SendMessage,hREd,EM_STREAMIN,SF_TEXT,addr editstream
invoke CloseHandle,hFile
invoke SendMessage,hREd,EM_SETMODIFY,FALSE,0
mov chrg.cpMin,0
mov chrg.cpMax,0
invoke SendMessage,hREd,EM_EXSETSEL,0,addr chrg
invoke SetWinCaption
invoke _SetStatus
mov eax,FALSE
.else
invoke MessageBox,hWnd,addr OpenFileFail,addr AppName,MB_OK
mov eax,TRUE
.endif
.endif
ret
OpenEdit endp
FindDlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM ;查找函数过程
LOCAL hCtl:DWORD
LOCAL @setText:SETTEXTEX
LOCAL @Buffer[256]:BYTE
mov eax,uMsg
.if eax==WM_INITDIALOG
mov eax,hWin
mov hFind,eax
.if !lParam
;Disable replace
invoke GetDlgItem,hWin,IDC_REPLACETEXT
mov hCtl,eax
invoke GetWindowLong,hCtl,GWL_STYLE
xor eax,WS_VISIBLE
invoke SetWindowLong,hCtl,GWL_STYLE,eax
invoke GetDlgItem,hWin,IDC_REPLACESTATIC
mov hCtl,eax
invoke GetWindowLong,hCtl,GWL_STYLE
xor eax,WS_VISIBLE
invoke SetWindowLong,hCtl,GWL_STYLE,eax
;invoke GetDlgItem,hWin,IDC_BTN_REPLACEALL
;invoke EnableWindow,eax,FALSE
invoke GetDlgItem,hWin,IDC_RBN_DOWN
invoke CheckRadioButton,hWin,IDC_RBN_DOWN,IDC_RBN_UP,IDC_RBN_DOWN
invoke SendDlgItemMessage,hWin,IDC_FINDTEXT,WM_SETTEXT,0,addr szFindText
invoke SendDlgItemMessage,hWin,IDC_REPLACETEXT,WM_SETTEXT,0,addr szReplaceText
.else
invoke SetWindowText,hWin, addr Replace
.endif
.elseif eax==WM_COMMAND
mov eax,wParam
mov edx,eax
shr edx,16
and eax,0FFFFh
.if edx==BN_CLICKED
.if eax==IDC_FINDTEXT
mov uFlags,0
invoke SendMessage,hREd,EM_EXGETSEL,0,addr stFindText.chrg
invoke GetDlgItemText,hWin,IDC_FINDTEXT,addr szFindText,sizeof szFindText
.if eax!=0
invoke IsDlgButtonChecked,hWin,IDC_RBN_DOWN
.if eax==BST_CHECKED
or uFlags,FR_DOWN
mov eax,stFindText.chrg.cpMin
.if eax!=stFindText.chrg.cpMax
push stFindText.chrg.cpMax
pop stFindText.chrg.cpMin
.endif
mov stFindText.chrg.cpMax,-1
.else
mov stFindText.chrg.cpMax,0
.endif
invoke IsDlgButtonChecked,hWin,IDC_CHK_MATCHCASE
.if eax==BST_CHECKED
or uFlags,FR_MATCHCASE
.endif
invoke IsDlgButtonChecked,hWin,IDC_CHK_WHOLEWORD
.if eax==BST_CHECKED
or uFlags,FR_WHOLEWORD
.endif
mov stFindText.lpstrText,offset szFindText
invoke SendMessage,hREd,EM_FINDTEXTEX,uFlags,addr stFindText
.if eax==-1
mov ecx,hWnd
.if hFind
mov ecx,hFind
.endif
invoke MessageBox,ecx,addr szNotFound,NULL,MB_OK
ret
.endif
invoke SendMessage,hREd,EM_EXSETSEL,0,addr stFindText.chrgText
invoke SendMessage,hREd,EM_SCROLLCARET,NULL,NULL
.endif
.elseif eax==IDC_BTN_REPLACEALL
push ebx
xor ebx,ebx
invoke SendMessage,hREd,EM_EXGETSEL,0,addr stFindText.chrg
invoke GetDlgItemText,hWin,IDC_FINDTEXT,addr szFindText,sizeof szFindText
invoke GetDlgItemText,hWin,IDC_REPLACETEXT,addr szReplaceText,sizeof szReplaceText
mov stFindText.chrg.cpMin,0
mov stFindText.chrg.cpMax,-1
mov stFindText.lpstrText,offset szFindText
mov @setText.flags,ST_SELECTION
mov @setText.codepage,CP_ACP
.while TRUE
invoke SendMessage,hREd,EM_FINDTEXTEX,FR_DOWN,addr stFindText
.if eax==-1
.break
.else
invoke SendMessage,hREd,EM_EXSETSEL,0,addr stFindText.chrgText
invoke SendMessage,hREd,EM_SETTEXTEX,addr @setText,addr szReplaceText
inc ebx
.endif
.endw
invoke wsprintf,addr @Buffer,addr szReplaceMessage,ebx
invoke MessageBox,hWin,addr @Buffer,addr AppName,MB_OK
pop ebx
ret
.elseif eax==IDC_BTN_REPLACE
mov uFlags,0
invoke SendMessage,hREd,EM_EXGETSEL,0,addr stFindText.chrg
invoke GetDlgItemText,hWin,IDC_FINDTEXT,addr szFindText,sizeof szFindText
invoke GetDlgItemText,hWin,IDC_REPLACETEXT,addr szReplaceText,sizeof szReplaceText
.if eax!=0
invoke IsDlgButtonChecked,hWin,IDC_RBN_DOWN
.if eax==BST_CHECKED
or uFlags,FR_DOWN
mov eax,stFindText.chrg.cpMin
.if eax!=stFindText.chrg.cpMax
push stFindText.chrg.cpMax
pop stFindText.chrg.cpMin
.endif
mov stFindText.chrg.cpMax,-1
.else
mov stFindText.chrg.cpMax,0
.endif
invoke IsDlgButtonChecked,hWin,IDC_CHK_MATCHCASE
.if eax==BST_CHECKED
or uFlags,FR_MATCHCASE
.endif
invoke IsDlgButtonChecked,hWin,IDC_CHK_WHOLEWORD
.if eax==BST_CHECKED
or uFlags,FR_WHOLEWORD
.endif
mov stFindText.lpstrText,offset szFindText
invoke SendMessage,hREd,EM_FINDTEXTEX,uFlags,addr stFindText
.if eax==-1
mov ecx,hWnd
.if hFind
mov ecx,hFind
.endif
invoke MessageBox,ecx,addr szNotFound,NULL,MB_OK
ret
.endif
invoke SendMessage,hREd,EM_EXSETSEL,0,addr stFindText.chrgText
invoke SendMessage,hREd,EM_SCROLLCARET,NULL,NULL
.endif
invoke SendMessage,hREd,EM_EXSETSEL,0,addr stFindText.chrgText
invoke SendMessage,hREd,EM_SETTEXTEX,addr @setText,addr szReplaceText
.elseif eax==IDCANCEL
invoke SendMessage,hWin,WM_CLOSE,NULL,NULL
.endif
.endif
.elseif eax==WM_CLOSE
mov hFind,0
invoke EndDialog,hWin,NULL
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -