КАТЕГОРИИ: Архитектура-(3434)Астрономия-(809)Биология-(7483)Биотехнологии-(1457)Военное дело-(14632)Высокие технологии-(1363)География-(913)Геология-(1438)Государство-(451)Демография-(1065)Дом-(47672)Журналистика и СМИ-(912)Изобретательство-(14524)Иностранные языки-(4268)Информатика-(17799)Искусство-(1338)История-(13644)Компьютеры-(11121)Косметика-(55)Кулинария-(373)Культура-(8427)Лингвистика-(374)Литература-(1642)Маркетинг-(23702)Математика-(16968)Машиностроение-(1700)Медицина-(12668)Менеджмент-(24684)Механика-(15423)Науковедение-(506)Образование-(11852)Охрана труда-(3308)Педагогика-(5571)Полиграфия-(1312)Политика-(7869)Право-(5454)Приборостроение-(1369)Программирование-(2801)Производство-(97182)Промышленность-(8706)Психология-(18388)Религия-(3217)Связь-(10668)Сельское хозяйство-(299)Социология-(6455)Спорт-(42831)Строительство-(4793)Торговля-(5050)Транспорт-(2929)Туризм-(1568)Физика-(3942)Философия-(17015)Финансы-(26596)Химия-(22929)Экология-(12095)Экономика-(9961)Электроника-(8441)Электротехника-(4623)Энергетика-(12629)Юриспруденция-(1492)Ядерная техника-(1748) |
End start
WndProc ENDP Ret Xor dx, dx Jmp finish Xor ax, ax Call MESSAGEBOX, 0, ds offset lpszRightMsg, ds offset lpszCaption, 0 Jmp finish Xor ax, ax Call MESSAGEBOX, 0, ds offset lpszLeftMsg, ds offset lpszCaption, 0 Jmp finish Xor ax, ax Call POSTQUITMESSAGE, 0 Jmp finish Call DEFWINDOWPROC, hwnd, wmsg, wparam, lparam Jmp finish Xor ax, ax Jmp finish Xor ax, ax Call ENDPAINT, hwnd, ds offset lppaint Call TEXTOUT, ax, 5, 5, ds offset lpszText, lpszTextLength Call BEGINPAINT, hwnd, ds offset lppaint Jmp defwndproc Je wmpaint Je wmrbuttondown Je wmcreate Je wmlbuttondown Je wmdestroy WndProc PROC Mov ah, 4Ch int 21h ; ; Процедура обработки сообщений ; ARG hwnd:WORD, wmsg:WORD, wparam:WORD, lparam:DWORD
cmp [wmsg], WM_DESTROY ; Если получили сообщение WM_DESTROY (получено сообщение "на выход") cmp [wmsg], WM_LBUTTONDOWN ; Если получили сообщение WM_LBUTTONDOWN (нажата левая кнопка мыши) cmp [wmsg], WM_CREATE ; Если получили сообщение WM_CREATE (получено сообщение "создать окно") cmp [wmsg], WM_RBUTTONDOWN ; Если получили сообщение WM_RBUTTONDOWN (нажата правая кнопка мыши) cmp [wmsg], WM_PAINT ; Если получили сообщение WM_PAINT (получено сообщение "нарисуйся") ; Если мы не обрабатываем ни одно из вышеперечисленных сообщений передаем ; управление стандартному обработчику ; ; Обработка сообщения WM_PAINT ; wmpaint: ; Начинаем рисование и получаем указатель на текущий DC ; AX содержит контекст устройства DC, полученный после вызова BEGINPAINT ; Вызываем TEXTOUT для вывода строки lpszText ; Заканчиваем рисование ; Обнуляем AX и на выход ; ; Обработка сообщения WM_CREATE ; wmcreate: ; Обнуляем AX и на выход ; ; Вызов стандартного обработчика сообщений ; defwndproc: ; ; Обработка сообщения WM_DESTROY ; wmdestroy: ; Вызываем POSTQUITMESSAGE ; Обнуляем AX и на выход ; ; Обработка сообщения WM_LBUTTONDOWN ; wmlbuttondown: ; Выводим на экран MESSAGEBOX с надписью "Left button pressed" ; Обнуляем AX и на выход ; ; Обработка сообщения WM_RBUTTONDOWN ; wmrbuttondown: ; Выводим на экран MESSAGEBOX с надписью "Right button pressed" ; Обнуляем AX и на выход ; ; "Финишная прямая" ; finish: ; Обнуляем DX и на выход
Текст исходной программы wap.asm ; Copyright (c) 1993 by Borland International, Inc. ; * Borland Turbo Assembler 4.0 * ; * Windows Application Example in Assembly * ; This example (WAP.ASM) will put up a window and beep when the ; right mouse button is pressed. When the left mouse button is ; pressed, it will put up a message box.
locals jumps .model large, WINDOWS PASCAL include windows.inc
extrn BEGINPAINT:PROC extrn CREATEWINDOW:PROC extrn DEFWINDOWPROC:PROC extrn DISPATCHMESSAGE:PROC extrn ENDPAINT:PROC extrn GETMESSAGE:PROC extrn GETSTOCKOBJECT:PROC extrn INITAPP:PROC extrn INITTASK:PROC extrn INVALIDATERECT:PROC extrn LOADCURSOR:PROC extrn MESSAGEBEEP:PROC extrn MESSAGEBOX:PROC extrn POSTQUITMESSAGE:PROC extrn REGISTERCLASS:PROC extrn SHOWWINDOW:PROC extrn TEXTOUT:PROC extrn TRANSLATEMESSAGE:PROC extrn UPDATEWINDOW:PROC extrn WAITEVENT:PROC .data
db 16 dup (0); Filler for Windows Task manager. ; This *MUST* be declared, otherwise ; Windows will clobber part of your data ; segment. For additional information on ; Windows Task managment and what ; happens when Windows apps start up, see ; "Windows Internals" - Matt Pietrek, ; 1993 Addison Wesley psp dw? pszCmdline dw? hPrev dw? hInstance dw? cmdShow dw?
newhwnd dw 0 lppaint PAINTSTRUCT <0> msg MSGSTRUCT <0> wc WNDCLASS <0> mbx_count dw 0
szTitleName db 'Windows Assembly Program', 0 szClassName db 'ASMCLASS', 0 szMsg db 'Hello there folks', 0 szCapt db 'Left Mouse', 0 szPaint db 'There are ' s_num db '0 MessageBoxes waiting.', 0 MSG_L EQU ($-offset szPaint)-1 .code .286 ;------------------------------ start:
mov ax, @data mov ds, ax; set up data segment
;Windows initialization. Sets up registers and stack.
;INITTASK returns: ; Failure: ; AX = zero if it failed ; Success: ; AX = 1 ; CX = stack limit ; DX = cmdShow parameter to CreateWindow ; ES:BX = -> DOS format command line (ES = PSP address) ; SI = hPrevinstance ; DI = hinstance
call INITTASK or ax, ax jnz @@OK jmp @@Fail @@OK: mov [psp], es mov word ptr [pszCmdline], bx mov [hPrev], si mov [hInstance], di mov [cmdShow], dx
;Initialize the Windows App
xor ax, ax push ax call WAITEVENT push [hInstance] call INITAPP or ax, ax jnz @@InitOK
@@Fail: mov ax, 4CFFh int 21h; terminate program
@@InitOK: ;----------------------------- ; This is generally where WinMain is called. We won't use a WinMain, since ; this app is 100% assembly.
cmp [hPrev], 0 jne already_running
; initialize the WndClass structure mov [wc.clsStyle], CS_HREDRAW + CS_VREDRAW mov word ptr [wc.clsLpfnWndProc], offset WndProc mov word ptr [wc.clsLpfnWndProc+2], seg WndProc mov [wc.clsCbClsExtra], 0 mov [wc.clsCbWndExtra], 0 mov ax, [hInstance] mov [wc.clsHInstance], ax mov [wc.clsHIcon], 0
push 0 push IDC_ARROW call LOADCURSOR mov [wc.clsHCursor], ax
push WHITE_BRUSH call GETSTOCKOBJECT mov [wc.clsHbrBackground], ax
mov word ptr [wc.clsLpszMenuName], 0 mov word ptr [wc.clsLpszMenuName+2], 0
mov word ptr [wc.clsLpszClassName], offset szClassName mov word ptr [wc.clsLpszClassName+2], ds
push ds push offset wc call REGISTERCLASS
already_running:
push ds push offset szClassName; Class name push ds push offset szTitleName; Title string push WS_OVERLAPPEDWINDOW+WS_VISIBLE; high word of Style push 0; low word of Style push CW_USEDEFAULT; x push CW_USEDEFAULT; y push CW_USEDEFAULT; width push CW_USEDEFAULT; height push 0; parent hwnd push 0; menu push [hInstance]; hInstance push 0; lpParam push 0; lpParam call CREATEWINDOW mov [newhwnd], ax push [newhwnd] push [cmdShow] call SHOWWINDOW push [newhwnd] call UPDATEWINDOW msg_loop: push ds push offset msg push 0 push 0 push 0 call GETMESSAGE cmp ax, 0 je end_loop
push ds push offset msg call TRANSLATEMESSAGE
push ds push offset msg call DISPATCHMESSAGE
jmp msg_loop
end_loop: mov ax, [msg.msWPARAM] mov ah, 4Ch int 21h
;----------------------------- WndProc proc hwnd:WORD, wmsg:WORD, wparam:WORD, lparam:DWORD
cmp [wmsg], WM_DESTROY je wmdestroy cmp [wmsg], WM_LBUTTONDOWN je wmlbuttondown cmp [wmsg], WM_CREATE je wmcreate cmp [wmsg], WM_RBUTTONDOWN je wmrbuttondown cmp [wmsg], WM_PAINT je wmpaint
jmp defwndproc
wmpaint: push [hwnd] push ds push offset lppaint call BEGINPAINT
push ax; the DC
mov bx, [mbx_count] add bl, '0' mov [s_num], bl
push 5; x push 5; y
push ds push offset szPaint; string
push MSG_L; length of string
call TEXTOUT
push [hwnd] push ds push offset lppaint call ENDPAINT
mov ax, 0 jmp finish
wmcreate: mov ax, 0 jmp finish
defwndproc: push hwnd push wmsg push wparam push lparam call DEFWINDOWPROC jmp finish
wmdestroy: push 0 call POSTQUITMESSAGE mov ax, 0 jmp finish
wmlbuttondown: cmp [mbx_count], 5 jae finish
inc [mbx_count]
push [hwnd] push 0 push 0 push 0 call INVALIDATERECT; repaint window
push 0 push ds push offset szMsg push ds push offset szCapt push 0 call MESSAGEBOX; put up msgbox and wait mov ax, 0 dec [mbx_count]
push [hwnd] push 0 push 0 push 0 call INVALIDATERECT; repaint window again
jmp finish
wmrbuttondown: push 0 call MESSAGEBEEP jmp finish
finish: mov dx, 0 ret WndProc endp ;----------------------------- public WndProc ends end start
Результат работы исходной программы
Текст модифицированной программы ; Copyright (c) 1993 by Borland International, Inc. ; * Borland Turbo Assembler 4.0 * ; * Windows Application Example in Assembly * ; This example (WAP.ASM) will put up a window and beep when the ; right mouse button is pressed. When the left mouse button is ; pressed, it will put up a message box. locals jumps .model large, WINDOWS PASCAL include windows.inc extrn BEGINPAINT:PROC extrn CREATEWINDOW:PROC extrn DEFWINDOWPROC:PROC extrn DISPATCHMESSAGE:PROC extrn ENDPAINT:PROC extrn GETMESSAGE:PROC extrn GETSTOCKOBJECT:PROC extrn INITAPP:PROC extrn INITTASK:PROC extrn INVALIDATERECT:PROC extrn LOADCURSOR:PROC extrn MESSAGEBEEP:PROC extrn MESSAGEBOX:PROC extrn POSTQUITMESSAGE:PROC extrn REGISTERCLASS:PROC extrn SHOWWINDOW:PROC extrn TEXTOUT:PROC extrn TRANSLATEMESSAGE:PROC extrn UPDATEWINDOW:PROC extrn WAITEVENT:PROC .data db 16 dup (0); Filler for Windows Task manager. ; This *MUST* be declared, otherwise ; Windows will clobber part of your data ; segment. For additional information on ; Windows Task managment and what ; happens when Windows apps start up, see ; "Windows Internals" - Matt Pietrek, ; 1993 Addison Wesley psp dw? pszCmdline dw? hPrev dw? hInstance dw? cmdShow dw? newhwnd dw 0 lppaint PAINTSTRUCT <0> msg MSGSTRUCT <0> wc WNDCLASS <0> mbx_count dw 0 szTitleName db 'Windows Assembly Program', 0 szClassName db 'ASMCLASS', 0 szMsg db 'Hello there folks', 0 szCapt db 'Left Mouse', 0 szRight db 'Right Mouse', 0 szPaint db 'There are ' s_num db '0 MessageBoxes waiting.', 0 MSG_L EQU ($-offset szPaint)-1 .code .286 ;----------------------------- start: mov ax, @data mov ds, ax; set up data segment ;Windows initialization. Sets up registers and stack. ;INITTASK returns: ; Failure: ; AX = zero if it failed ; Success: ; AX = 1 ; CX = stack limit ; DX = cmdShow parameter to CreateWindow ; ES:BX = -> DOS format command line (ES = PSP address) ; SI = hPrevinstance ; DI = hinstance call INITTASK or ax, ax jnz @@OK jmp @@Fail @@OK: mov [psp], es mov word ptr [pszCmdline], bx mov [hPrev], si mov [hInstance], di mov [cmdShow], dx ;Initialize the Windows App xor ax, ax push ax call WAITEVENT push [hInstance] call INITAPP or ax, ax jnz @@InitOK
@@Fail: mov ax, 4CFFh int 21h; terminate program @@InitOK: ;----------------------------- ; This is generally where WinMain is called. We won't use a WinMain, since ; this app is 100% assembly. cmp [hPrev], 0 jne already_running ; initialize the WndClass structure mov [wc.clsStyle], CS_HREDRAW + CS_VREDRAW mov word ptr [wc.clsLpfnWndProc], offset WndProc mov word ptr [wc.clsLpfnWndProc+2], seg WndProc mov [wc.clsCbClsExtra], 0 mov [wc.clsCbWndExtra], 0 mov ax, [hInstance] mov [wc.clsHInstance], ax mov [wc.clsHIcon], 0 push 0 push IDC_ARROW call LOADCURSOR mov [wc.clsHCursor], ax push WHITE_BRUSH call GETSTOCKOBJECT mov [wc.clsHbrBackground], ax mov word ptr [wc.clsLpszMenuName], 0 mov word ptr [wc.clsLpszMenuName+2], 0 mov word ptr [wc.clsLpszClassName], offset szClassName mov word ptr [wc.clsLpszClassName+2], ds push ds push offset wc call REGISTERCLASS already_running: push ds push offset szClassName; Class name push ds push offset szTitleName; Title string push WS_OVERLAPPEDWINDOW+WS_VISIBLE; high word of Style push 0; low word of Style push CW_USEDEFAULT; x push CW_USEDEFAULT; y push CW_USEDEFAULT; width push CW_USEDEFAULT; height push 0; parent hwnd push 0; menu push [hInstance]; hInstance push 0; lpParam push 0; lpParam call CREATEWINDOW mov [newhwnd], ax push [newhwnd] push [cmdShow] call SHOWWINDOW push [newhwnd] call UPDATEWINDOW msg_loop: push ds push offset msg push 0 push 0 push 0 call GETMESSAGE
cmp ax, 0 je end_loop push ds push offset msg call TRANSLATEMESSAGE push ds push offset msg call DISPATCHMESSAGE jmp msg_loop end_loop: mov ax, [msg.msWPARAM] mov ah, 4Ch int 21h ;------------------------- WndProc proc hwnd:WORD, wmsg:WORD, wparam:WORD, lparam:DWORD cmp [wmsg], WM_DESTROY je wmdestroy cmp [wmsg], WM_LBUTTONDOWN je wmlbuttondown cmp [wmsg], WM_CREATE je wmcreate cmp [wmsg], WM_RBUTTONDOWN je wmrbuttondown cmp [wmsg], WM_PAINT je wmpaint jmp defwndproc wmpaint: push [hwnd] push ds push offset lppaint call BEGINPAINT push ax; the DC mov bx, [mbx_count] add bl, '0' mov [s_num], bl push 5; x push 5; y push ds push offset szPaint; string push MSG_L; length of string call TEXTOUT push [hwnd] push ds push offset lppaint call ENDPAINT mov ax, 0 jmp finish wmcreate: mov ax, 0 jmp finish defwndproc: push hwnd push wmsg push wparam push lparam call DEFWINDOWPROC jmp finish wmdestroy: push 0 call POSTQUITMESSAGE mov ax, 0 jmp finish wmlbuttondown: cmp [mbx_count], 5 jae finish inc [mbx_count] push [hwnd] push 0 push 0 push 0 call INVALIDATERECT; repaint window push 0 push ds push offset szMsg push ds push offset szCapt push 0 call MESSAGEBOX; put up msgbox and wait mov ax, 0 dec [mbx_count] push [hwnd] push 0 push 0 push 0 call INVALIDATERECT; repaint window again jmp finish wmrbuttondown: push 0 push ds push offset szMsg push ds push offset szRight push MB_YESNOCANCEL+MB_ICONQUESTION+MB_SYSTEMMODAL call MESSAGEBOX cmp ax, IDYES je wmdestroy cmp ax, IDNO je wmrbuttondown jmp finish finish: mov dx, 0 ret WndProc endp ;----------------------------- public WndProc ends end start
Результат выполнения доработанной программы
Дата добавления: 2014-01-06; Просмотров: 367; Нарушение авторских прав?; Мы поможем в написании вашей работы! Нам важно ваше мнение! Был ли полезен опубликованный материал? Да | Нет |