这次用到了RadASM这个工具,说实话很好用,自带了资源编辑,一个按钮搞定编译连接,一个字爽,晚上写了个小程序试了些常用的API,比如当点击按钮时候显示文本框的内容。
首先还是建立资源文件,在上面画文本框和按钮,资源分别为:
#define
IDD_DIALOG1 101
#define
IDC_TEST 1001
#define
IDC_EDT1 1002
然后在ASM中用equ定义:
.
const
IDD_DIALOG1 equ
101 ;对话框
IDC_TEST equ
1001 ;按钮
IDC_EDT1 equ
1002 ;文本框
下面是关键
DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax,uMsg
.
if
eax
==
WM_INITDIALOG
.elseif eax
==
WM_COMMAND
mov eax,wParam
.IF ax
==
IDC_TEST
invoke GetDlgItemText,hWin,IDC_EDT1,addr t,
sizeof
t ;这里取文本框内容存放到 t中
invoke MessageBox,NULL,addr t,ADDR AppName,MB_OK ;和这里把t中的内容显示出来
.endif
.elseif eax
==
WM_CLOSE
invoke EndDialog,hWin,
0
.
else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp
上面用的t在全局中定义:
.data
?
t db
250
dup(
?
)
这样就OK了,下面是源代码
test.inc 这里是些基本定义,如上面的.data?等,然后在主asm中include就行了
include windows.inc
include kernel32.inc
include user32.inc
include Comctl32.inc
include shell32.inc
includelib kernel32.lib
includelib user32.lib
includelib Comctl32.lib
includelib shell32.lib
DlgProc PROTO :HWND,:UINT,:WPARAM,:LPARAM
.
const
IDD_DIALOG1 equ
101
IDC_TEST equ
1001
IDC_EDT1 equ
1002
.data
AppName db
"
Our First Window
"
,
0
Msg db
"
hello
"
,
0
;#########################################################################
.data
?
hInstance dd
?
t db
250
dup(
?
)
;#########################################################################
test.asm 主文件
.
386
.model flat, stdcall ;
32
bit memory model
option casemap :none ;
case
sensitive
include test.inc
.code
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke InitCommonControls
invoke DialogBoxParam,hInstance,IDD_DIALOG1,NULL,addr DlgProc,NULL
invoke ExitProcess,
0
;########################################################################
DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax,uMsg
.
if
eax
==
WM_INITDIALOG
.elseif eax
==
WM_COMMAND
mov eax,wParam
.IF ax
==
IDC_TEST
invoke GetDlgItemText,hWin,IDC_EDT1,addr t,
sizeof
t
invoke MessageBox,NULL,addr t,ADDR AppName,MB_OK
.endif
.elseif eax
==
WM_CLOSE
invoke EndDialog,hWin,
0
.
else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp
end start
test.rc 资源文件
#define
IDD_DIALOG1 101
#define
IDC_TEST 1001
#define
IDC_EDT1 1002
IDD_DIALOG1 DIALOGEX
6
,
6
,
194
,
106
FONT
8
,
"
MS Sans Serif
"
,
0
,
0
STYLE
0x10CF0800
EXSTYLE
0x00000000
BEGIN
CONTROL
"
test
"
,IDC_TEST,
"
Button
"
,
0x50010000
,
94
,
36
,
53
,
12
,
0x00000000
CONTROL
""
,IDC_EDT1,
"
Edit
"
,
0x50010000
,
14
,
36
,
66
,
12
,
0x00000200
END