能力值:
( LV2,RANK:10 )
2 楼
.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include gdi32.inc
includelib gdi32.lib
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include Advapi32.inc
includelib Advapi32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
hWinMain dd ?
hButton dd ?
szRsing db 255 dup (?),0
hEdit dd ?
dwNot dd ?
hCompatibleDc dd ?
hCompatibleBitmap dd ?
hHatchBrush dd ?
hRoundRectRgn dd ?
szCharBuffer db 256 dup (?)
hTimer dd ?
hFont dd ?
dwXo1 dd ?
stRect RECT <?>
.const
szClassName db 'MyClass',0
szCaptionMain db 'My first Window !',0
szText db 'Win32 Assembly, Simple and powerful !',0
szButton db 'button',0
szButtonText db '&OK',0
x1 db '%x',0
szOpen db '打开',0
szEdit db 'edit',0
szUserName db '请输入用户名:',0 ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 窗口过程
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_a proc xxx
invoke wsprintf,addr szRsing,addr x1,xxx
invoke SendMessage,hWinMain,WM_SETTEXT,0,addr szRsing
ret
_a endp
_ProcWinMain proc uses ebx edi esi hWnd,uMsg,wParam,lParam
local @stPs:PAINTSTRUCT
local @stRect:RECT
local @hDc
local @stPoint:POINT
local @stDwPoint[8]:POINT
local @n1:BYTE
local @stS:SIZEL
mov eax,uMsg
;********************************************************************
.if eax == WM_PAINT
invoke BeginPaint,hWnd,addr @stPs
mov @hDc,eax
invoke SelectObject,@hDc,hFont
invoke GetClientRect,hWnd,addr @stRect
invoke TextOut,@hDc,10,17,offset szUserName,sizeof szUserName-1
invoke SelectObject,@hDc,hHatchBrush
invoke SelectObject,@hDc,hRoundRectRgn invoke PatBlt,@hDc,0,0,@stRect.right,@stRect.bottom,PATCOPY
invoke SetBkMode,@hDc,TRANSPARENT
invoke lstrlen,offset szCharBuffer
lea esi,szCharBuffer
xor ebx,ebx
.while BYTE ptr [esi] !=0
.if BYTE ptr [esi]>7fh
inc ebx
.endif
inc esi
.endw
test ebx,1
je @f
lea esi,szCharBuffer
invoke lstrlen,offset szCharBuffer
add esi,eax
mov BYTE ptr [esi-1],0
@@:
invoke lstrlen,offset szCharBuffer
push eax
invoke TextOut,@hDc,120,17,offset szCharBuffer,eax
pop ecx
invoke GetTextExtentPoint32,@hDc,offset szCharBuffer,ecx,addr @stS
.if wParam ==1
mov @n1,'|'
mov ecx,120
add ecx,@stS.x
invoke TextOut,@hDc,ecx,17,addr @n1,1
.else
invoke TextOut,@hDc,ecx,17,addr @n1,0
.endif invoke EndPaint,hWnd,addr @stPs
;********************************************************************
.elseif eax== WM_CREATE
invoke CreateHatchBrush,HS_BDIAGONAL1,0ff11f1h
mov hHatchBrush,eax
invoke CreateRoundRectRgn,120,10,400,35,3,3
mov hRoundRectRgn,eax
invoke SetTimer,hWnd,1000,500,0
mov hTimer,eax
invoke CreateFont,0,0,0,0,400,0,0,0,0,0,0,0,0,0
mov hFont,eax .elseif eax == WM_CHAR
.if dwXo1
lea ebx,szCharBuffer
invoke lstrlen,ebx
mov edx,wParam
.if eax<30 || dl ==8
.if eax >=0 && dl !=8
add ebx,eax
mov BYTE ptr [ebx],dl
.else
.if dl==8 && eax && (BYTE ptr [ebx+eax-1] <= 7fh)
mov BYTE ptr [ebx+eax-1],0
.elseif eax && (BYTE ptr [ebx+eax-1] > 7fh)
mov WORD ptr [ebx+eax-2],0
.endif
.endif
invoke GetClientRect,hWnd,addr @stRect
invoke InvalidateRect,hWnd,addr @stRect,0
.endif
.endif .elseif eax ==WM_TIMER
.if dwNot
and dwNot,0
.else
or dwNot,1
.endif
invoke GetClientRect,hWnd,addr @stRect
invoke InvalidateRect,hWnd,addr @stRect,0
invoke SendMessage,hWnd,WM_PAINT,dwNot,0 .elseif eax == 202h
invoke GetCursorPos,addr @stPoint;
invoke ScreenToClient,hWnd,addr @stPoint
.if @stPoint.x>=120 && @stPoint.x<=400 && @stPoint.y >=10 && @stPoint.y <=34
or dwXo1,1
.else
and dwXo1,0
.endif .elseif eax == WM_CLOSE
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
;********************************************************************
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
;********************************************************************
xor eax,eax
ret
_ProcWinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain proc
local @stWndClass:WNDCLASSEX
local @stMsg:MSG
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
;********************************************************************
; 注册窗口类
;********************************************************************
invoke LoadCursor,0,IDC_ARROW
mov @stWndClass.hCursor,eax
push hInstance
pop @stWndClass.hInstance
mov @stWndClass.cbSize,sizeof WNDCLASSEX
mov @stWndClass.style,CS_HREDRAW or CS_VREDRAW
mov @stWndClass.lpfnWndProc,offset _ProcWinMain
mov @stWndClass.hbrBackground,COLOR_WINDOW + 1
mov @stWndClass.lpszClassName,offset szClassName
invoke RegisterClassEx,addr @stWndClass
;********************************************************************
; 建立并显示窗口
;********************************************************************
invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,offset szCaptionMain,\
WS_OVERLAPPEDWINDOW,\
180,100,900,550,\
NULL,NULL,hInstance,NULL
mov hWinMain,eax
invoke ShowWindow,hWinMain,SW_SHOWNORMAL
invoke UpdateWindow,hWinMain
;********************************************************************
; 消息循环
;********************************************************************
.while TRUE
invoke GetMessage,addr @stMsg,NULL,0,0
.break .if eax == 0
invoke TranslateMessage,addr @stMsg
invoke DispatchMessage,addr @stMsg
.endw
ret
_WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
call _WinMain
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start