?? 源程序.txt
字號:
; #########################################################################
.386
.model flat, stdcall
option casemap :none ; case sensitive
; #########################################################################
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\masm32.lib
; #########################################################################
;=============
; Local macros
;=============
szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM
;=================
; Local prototypes
;=================
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
EditProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
hWnd dd 0
hEdit1 dd 0
hEdit2 dd 0
hEdit3 dd 0
hButn1 dd 0
hButn2 dd 0
hInstance dd 0
hIconImage dd 0
hIcon dd 0
lpfnEditProc dd 0;/////////////////////////////
dlgname db "TESTWIN",0
fMtStrinG db "%lu",0 ; this is for wsprintf
AppName db "Get Value Dialog Box",0;`````````````````````````
;-----------------------------------------------------------
.data?
;hInstance HINSTANCE ?
CommandLine LPSTR ?
buffer db 512 dup(?)
;-------------------------------------------------------------
.const
IDR_MENU1 equ 32000
IDM_GETTEXT equ 32001
IDM_CLEAR_INPUT1 equ 32002
IDM_CLEAR_INPUT2 equ 32003
IDM_EXIT equ 32004
IDC_EDIT1 equ 100
IDC_EDIT2 equ 101
IDC_EDIT3 equ 102
IDC_CACULATE equ 1000
IDC_EXIT equ 1001
; #########################################################################
.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
; -------------------------------------------
; Call the dialog box stored in resource file
; -------------------------------------------
;invoke DialogBoxParam,hInstance,ADDR dlgname,0,ADDR WndProc,0
invoke DialogBoxParam, hInstance, ADDR dlgname,NULL,addr WndProc,NULL
invoke ExitProcess,eax
; #########################################################################
WndProc proc hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD
;WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL TheValue :DWORD
LOCAL inBuffer1[64] :BYTE ; stack as they are more
LOCAL inBuffer2[64]:BYTE ; efficient with file size.
LOCAL outBuffer[64]:BYTE
.if uMsg == WM_INITDIALOG ; set up required items at startup
mov eax, hWin
mov hWnd, eax
szText dlgTitle,"Caculate Sum"
invoke SendMessage,hWin,WM_SETTEXT,0,ADDR dlgTitle;給標題命名
invoke LoadIcon,hInstance,200
mov hIcon, eax ;加載應用程序的圖標
invoke SendMessage,hWin,WM_SETICON,1,hIcon
; --------------------
; edit control handles
; --------------------
invoke GetDlgItem,hWin,100; 100 is id of edit distriction
mov hEdit1, eax
invoke SetWindowLong,hEdit1,GWL_WNDPROC,EditProc ; subclass 1st one so text can be filtered
mov lpfnEditProc, eax
invoke GetDlgItem,hWin,101
mov hEdit2, eax
invoke SetWindowLong,hEdit2,GWL_WNDPROC,EditProc
mov lpfnEditProc, eax
;---------------------------------------
invoke GetDlgItem,hWin,102 ;EDIT3 IS ONLY DISPLAY
mov hEdit3, eax
; --------------
; button handles
; --------------
invoke GetDlgItem,hWin,1000
mov hButn1, eax
invoke GetDlgItem,hWin,1001
mov hButn2, eax
; -----------------------------------------
; process the messages from the two buttons
; -----------------------------------------
.elseif uMsg == WM_COMMAND;
mov eax,wParam;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.IF lParam==0;menu
.IF ax==IDM_GETTEXT ;;; i can replace it with outBuffer
invoke GetDlgItemText,hWnd,IDC_EDIT3,ADDR buffer,512;獲取輸出的文本
invoke MessageBox,NULL,ADDR buffer ,ADDR AppName,MB_OK
.ELSEIF ax==IDM_CLEAR_INPUT1;
invoke SetDlgItemText,hWnd,IDC_EDIT1,NULL;CLEAR INPUT1
.ELSEIF ax==IDM_CLEAR_INPUT2;
invoke SetDlgItemText,hWnd,IDC_EDIT2,NULL;CLEAR INPUT2
.ELSEIF ax==IDM_EXIT
invoke EndDialog, hWnd,NULL
.ENDIF
.ELSE;BUTTON
.if wParam == 1000 ; convert 1st text
invoke GetWindowText,hEdit1,ADDR inBuffer1,40;將1中text輸入緩沖區
; ------------------------
; text is now in inBuffer,
; test if its blank.
; ------------------------
lea esi, inBuffer1 ; get 1st byte
lodsb
cmp al, 0 ; see if its ascii zero
jne @F
invoke SetFocus,hEdit1
xor eax, eax ; return zero if blank
ret
@@:
invoke atodw,ADDR inBuffer1 ; convert text to DWORD
mov TheValue, eax ;存1的結果
;------------------------------------------------------------------
invoke GetWindowText,hEdit2,ADDR inBuffer2,40 ;將2中text輸入緩沖區
; ------------------------
; text is now in inBuffer,
; test if its blank.
; ------------------------
lea esi, inBuffer2 ; get 2st byte
lodsb
cmp al, 0 ; see if its ascii zero
jne @F
invoke SetFocus,hEdit2
xor eax, eax ; return zero if blank
ret
@@:
invoke atodw,ADDR inBuffer2 ; convert text to DWORD value
ADD TheValue, eax ;MAKE THE SUM
; -------------------------------------------------------------
; Do the function call here for the numeric conversion you need
; using the DWORD value converted from the text input. When it
; is done, use the following conversion of the result back to
; text and display it in the second edit control.
; -------------------------------------------------------------
invoke wsprintf,ADDR outBuffer,ADDR fMtStrinG,TheValue;結果輸出到緩沖區
invoke SetWindowText,hEdit3,ADDR outBuffer
.elseif wParam == 1001 ; the exit button
jmp GetOutaHere
.endif;1000 OR 1001
.endif;MENU AND BUTTON
.elseif uMsg == WM_CLOSE ; for system close button
GetOutaHere:
invoke EndDialog,hWin,0
; .endif;
.endif;uMsg
xor eax, eax ; this must be here in NT4
ret
WndProc endp
; #########################################################################
EditProc proc hCtl :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD
LOCAL tl:DWORD
LOCAL testBuffer[16]:BYTE
; -----------------------------
; Process control messages here
; -----------------------------
.if uMsg == WM_CHAR
.if wParam == 8 ; allow backspace
jmp @F ; jump FORWORD to next @@:
.endif
invoke GetWindowText,hCtl,ADDR testBuffer,16
invoke lnstr,ADDR testBuffer
.if eax >= 10 ; restrict length to 10 digits
xor eax, eax
ret
.endif
; ------------------
; allow numbers only
; ------------------
.if wParam > 57
xor eax, eax
ret
.elseif wParam < 48
xor eax, eax
ret
.endif
@@:
.endif
invoke CallWindowProc,lpfnEditProc,hCtl,uMsg,wParam,lParam
ret
EditProc endp
; #########################################################################
end start
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -