;运行效果
;win32汇编环境,窗口程序中对多行编辑框的操作
;比如生成多行编辑框,显示文本、获取文本、设置滚动条、捕获超出文本长度消息等。
;直接抄进RadAsm可编译运行。重点部分加备注。
;下面为asm文件
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
include gdi32.inc
includelib user32.lib
includelib gdi32.lib
includelib kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.DATA
ClassName db "SimpleWinClass",0
AppName db "窗口程序的模版",0
szButtonClassName db "button",0 ;按钮类名
szEditClassName db "edit",0 ;编辑框类名
szTitle db "提示",0
szEditTitle01 db "我只能输入数字的",0
szCheshi_Format01 db "文本的长度是 %d",0
szCheshi_Format02 db "超过允许输入的文本长度了",0
szButtonTitle01 db "得到第1个编辑框的文字",0
szButtonTitle02 db "得到第1个编辑框的文字长度",0
.DATA?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hID_EDIT01 dd ? ;编辑框控件句柄
hIDB01 dd ? ;按钮控件句柄
hIDB02 dd ?
.const
; Equ 等值定义;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ID_EDIT01 equ 11 ;编辑框控件标识符
IDB01 equ 21 ;按钮控件标识符
IDB02 equ 22
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.CODE
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess, eax
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx,NULL, ADDR ClassName,ADDR AppName,WS_CAPTION or WS_SYSMENU or WS_MINIMIZEBOX,100,100,300,320, NULL,NULL,hInst, NULL
mov hwnd,eax
invoke ShowWindow, hwnd,CmdShow
invoke UpdateWindow, hwnd
.while TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.break .if (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.endw
mov eax,msg.wParam
ret
WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL @DEFAULT_GUI_FONT,@OLD_DEFAULT_GUI_FONT
LOCAL @szBuffer[1024]:byte
LOCAL @szBuffer01[1024]:byte
.if uMsg == WM_CREATE
invoke CreateWindowEx,NULL,ADDR szEditClassName,ADDR szEditTitle01, WS_BORDER or WS_CHILDWINDOW or WS_VISIBLE or \
ES_MULTILINE or ES_WANTRETURN or ES_AUTOVSCROLL or WS_VSCROLL or WS_HSCROLL ,20,20,250,150,hWnd,ID_EDIT01,NULL,NULL
mov hID_EDIT01,eax
invoke CreateWindowEx,NULL,ADDR szButtonClassName,ADDR szButtonTitle01, WS_TABSTOP OR WS_VISIBLE OR WS_CHILD OR BS_DEFPUSHBUTTON ,20,200,250,25,hWnd,IDB01,NULL,NULL ;创建按钮控件
mov hIDB01,eax
invoke CreateWindowEx,NULL,ADDR szButtonClassName,ADDR szButtonTitle02, WS_TABSTOP OR WS_VISIBLE OR WS_CHILD OR BS_DEFPUSHBUTTON ,20,240,250,25,hWnd,IDB02,NULL,NULL
mov hIDB02,eax
invoke GetStockObject,DEFAULT_GUI_FONT ;调用GetStockObject函数,得到系统默认字体
mov @DEFAULT_GUI_FONT,eax
invoke SendMessage,hID_EDIT01,WM_SETFONT,@DEFAULT_GUI_FONT,TRUE ;发送WM_SETFONT消息,设置编辑框控件的字体
invoke SendMessage,hIDB01,WM_SETFONT,@DEFAULT_GUI_FONT,TRUE
invoke SendMessage,hIDB02,WM_SETFONT,@DEFAULT_GUI_FONT,TRUE
invoke DeleteObject,@DEFAULT_GUI_FONT ;删除本程序新建的字体
invoke SendMessage,hID_EDIT01,EM_SETLIMITTEXT,1024,NULL ;设定编辑框最多只能1024个字符
.elseif uMsg == WM_COMMAND
mov eax,wParam
.if lParam == 0
.else
mov edx,wParam
shr edx,16
.if dx == BN_CLICKED
.if ax == IDB01
invoke GetDlgItemText,hWnd,ID_EDIT01,addr @szBuffer,sizeof @szBuffer ;得到编辑框内的文本
invoke MessageBox,hWnd,addr @szBuffer,addr szTitle,MB_OK or MB_ICONINFORMATION
.elseif ax == IDB02
invoke GetDlgItem,hWnd,ID_EDIT01
invoke GetWindowTextLength,eax
invoke wsprintf,addr @szBuffer,addr szCheshi_Format01,eax
invoke MessageBox,hWnd,addr @szBuffer,addr szTitle,MB_OK or MB_ICONINFORMATION
.endif
.elseif dx == EN_MAXTEXT ;超过可输入的文本长度时,即超过上面设定的1024字符时,则
.if ax == ID_EDIT01
invoke MessageBox,hWnd,addr szCheshi_Format02,addr szTitle,MB_OK or MB_ICONINFORMATION
.endif
.endif
.endif
.elseif uMsg == WM_DESTROY
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret
WndProc endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start