📄 ewcalc.asm
字号:
.code
start:
call InitCommonControls ;Initialize the common ctrl lib
INVOKE GetModuleHandle, 0
mov hInst,eax ;hInstance is same as HMODULE
INVOKE GetCommandLine
mov CommandLine, eax
INVOKE WinMain, hInst, NULL, CommandLine, SW_SHOWDEFAULT
INVOKE ExitProcess, msg.wParam
;=========================================================================|
; WinMain Procedure |
;=========================================================================|
WinMain PROC hinst:DWORD, hPrevInst:DWORD, CmdLine:DWORD, CmdShow:DWORD
;**********************
;* Initialize the WndClass structure and register the class name
;**********************
mov wc.style,CS_HREDRAW or CS_VREDRAW or CS_GLOBALCLASS
mov wc.lpfnWndProc,offset WndProc
mov wc.cbClsExtra,0
mov wc.cbWndExtra,0
mov eax,hInst
mov wc.hInstance,eax
INVOKE LoadIcon, eax, IDI_ICON1
mov wc.hIcon,eax
INVOKE LoadCursor, 0, IDC_ARROW
mov wc.hCursor,eax
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName, 0
mov wc.lpszClassName, offset class
INVOKE RegisterClass, offset wc
INVOKE LoadMenu, hInst, IDR_MENU1
mov hMenu, eax
INVOKE CreateWindowEx,0,ADDR class,ADDR TB,
WS_OVERLAPPED or WS_CAPTION or WS_SYSMENU or WS_MINIMIZEBOX,
200,68,460,262,NULL,hMenu,hinst,NULL ;450
mov hWnd,eax
INVOKE ShowWindow, hWnd,SW_SHOWNORMAL
INVOKE UpdateWindow, hWnd
INVOKE SetWindowPos, hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW
BeginLoop:
INVOKE GetMessage, offset msg, 0, 0, 0
cmp eax,0
je EndLoop
INVOKE TranslateMessage, offset msg
INVOKE DispatchMessage, offset msg
jmp BeginLoop
EndLoop:
RET
WinMain ENDP
;=========================================================================|
; WinProc Procedure |
;=========================================================================|
WndProc PROC uses ebx edi esi, hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
mov eax,wmsg
cmp eax,WM_CREATE
je wmcreate
cmp eax,WM_COMMAND
je wmcommand
cmp eax,WM_CLOSE
je wmdestroy
cmp eax,WM_NOTIFY
je wmnotify
.if wmsg == WM_KEYDOWN
INVOKE SetFocus, hEdit
.endif
jmp defwndproc
wmcommand:
mov eax,wparam
cwde ; Only low word contains command
cmp eax,IDM_CLOSE
je wmdestroy
cmp eax,IDM_INFO
je idminfo
cmp eax,IDM_ABOUT
je idmabout
cmp eax, 1
je wmbs
cmp eax, 2
je wmce
cmp eax, 3
je wmclr
.if eax == 19
mov T, 1
INVOKE SendMessage, hRad, BM_SETCHECK, BST_UNCHECKED, 0 ; Sets rad to unchecked
.endif
.if eax == 20
mov T, 2
INVOKE SendMessage, hDeg, BM_SETCHECK, BST_UNCHECKED, 0 ; Sets deg to unchecked
.endif
; -------* 21=Dec * 22=Hex * 23=Oct * 24=Bin *-------
and sw2, 0
.if eax == 21 ; Dec
.if Base != 10
MOVmd PrevBase, Base
mov Base, 10
mov sw2, 10
call DsplyConv
.endif
.endif
.if eax == 22 ; Hex
.if Base != 16
MOVmd PrevBase, Base
mov Base, 16
mov sw2, 16
call DsplyConv
.endif
.endif
.if eax == 23 ; Oct
.if Base != 8
MOVmd PrevBase, Base
mov Base, 8
mov sw2, 8
call DsplyConv
.endif
.endif
.if eax == 24 ; Bin
.if Base != 2
MOVmd PrevBase, Base
mov Base, 2
mov sw2, 2
call DsplyConv
.endif
.endif
.if eax > 20 && eax < 25
and I, 0
.endif
.if eax == 43
and Float, 0
INVOKE SendMessage, hFloat, BM_GETCHECK, 0, 0
.if eax == 1
or Float, 1
.endif
jmp wmclr
.endif
.if eax == 50
and ArcOn, 0
INVOKE SendMessage, hArc, BM_GETCHECK, 0, 0
.if eax == 1
or ArcOn, 1
.endif
.endif
jmp defwndproc
wmcreate:
INVOKE GetSysColor, COLOR_MENU
mov BackGC, eax
INVOKE lstrcpy, ADDR lf.lfFaceName, ADDR FontName
mov lf.lfHeight, -12
mov lf.lfWeight, 500
INVOKE CreateFontIndirect, ADDR lf
mov hFont,eax
INVOKE lstrcpy, ADDR lf.lfFaceName, ADDR FontName1
mov lf.lfHeight, -12
mov lf.lfWeight, 500
INVOKE CreateFontIndirect, ADDR lf
mov hDspF,eax
INVOKE CreateWindowEx,NULL, ADDR Butt,ADDR float,
WS_CHILD or WS_VISIBLE or BS_AUTOCHECKBOX,
4,4,130,12,hwnd,43,hInst,NULL ; Floating Point
mov hFloat, eax
INVOKE SendMessage, hFloat, WM_SETFONT, hFont, 0
INVOKE CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditPT,NULL,
WS_CHILD or WS_VISIBLE or WS_BORDER or ES_RIGHT or ES_AUTOHSCROLL,
135,0,315,22,hwnd,44,hInst,NULL ; Edit window
mov hEdit,eax
INVOKE SetWindowLong, hEdit, GWL_WNDPROC, EditProc
mov SubEdit, eax
INVOKE CreateWindowEx,NULL, ADDR Butt,ADDR arc,
WS_CHILD or WS_VISIBLE or BS_AUTOCHECKBOX,
182,32,40,12,hwnd,50,hInst,NULL ; Arc for trig
mov hArc, eax
INVOKE SendMessage, hArc, WM_SETFONT, hFont, 0
INVOKE CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditPT,NULL,
WS_CHILD or WS_VISIBLE or WS_BORDER or ES_CENTER or ES_READONLY,
239,26,25,21,hwnd,88,hInst,NULL ; Memory window
mov hMem,eax
INVOKE CreateWindowEx,NULL, ADDR Butt, ADDR BackS,
WS_CHILD or WS_VISIBLE,
271,26,80,20,hwnd,1,hInst,NULL ; Backspace button
mov hBkSp, eax
INVOKE SendMessage, hBkSp, WM_SETFONT, hFont, 0
INVOKE CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditPT,NULL,
WS_CHILD or WS_VISIBLE or WS_BORDER or ES_CENTER or ES_READONLY,
363,26,25,21,hwnd,89,hInst,NULL ; Operator window
mov hOpr,eax
INVOKE CreateWindowEx,NULL, ADDR Butt,ADDR CE,
WS_CHILD or WS_VISIBLE,
399,26,20,20,hwnd,2,hInst,NULL ; Clear error button
mov hCE, eax
INVOKE SendMessage, hCE, WM_SETFONT, hFont, 0
INVOKE CreateWindowEx,NULL, ADDR Butt,ADDR CLR,
WS_CHILD or WS_VISIBLE,
429,26,20,20,hwnd,3,hInst,NULL ; Clear button
mov hCLR, eax
INVOKE SendMessage, hCLR, WM_SETFONT, hFont, 0
;--------[ Check boxes and radio buttons ]-----------------------------
INVOKE CreateWindowEx,NULL, ADDR Butt,0,
WS_CHILD or WS_VISIBLE or BS_GROUPBOX,
178,43,85,28,hwnd,14,hInst,NULL ; Deg & Rad group box
INVOKE CreateWindowEx,NULL, ADDR Butt,0,
WS_CHILD or WS_VISIBLE or BS_GROUPBOX,
271,43,178,28,hwnd,15,hInst,NULL ; Base group box
xor ebx, ebx
mov XP, 182
mov N, 19
BuildRadio:
.if N < 21
INVOKE CreateWindowEx,NULL, ADDR Butt,ADDR DegT[ebx],
WS_CHILD or WS_VISIBLE or BS_AUTOCHECKBOX,
XP,55,39,12,hwnd,N,hInst,NULL ; Deg & Rad check boxes
sub XP, 3
.else
INVOKE CreateWindowEx,NULL, ADDR Butt,ADDR DegT[ebx],
WS_CHILD or WS_VISIBLE or BS_AUTORADIOBUTTON,
XP,55,40,12,hwnd,N,hInst,NULL ; Base radio buttons
.endif
mov hDeg[ebx], eax
INVOKE SendMessage, hDeg[ebx], WM_SETFONT, hFont, 0
.if N < 24
add ebx, 4
add N, 1
.if N == 21
add XP, 13
.endif
add XP, 43
jmp BuildRadio
.endif
INVOKE SendMessage, hDeg, BM_SETCHECK, BST_CHECKED, 0 ; Sets deg to checked
INVOKE SendMessage, hDec, BM_SETCHECK, BST_CHECKED, 0 ; Sets dec to checked
;--------[ Toolbars ]--------------------------------------------------
xor ebx, ebx
mov XP, 178
mov YP, 74
mov Row, 0
mov I, 9
mov N, 17
mov W, 272
BuildTB:
INVOKE CreateWindowEx,NULL, ADDR Stat, 0,
WS_CHILD or WS_VISIBLE,
XP,YP,W,24,hwnd,1,hInst,NULL ; Toolbars
mov hTB01,eax
INVOKE SetWindowLong, hTB01, GWL_WNDPROC, ToolbarProc
mov SubTool, eax
INVOKE CreateToolbarEx,hTB01,WS_CHILD or WS_VISIBLE or CCS_NODIVIDER,
IDT[ebx],I, hInst, IDT[ebx], tb[ebx], N, 16, 16, 16, 16, tbl[ebx]
.if Row < 4
add ebx, 4
add YP, 29
add Row, 1
jmp BuildTB
.endif
and I, 0
;--------[ Display area ]----------------------------------------------
INVOKE CreateWindowEx,NULL, ADDR Butt,0,
WS_CHILD or WS_VISIBLE or BS_GROUPBOX,
4,18,161,196,hwnd,55,hInst,NULL ; Display area
mov hDspl, eax
jmp returnP
wmnotify:
jmp returnP
idminfo:
INVOKE MessageBox,NULL, offset Info, offset AppName, MB_OK
jmp returnP
idmabout:
mov eax, offset InfoAbDlg
mov ebx, IDD_ABOUT
jmp DialogBox
DialogBox: ;modal dialog box
INVOKE DialogBoxParam, hInst, ebx, hwnd, eax, 0
jmp returnP
wmbs: ; Backspace
INVOKE SendMessage, hEdit, WM_GETTEXT, 35, ADDR Buff
INVOKE lstrlen, ADDR Buff
.if eax == 0
jmp returnP
.endif
INVOKE lstrcpyn, ADDR ConvO, ADDR Buff, eax
INVOKE SendMessage, hEdit, WM_SETTEXT, NULL, ADDR ConvO
INVOKE SendMessage, hEdit, EM_SETSEL, 33, 33
INVOKE SetFocus, hWnd
INVOKE lstrcpy, ADDR Buff, ADDR ConvO
call AsciiToBase
INVOKE lstrcpy, ADDR Buff, ADDR ConvO
call AsciiToFloat
mov edx, offset RNum10
call FloatToAscii
call Display
jmp returnP
wmce: ; Clear error
mov ConvO, 0h
INVOKE SendMessage, hEdit, WM_SETTEXT, NULL, offset ConvO
INVOKE SetFocus, hWnd
jmp returnP
wmclr: ; Clears all Fields
mov ConvO, 0
mov Buff, 0
mov LBuff, 0
mov RBuff, 0
mov PLBuff, 0
mov PRBuff, 0
and HPress, 0
and NPress, 0
and RPress, 0
and BPress, 0 ; 1=add, 2=sub, 3=mul, 4=div
and DP, 0
INVOKE SendMessage, hEdit, WM_SETTEXT, NULL, offset ConvO
INVOKE SetFocus, hWnd
INVOKE SendMessage, hOpr, WM_SETTEXT, NULL, ADDR Clear
mov Len, 0
INVOKE CLRMW, offset R, 32
call Display
and First, 0
fldz
fstp RNum10
fldz
fstp RWrk10
jmp returnP
;******************************************************************************
defwndproc:
INVOKE DefWindowProc, hwnd, wmsg, wparam, lparam
jmp finish
wmdestroy:
push 0
call PostQuitMessage ; Quit
jmp returnP
returnP: xor eax,eax
finish: RET
WndProc ENDP
;=========================================================================|
; About Box Dialog Procedure. |
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -