Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
system prog new.docx
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
275.7 Кб
Скачать

29. Structure of the program written for Windows.

Despite the fact that Windows 95 and Windows NT seem to be more complex operating systems compared with DOS, to program in assembly language for them much easier. On the one hand, Windows-application runs in 32-bit mode (we do not consider Windows 3.11 and older who were working in 16-bit mode) memory model flat, so that the programmer gets all the benefits mentioned in the previous head and on the other hand - we no longer need to learn in detail how the different devices of the computer program is low. In the current operating environment applications use only system calls, the number of which is greater than 2000 (about 2200 for Windows 95 and 2434 for Windows NT). All Windows-based applications using a special format of executable files - the format of PE (Portable Executable). These files start as usual EXE-files the old model (also known as MZ in the first two symbols of the title), and if such a file is run from DOS, then it will run and display the error message (text message depends on the compiler), while as Windows will notice that after the usual MZ-header file is PE-header, and launch the application. UTB will only mean that the program will be required to compile other parameters on the command line.

30. The general principles of creation of window applications in the Assembler

In order to display any window, the program usually has to first describe its appearance and all of the properties, that is what is called a window class. MessageBox - it's a small window with the specified text message and one or more buttons. In our example, the message will be the traditional «Hello world!», And the button will be only one - OK.

; winhello.asm

; Graphic win32-prilozhenie

; A dialog box appears with the text type mesagebox "Hello world!"

include def32.inc

include kernel32.inc

include user32.inc

.386

.model flat

.const

; window title

hello_title db "First win32 GUI program",0

; message

hello_message db "Hello world!",0

.code

_start:

push MB_ICONINFORMATION ; window style

push offset hello_title ; Address line with the title

push offset hello_message ; Address line with the message

push 0 ; ID of parent

call MessageBox

push 0 ; exit code

call ExitProcess ; completion of the program

end _start

we need to add to the file def32.inc line:

; from winuser.h

MB_ICONINFORMATION equ 40h

and create a new file, user32.inc, which will include determining the functions of user32.dll - library, which includes all the basic functions that are responsible for window interface:

; user32.inc

; include file with definitions of functions from user32.dll

;

ifdef _TASM_

includelib import32.lib

; the names of the functions

extrn MessageBoxA:near

; assignment to facilitate readability

MessageBox equ MessageBoxA

else

includelib user32.lib

; true names used functions

extrn __imp__MessageBoxA@16:dword

; assignment to facilitate readability

MessageBox equ __imp__MessageBoxA@16

Now you can compile the program the same way as we did winurl.asm, and run - you will see a small window with our message and an OK button, which will disappear after you press the button. If winhello.asm compiled as a console application, nothing will change, the text box with the name of the program will be open as long as our message box is closed.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]