在看罗云斌大哥的32汇编。看到第9章的时候有个Subclass的小程序。想自己动手写个将十六进制转换成十进制数和无符号十进制数的程序。可是输入十六进制数根本就没有转换!用od跟踪可是按到对话框打开的时候就不能再运行。是在不懂为什么~~~
源码如下:
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat, stdcall
option casemap: none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Equ
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
IDD_DLG1 equ 1000
ICO_MAIN equ 1000
IDC_HEX equ 1001
IDC_SIGENDDEX equ 1002
IDC_UNSIGNEDDEX equ 1003
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
hWinMain dd ?
dwOption dd ?
lpOldProcEdit dd ?
.const
;szFmtDecToHex db '%08X',0
szHexToUndec db '%u',0
szHexToDec db '%d',0
szAllowedChar db '0123456789ABCDEFabcdef',08h
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; IDC_HEX新窗口过程
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcEdit proc uses ebx edi esi hWnd,uMsg,wParam,lParam
mov eax,uMsg
;********************************************************************
.if uMsg == WM_CHAR
mov eax,wParam; the character
mov ecx,sizeof szAllowedChar
mov edi,offset szAllowedChar
repnz scasb;al/ax - [es:di]
.if ZERO?
.if al > '9'
and eax,not 20h
.endif
invoke CallWindowProc,lpOldProcEdit,hWnd,uMsg,eax,lParam
ret
.endif
.else
invoke CallWindowProc,lpOldProcEdit,hWnd,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret
_ProcEdit endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Hex to dec十六进制转十进制
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_HexToDec proc
LOCAL @szBuffer[512]:byte
invoke GetDlgItemText,hWinMain,IDC_HEX,addr @szBuffer,sizeof @szBuffer
lea esi,@szBuffer
cld
xor eax,eax
mov ebx,16
.while TRUE
movzx ecx,byte ptr [esi];or mov cl,byte ptr [esi]
inc esi
.break .if !ecx
.if cl > '9'
sub cl,'A' - 0ah
.else
sub cl,'0'
.endif
mul ebx
add eax,ecx
.endw
invoke wsprintf,addr @szBuffer,addr szHexToUndec,eax
invoke SetDlgItemText,hWinMain,IDC_UNSIGNEDDEX,addr @szBuffer
invoke wsprintf,addr @szBuffer,addr szHexToDec,eax
invoke SetDlgItemText,hWinMain,IDC_SIGENDDEX,addr @szBuffer
ret
_HexToDec endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
mov eax,wMsg
;********************************************************************
.if eax == WM_CLOSE
invoke EndDialog,hWinMain,NULL
;********************************************************************
.elseif eax == WM_INITDIALOG
mov eax,hWnd
mov hWinMain,eax
invoke LoadIcon,hInstance,ICO_MAIN
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
invoke SendDlgItemMessage,hWinMain,IDC_HEX,EM_LIMITTEXT,8,0
invoke SendDlgItemMessage,hWinMain,IDC_UNSIGNEDDEX,EM_LIMITTEXT,10,0
invoke SendDlgItemMessage,hWinMain,IDC_SIGENDDEX,EM_LIMITTEXT,10,0
invoke GetDlgItem,hWinMain,IDC_HEX
invoke SetWindowLong,eax,GWL_WNDPROC,addr _ProcEdit
mov lpOldProcEdit,eax
;********************************************************************
.elseif eax == WM_COMMAND
mov eax,wParam
.if ! dwOption
mov dwOption,TRUE
.if eax == IDC_HEX
invoke _HexToDec
.endif
mov dwOption,FALSE
.endif
;********************************************************************
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,IDD_DLG1,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
顺便问下罗云斌大哥的程序为什么总在窗口过程最后加上这段代码了?
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
eax究竟犯什么错了非要改变它?
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课