📄 calc.asm
字号:
_DlgCalcProc proto :DWORD,:DWORD,:DWORD,:DWORD
.data
szcalcop db '+',0,'-',0,'*',0,'/',0,'mod',0
db 'and',0,'or',0,'xor',0
db 'shl',0,'shr',0,'rol',0,'ror',0
db 'neg',0,'not',0
db 0
szkey_calc db 'calc_by',0
__calc_disablewindow macro @id
invoke GetDlgItem,@hDlg,@id
invoke EnableWindow,eax,FALSE
endm
__calc_calc macro n,m
.if ebx==0
add n,m
.elseif ebx==1
sub n,m
.elseif ebx==2
mul m
.elseif ebx==3 && cl ;除法操作,防止除0
xor edx,edx
div m
.elseif ebx==4 && cl;求余,防止除0
xor edx,edx
div m
mov eax,edx
.elseif ebx==5;and
and n,m
.elseif ebx==6
or n,m
.elseif ebx==7
xor n,m
.elseif ebx==8
shl n,cl
.elseif ebx==9
shr n,cl
.elseif ebx==10
rol n,cl
.elseif ebx==11
ror n,cl
.elseif ebx==12
neg n
.elseif ebx==13
not n
.endif
endm
.data?
wCalcType dw ?
.CODE
_DlgCalcProc proc uses ebx ecx edx edi @hDlg,uMsg,wParam,lParam
local @szBuf[255]:BYTE
mov eax,uMsg
.if eax==WM_INITDIALOG
lea edi,szcalcop
.while BYTE ptr [edi]
__senddlgmessage 1005,CB_ADDSTRING ,0,edi
invoke lstrlen,edi
add edi,eax
inc edi
.endw
__senddlgmessage 1002,BM_SETCHECK ,1
__senddlgmessage 1005,CB_SETCURSEL
mov eax,dwFileSize
sub eax,dwCurPos
.if eax==0
__calc_disablewindow 1004
__calc_disablewindow 1003
.elseif eax<=3
__calc_disablewindow 1004
.endif
mov wCalcType,1002
invoke _IniSet2Default
invoke _IniGetStr2Edit,@hDlg,1007,0,addr szkey_calc
mov eax,dwCurPos
mov dwBlockStart,eax
mov dwBlockEnd,eax
call _ReDraw
.elseif eax==WM_COMMAND
mov eax,wParam
.if ax==1008
invoke _GetInt,@hDlg,1007
push eax
__senddlgmessage 1005,CB_GETCURSEL
mov ebx,eax
pop ecx
mov eax,dwCurPos
add eax,lpMemFile
mov edi,eax
mov eax,[eax]
.if wCalcType==1002
and eax,0ffh
__calc_calc al,cl
invoke _PushUndo,edi,UNDO_INPUT,NULL,NULL
stosb
.elseif wCalcType==1003
__calc_calc ax,cx
invoke _PushUndo,edi,UNDO_REPLACE,2,NULL
stosw
.else
__calc_calc eax,ecx
invoke _PushUndo,edi,UNDO_REPLACE,4,NULL
stosd
.endif
call _ReDraw
.elseif ax>=1002 && ax<=1004
mov wCalcType,ax
.if ax==1002
xor eax,eax
.elseif ax==1003
mov eax,1
.else
mov eax,3
.endif
add eax,dwBlockStart
mov dwBlockEnd,eax
call _ReDraw
.else
shr eax,16
.if ax==CBN_SELCHANGE ;neg,not只要一个操作数
__senddlgmessage 1005,CB_GETCURSEL
.if eax>=12;12-neg,13-not
push FALSE
.else
push TRUE
.endif
invoke GetDlgItem,@hDlg,1007
push eax
call EnableWindow
.endif
.endif
.elseif eax==WM_CLOSE
invoke _IniSetStrFromEdit,@hDlg,1007,0,addr szkey_calc
invoke EndDialog,@hDlg,0
.else
xor eax,eax
ret
.endif
mov eax,TRUE
ret
_DlgCalcProc endp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -