我刚学WIN32汇编,这是我写的第一个程序,但有的错误我无法排除(很惭愧,不是一个错误,错误太多了。我是把代码从纸上输到记事本里的,检查的时候都是纸上谈兵,很多书写错误都不知道),望高手指教!
first.asm文件
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat, stdcall
option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Equ 等值定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
IDI_ICON1 equ 101
IDD_DIALOG1 equ 102
IDC_COMBOBOX1 equ 108
IDC_COMBOBOX2 equ 109
IDC_COMBOBOX3 equ 110
IDC_COMBOBOX4 equ 111
IDC_CHACKEBOX1 equ 101
IDC_CHACKEBOX2 equ 102
IDC_CHACKEBOX3 equ 103
IDC_CHACKEBOX4 equ 104
IDC_SCROLL1 equ 105
IDC_SCROLL2 equ 106
IDC_SCROLL3 equ 107
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
dwpos1 dd ?
dwpos2 dd ?
dwpos3 dd ?
dwpos dd ?
IDC_SCROLL dd ?
szbuffer db ?
text1 db ?
text2 db ?
text3 db ?
text4 db ?
.const
sztitle db '参数输入',0
sztext1 db 'F1',0
sztext2 db 'F2',0
sztext3 db 'F3',0
sztext4 db 'F4',0
sztext5 db 'F5',0
sztext6 db 'F6',0
sztext7 db 'F7',0
sztext8 db 'F8',0
sztext9 db 'F9',0
szformat db 'HP:%08d.MP:%08d.FP:%08d.加HP按:%s.加MP按:%s.加FP按:%s',0dh,0ah,0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
local @szbuffer[128]:byte
mov eax,wMsg
.if eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif eax == WM_INITDIALOG
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 初始化组合框
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
mov ecx,8
while ecx
lea edx,sztext1
invoke SendDlgItemMessage,hWnd,IDC_COMBOBOX1,CB_ADDSTRING,0,edx
dec edx
dec ecx
endw
mov ecx,8
while ecx
lea edx,sztext1
invoke SendDlgItemMessage,hWnd,IDC_COMBOBOX2,CB_ADDSTRING,0,edx
dec edx
dec ecx
endw
mov ecx,8
while ecx
lea edx,sztext1
invoke SendDlgItemMessage,hWnd,IDC_COMBOBOX3,CB_ADDSTRING,0,edx
dec edx
dec ecx
endw
mov ecx,8
while ecx
lea edx,sztext1
invoke SendDlgItemMessage,hWnd,IDC_COMBOBOX4,CB_ADDSTRING,0,edx
dec edx
dec ecx
endw
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 初始化复合框
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
mov ecx,4
while ecx
mov dx,IDC_CHACKBOX4
invoke ChackDlgButton,hWnd,dx,BST_UNCHACK
dec dx
dec ecx
endw
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 初始化滚动条
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
invoke SendDlgItemMessage,hWnd,IDC_ROLL1,SBN_SETRANGE,0,100
invoke SendDlgItemMessage,hWnd,IDC_ROLL2,SBN_SETRANGE,0,100
invoke SendDlgItemMessage,hWnd,IDC_ROLL3,SBN_SETRANGE,0,100
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 处理滚动条消息
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.elseif eax == WM_HSCROLL
mov eax,lParam
.if eax == WM_HSCROLL1
mov ecx,dwpos1
mov dwpos,ecx
.elseif eax == WM_HSCROLL2
mov ecx,dwpos2
mov dwpos,ecx
.elseif eax == WM_HSCROLL3
mov ecx,dwpos3
mov dwpos,ecx
.endif
mov eax,wParam
.if ax == SB_LINELEFT
dec dwpos
.elseif ax == SB_LINERIGHT
inc dwpos
.elseif ax == SB_PAGERIGHT
sub dwpos,10
.elseif ax == SB_PAGERIGHT
add dwpos,10
.elseif ax == SB_THUMBPOSITION||ax == SB_THUMBTRACK
mov eax,wParam
shr eax,16
mov dwpos,eax
.else
mov eax,TRUE
ret
.endif
cmp dwpos,100
jle @F
mov dwpos,0
@@:
cmp dwpos,100
jle @F
mov dwpos,100
@@:
mov eax,lParam
.if eax == WM_HSCROLL1
mov IDC_SCRLL,IDC_SCRLL1
mov dwpos1,dwpos
.elseif eax == WM_HSCROLL2
mov IDC_SCRLL,IDC_SCRLL2
mov dwpos2,dwpos
.elseif eax == WM_HSCROLL3
mov IDC_SCRLL,IDC_SCRLL3
mov dwpos3,dwpos
.endif
invoke SendDlgItemMessage,hWnd,IDC_SCRLL,SBM_SETPOS,dwpos,TRUE
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 处理复选框消息
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.elseif eax == WM_COMMAND
mov eax,wParam
.if ax == IDCANCEL
invoke EndDialog,hWnd,NULL
.elseif ax == IDC_CHACKEBOX1
invoke IsDlgButtonChacked,hWnd,IDC_CHACKEBOX1
.if eax == BST_CHACKED
mov ebx,TRUE
.else xor ebx,ebx
.endif
invoke GetDlgItem,hWnd,IDC_ROLL1
invoke EnableWindow,eax,ebx
invoke GetDlgItem,hWnd,IDC_COMBOBOX1
invoke EnableWindow,eax,ebx
.elseif ax == IDC_CHACKEBOX2
invoke IsDlgButtonChacked,hWnd,IDC_CHACKEBOX2
.if eax == BST_CHACKED
mov ebx,TRUE
.else xor ebx,ebx
.endif
invoke GetDlgItem,hWnd,IDC_ROLL2
invoke EnableWindow,eax,ebx
invoke GetDlgItem,hWnd,IDC_COMBOBOX2
invoke EnableWindow,eax,ebx
.elseif ax == IDC_CHACKEBOX3
invoke IsDlgButtonChacked,hWnd,IDC_CHACKEBOX3
.if eax == BST_CHACKED
mov ebx,TRUE
.else xor ebx,ebx
.endif
invoke GetDlgItem,hWnd,IDC_ROLL3
invoke EnableWindow,eax,ebx
invoke GetDlgItem,hWnd,IDC_COMBOBOX3
invoke EnableWindow,eax,ebx
.elseif ax == IDC_CHACKEBOX1
invoke IsDlgButtonChacked,hWnd,IDC_CHACKEBOX4
.if eax == BST_CHACKED
mov ebx,TRUE
.else xor ebx,ebx
.endif
invoke GetDlgItem,hWnd,IDC_COMBOBOX4
invoke EnableWindow,eax,ebx
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 处理组合框消息
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.elseif ax == IDC_COMBOBOX1||ax == IDC_COMBOBOX2||ax == IDC_COMBOBOX3||ax == IDC_COMBOBOX4
mov dx,ax
shr eax.16
.if ax == CBN_SELENDOK
invoke SendMeaasge,lParam,CB_GETCURSEL,0,0
lea ecx,szbuffer
invoke SendMeaasge,lParam,CB_GETTEXT,eax,ecx
.if dx == IDC_COMBOBOX1
mov cl,szbufer
mov text1,cl
.elseif dx == IDC_COMBOBOX1
mov cl,szbufer
mov text2,cl
.elseif dx == IDC_COMBOBOX1
mov cl,szbufer
mov text3,cl
.elseif dx == IDC_COMBOBOX1
mov cl,szbufer
mov text4,cl
.endif
.endif
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 处理IDOK消息
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.elseif ax == IDOK
invoke wsprintf,addr @szbuffer,addr szformat,dwpos1,dwpos2,dwpos3,text1,text2,text3,text4
invoke Message,hWnd,addr @szbuffer,addr sztitle,MB_OK
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,IDD_DIALOG1,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
first.rc文件
#include "D:\MASM32\INCLUDE\resource.h"
#include "resource.h"
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 208, 140
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "对话"
FONT 10, "System"
BEGIN
DEFPUSHBUTTON "确定",IDOK,49,110,28,12
PUSHBUTTON "取消",IDCANCEL,109,111,28,11
CONTROL "复选1",101,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,20,
9,9
CONTROL "复选1",102,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,42,
9,9
CONTROL "复选1",103,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,64,
9,9
CONTROL "复选1",104,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,93,
9,9
SCROLLBAR 105,29,20,109,8
SCROLLBAR 107,30,65,109,8
SCROLLBAR 106,29,41,109,8
COMBOBOX 108,166,22,18,12,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL |
WS_TABSTOP
COMBOBOX 109,167,40,18,12,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL |
WS_TABSTOP
COMBOBOX 110,166,64,18,12,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL |
WS_TABSTOP
COMBOBOX 111,166,88,18,12,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL |
WS_TABSTOP
END
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON DISCARDABLE "Main.ico"
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_DIALOG1, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 201
TOPMARGIN, 7
BOTTOMMARGIN, 133
END
END
#endif // APSTUDIO_INVOKED
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
resource.h文件
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by first.rc
//
#define IDI_ICON1 101
#define IDD_DIALOG1 102
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1008
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Makefile文件
NAME = first
OBJS = $(NAME).obj
RES = $(NAME).res
LINK_FLAG = /subsystem:windows
ML_FLAG = /c /coff
$(NAME).exe: $(OBJS) $(RES)
Link $(LINK_FLAG) $(OBJS) $(RES)
.asm.obj:
ml $(ML_FLAG) $<
.rc.res:
rc $<
clean:
del *.obj
del *.res
文件下载地址
http://gcgl2008.111.tofor.com/lt/context.asp?id=7324&listpage=1
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!