helloworld.ru -  
helloworld.ru -        
               
:  

C#
MS Visual C++
Borland C++
C++ Builder
Visual Basic
Quick Basic
Turbo Pascal
Delphi
JavaScript
Java
PHP
Perl
Assembler
AutoLisp
Fortran
Python
1C

-
HTML
VRML
HTTP
CGI
FTP
Proxy
DNS
TCP/IP
Apache

Web-
HTML

VRML
PhotoShop
Cookie
CGI
SSI
CSS
ASP
PHP
Perl


DirectDraw
DirectSound
Direct3D
OpenGL
3D-
DOS









MySQL
SQL






demaker.ru

 .




helloworld.ru

WIN32

ASSEMBLER & WIN32

Win32 . , . . Win32 , , .

DOS, () , , Win32 . , , Windows , , DOS. , , . . , Win32 , DOS. Win32 :

-          startup , Windows 3.x;

-          : ; ;

-          ;

-          , , ;

-          (, ..).

, TASM 5.0 Borland International Inc., , , . , ( ) - . , , , .

, Win32 (Windows NT Windows 95). , , .

1.

, , dlg.asm

IDEAL

P586

RADIX 16

MODEL FLAT

 

%NOINCL

%NOLIST

include "winconst.inc" ; API Win32 consts

include "winptype.inc" ; API Win32 functions prototype

include "winprocs.inc" ; API Win32 function

include "resource.inc" ; resource consts

 

MAX_USER_NAME = 20

DataSeg

szAppName db 'Demo 1', 0

szHello db 'Hello, '

szUser db MAX_USER_NAME dup (0)

 

CodeSeg

Start: call GetModuleHandleA, 0

call DialogBoxParamA, eax, IDD_DIALOG, 0, offset DlgProc, 0

cmp eax,IDOK

jne bye

call MessageBoxA, 0, offset szHello, \

offset szAppName, \

MB_OK or MB_ICONINFORMATION

bye: call ExitProcess, 0

 

public stdcall DlgProc

proc DlgProc stdcall

arg @@hDlg :dword, @@iMsg :dword, @@wPar :dword, @@lPar :dword

mov eax,[@@iMsg]

cmp eax,WM_INITDIALOG

je @@init

cmp eax,WM_COMMAND

jne @@ret_false

 

mov eax,[@@wPar]

cmp eax,IDCANCEL

je @@cancel

cmp eax,IDOK

jne @@ret_false

 

call GetDlgItemTextA, @@hDlg, IDR_NAME, \

offset szUser, MAX_USER_NAME

mov eax,IDOK

@@cancel: call EndDialog, @@hDlg, eax

 

@@ret_false: xor eax,eax

ret

 

@@init: call GetDlgItem, @@hDlg, IDR_NAME

call SetFocus, eax

jmp @@ret_false

endp DlgProc

end Start

dlg.rc

#include "resource.h"

IDD_DIALOG DIALOGEX 0, 0, 187, 95

STYLE DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_CAPTION | WS_SYSMENU

EXSTYLE WS_EX_CLIENTEDGE

CAPTION "Dialog"

FONT 8, "MS Sans Serif"

BEGIN

DEFPUSHBUTTON "OK",IDOK,134,76,50,14

PUSHBUTTON "Cancel",IDCANCEL,73,76,50,14

LTEXT "Type your name",IDC_STATIC,4,36,52,8

EDITTEXT IDR_NAME,72,32,112,14,ES_AUTOHSCROLL

END

 

, 1.

Start, API Win32 GetModuleHandle handle ( handle of instance). handle, , , - . . OK, MessageBox .

. (WM_INITDIALOG) Windows . WM_COMMAND : . OK, szValue, Cancel, . : EndDialog. WM_COMMAND , Windows .

, , . , Windows 3.x, , startup . .

2.

Win32 , , Windows 3.x. startup , / , .

, , .

mylib.asm

Ideal

P586

Radix 16

Model flat

DLL_PROCESS_ATTACH = 1

 

extrn GetVersion: proc

 

DataSeg

hInst dd 0

OSVer dw 0

 

CodeSeg

proc libEntry stdcall

arg @@hInst :dword, @@rsn :dword, @@rsrv :dword

cmp [@@rsn],DLL_PROCESS_ATTACH

jne @@1

call GetVersion

mov [OSVer],ax

mov eax,[@@hInst]

mov [hInst],eax

@@1: mov eax,1

ret

endP libEntry

 

public stdcall Hex2Str

proc Hex2Str stdcall

arg @@num :dword, @@str :dword

uses ebx

mov eax,[@@num]

mov ebx,[@@str]

mov ecx,7

@@1: mov edx,eax

shr eax,4

and edx,0F

cmp edx,0A

jae @@2

add edx,'0'

jmp @@3

@@2: add edx,'A' - 0A

@@3: mov [byte ebx + ecx],dl

dec ecx

jns @@1

mov [byte ebx + 8],0

ret

endp Hex2Str

 

end libEntry

, , 2.

libEntry , , . LibEntry :

-          (DLL_PROCESS_ATTACH);

-          (DLL_THREAD_ATTACH), , LoadLibrary;

-          (DLL_THREAD_DETACH);

-          (DLL_PROCESS_DETACH).

DLL_PROCESS_ATTACH. OS , handle of instance.

, . , , , . : ebx + ecx, ecx .

 

3.

dmenu.asm

Ideal

P586

Radix 16

Model flat

 

struc WndClassEx

cbSize dd 0

style dd 0

lpfnWndProc dd 0

cbClsExtra dd 0

cbWndExtra dd 0

hInstance dd 0

hIcon dd 0

hCursor dd 0

hbrBackground dd 0

lpszMenuName dd 0

lpszClassName dd 0

hIconSm dd 0

ends WndClassEx

 

struc Point

left dd 0

top dd 0

right dd 0

bottom dd 0

ends Point

 

struc msgStruc

hwnd dd 0

message dd 0

wParam dd 0

lParam dd 0

time dd 0

pt Point <>

ends msgStruc

 

MyMenu = 0065

ID_OPEN = 9C41

ID_SAVE = 9C42

ID_EXIT = 9C43

 

CS_VREDRAW = 0001

CS_HREDRAW = 0002

IDI_APPLICATION = 7F00

IDC_ARROW = 7F00

COLOR_WINDOW = 5

WS_EX_WINDOWEDGE = 00000100

WS_EX_CLIENTEDGE = 00000200

WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE OR WS_EX_CLIENTEDGE

WS_OVERLAPPED = 00000000

WS_CAPTION = 00C00000

WS_SYSMENU = 00080000

WS_THICKFRAME = 00040000

WS_MINIMIZEBOX = 00020000

WS_MAXIMIZEBOX = 00010000

WS_OVERLAPPEDWINDOW = WS_OVERLAPPED OR \

WS_CAPTION OR \

WS_SYSMENU OR \

WS_THICKFRAME OR \

WS_MINIMIZEBOX OR \

WS_MAXIMIZEBOX

CW_USEDEFAULT = 80000000

SW_SHOW = 5

WM_COMMAND = 0111

WM_DESTROY = 0002

WM_CLOSE = 0010

MB_OK = 0

 

PROCTYPE ptGetModuleHandle stdcall \

lpModuleName :dword

 

PROCTYPE ptLoadIcon stdcall \

hInstance :dword, \

lpIconName :dword

 

PROCTYPE ptLoadCursor stdcall \

hInstance :dword, \

lpCursorName :dword

 

PROCTYPE ptLoadMenu stdcall \

hInstance :dword, \

lpMenuName :dword

 

PROCTYPE ptRegisterClassEx stdcall \

lpwcx :dword

 

PROCTYPE ptCreateWindowEx stdcall \

dwExStyle :dword, \

lpClassName :dword, \

lpWindowName :dword, \

dwStyle :dword, \

x :dword, \

y :dword, \

nWidth :dword, \

nHeight :dword, \

hWndParent :dword, \

hMenu :dword, \

hInstance :dword, \

lpParam :dword

 

PROCTYPE ptShowWindow stdcall \

hWnd :dword, \

nCmdShow :dword

 

PROCTYPE ptUpdateWindow stdcall \

hWnd :dword

 

PROCTYPE ptGetMessage stdcall \

pMsg :dword, \

hWnd :dword, \

wMsgFilterMin :dword, \

wMsgFilterMax :dword

 

PROCTYPE ptTranslateMessage stdcall \

lpMsg :dword

 

PROCTYPE ptDispatchMessage stdcall \

pmsg :dword

 

PROCTYPE ptSetMenu stdcall \

hWnd :dword, \

hMenu :dword

 

PROCTYPE ptPostQuitMessage stdcall \

nExitCode :dword

 

PROCTYPE ptDefWindowProc stdcall \

hWnd :dword, \

Msg :dword, \

wParam :dword, \

lParam :dword

 

PROCTYPE ptSendMessage stdcall \

hWnd :dword, \

Msg :dword, \

wParam :dword, \

lParam :dword

 

PROCTYPE ptMessageBox stdcall \

hWnd :dword, \

lpText :dword, \

lpCaption :dword, \

uType :dword

 

PROCTYPE ptExitProcess stdcall \

exitCode :dword

 

extrn GetModuleHandleA :ptGetModuleHandle

extrn LoadIconA :ptLoadIcon

extrn LoadCursorA :ptLoadCursor

extrn RegisterClassExA :ptRegisterClassEx

extrn LoadMenuA :ptLoadMenu

extrn CreateWindowExA :ptCreateWindowEx

extrn ShowWindow :ptShowWindow

extrn UpdateWindow :ptUpdateWindow

extrn GetMessageA :ptGetMessage

extrn TranslateMessage :ptTranslateMessage

extrn DispatchMessageA :ptDispatchMessage

extrn SetMenu :ptSetMenu

extrn PostQuitMessage :ptPostQuitMessage

extrn DefWindowProcA :ptDefWindowProc

extrn SendMessageA :ptSendMessage

extrn MessageBoxA :ptMessageBox

extrn ExitProcess :ptExitProcess

 

UDataSeg

hInst dd ?

hWnd dd ?

 

IFNDEF VER1

hMenu dd ?

ENDIF

 

 

DataSeg

msg msgStruc <>

classTitle db 'Menu demo', 0

wndTitle db 'Demo program', 0

msg_open_txt db 'You selected open', 0

msg_open_tlt db 'Open box', 0

msg_save_txt db 'You selected save', 0

msg_save_tlt db 'Save box', 0

 

CodeSeg

Start: call GetModuleHandleA, 0 ; ,

mov [hInst],eax

 

sub esp,SIZE WndClassEx ;

 

mov [(WndClassEx esp).cbSize],SIZE WndClassEx

mov [(WndClassEx esp).style],CS_HREDRAW or CS_VREDRAW

mov [(WndClassEx esp).lpfnWndProc],offset WndProc

mov [(WndClassEx esp).cbWndExtra],0

mov [(WndClassEx esp).cbClsExtra],0

mov [(WndClassEx esp).hInstance],eax

call LoadIconA, 0, IDI_APPLICATION

mov [(WndClassEx esp).hIcon],eax

call LoadCursorA, 0, IDC_ARROW

mov [(WndClassEx esp).hCursor],eax

mov [(WndClassEx esp).hbrBackground],COLOR_WINDOW

IFDEF VER1

mov [(WndClassEx esp).lpszMenuName],MyMenu

ELSE

mov [(WndClassEx esp).lpszMenuName],0

ENDIF

mov [(WndClassEx esp).lpszClassName],offset classTitle

mov [(WndClassEx esp).hIconSm],0

call RegisterClassExA, esp ;

 

add esp,SIZE WndClassEx ;

;

IFNDEF VER2

call CreateWindowExA, WS_EX_OVERLAPPEDWINDOW, \ extended window style

offset classTitle, \ pointer to registered class name

offset wndTitle,\ pointer to window name

WS_OVERLAPPEDWINDOW, \ window style

CW_USEDEFAULT, \ horizontal position of window

CW_USEDEFAULT, \ vertical position of window

CW_USEDEFAULT, \ window width

CW_USEDEFAULT, \ window height

0, \ handle to parent or owner window

0, \ handle to menu, or child-window identifier

[hInst], \ handle to application instance

0 ; pointer to window-creation data

ELSE

call LoadMenu, hInst, MyMenu

mov [hMenu],eax

call CreateWindowExA, WS_EX_OVERLAPPEDWINDOW, \ extended window style

offset classTitle, \ pointer to registered class name

offset wndTitle, \ pointer to window name

WS_OVERLAPPEDWINDOW, \ window style

CW_USEDEFAULT, \ horizontal position of window

CW_USEDEFAULT, \ vertical position of window

CW_USEDEFAULT, \ window width

CW_USEDEFAULT, \ window height

0, \ handle to parent or owner window

eax, \ handle to menu, or child-window identifier

[hInst], \ handle to application instance

0 ; pointer to window-creation data

ENDIF

mov [hWnd],eax

call ShowWindow, eax, SW_SHOW ; show window

call UpdateWindow, [hWnd] ; redraw window

 

IFDEF VER3

call LoadMenuA, [hInst], MyMenu

mov [hMenu],eax

call SetMenu, [hWnd], eax

ENDIF

 

msg_loop:

call GetMessageA, offset msg, 0, 0, 0

or ax,ax

jz exit

call TranslateMessage, offset msg

call DispatchMessageA, offset msg

jmp msg_loop

exit: call ExitProcess, 0

 

public stdcall WndProc

proc WndProc stdcall

arg @@hwnd: dword, @@msg: dword, @@wPar: dword, @@lPar: dword

mov eax,[@@msg]

cmp eax,WM_COMMAND

je @@command

cmp eax,WM_DESTROY

jne @@default

call PostQuitMessage, 0

xor eax,eax

jmp @@ret

@@default:

call DefWindowProcA, [@@hwnd], [@@msg], [@@wPar], [@@lPar]

@@ret: ret

@@command:

mov eax,[@@wPar]

cmp eax,ID_OPEN

je @@open

cmp eax,ID_SAVE

je @@save

call SendMessageA, [@@hwnd], WM_CLOSE, 0, 0

xor eax,eax

jmp @@ret

@@open: mov eax, offset msg_open_txt

mov edx, offset msg_open_tlt

jmp @@mess

@@save: mov eax, offset msg_save_txt

mov edx, offset msg_save_tlt

@@mess: call MessageBoxA, 0, eax, edx, MB_OK

xor eax,eax

jmp @@ret

endp WndProc

end Start

API Win32. ( API Win32) , , . , . , , , API Win32 .

. (), VER2 VER3 ( VER1). . , , CreateWindowEx. , . , , . , .

. , . , , , . , , () .

(esp). WndClassEx. () esp:

sub esp,SIZE WndClassEx

. 16- . . , , , . (heap) (virtual memory).

- . .

DOS. Win32 . , . , Win32 , . , , / . , . , , . . , , .

macro MessageVector message1, message2:REST

IFNB <message1>

dd message1

dd offset @@&message1

@@VecCount = @@VecCount + 1

MessageVector message2

ENDIF

endm MessageVector

 

macro WndMessages VecName, message1, message2:REST

@@VecCount = 0

DataSeg

label @@&VecName dword

MessageVector message1, message2

@@&VecName&Cnt = @@VecCount

CodeSeg

mov ecx,@@&VecName&Cnt

mov eax,[@@msg]

@@&VecName&_1: dec ecx

js @@default

cmp eax,[dword ecx * 8 + offset @@&VecName]

jne @@&VecName&_1

jmp [dword ecx + offset @@&VecName + 4]

 

@@default: call DefWindowProcA, [@@hWnd], [@@msg], [@@wPar], [@@lPar]

@@ret: ret

@@ret_false: xor eax,eax

jmp @@ret

@@ret_true: mov eax,-1

dec eax

jmp @@ret

endm WndMessage

 

WndMessages, , . :

 

proc WndProc stdcall

arg @@hWnd: dword, @@msg: dword, @@wPar: dword, @@lPar: dword

WndMessages WndVector, WM_CREATE, WM_SIZE, WM_PAINT, WM_CLOSE, WM_DESTROY

 

@@WM_CREATE:

; WM_CREATE

@@WM_SIZE:

; WM_SIZE

@@WM_PAINT:

; WM_PAINT

@@WM_CLOSE:

; WM_CLOSE

@@WM_DESTROY:

; WM_DESTROY

 

endp WndProc

 

:

-          TRUE, @@ret_true;

-          FALSE, @@ret_false;

-          , @@default.

, WndMessages .

, WndMessages. ( ). , . @@ . &. , TestLabel, : @@TestLabel. MessageVector, , , , . MessageVector . dword . dword , . . , , .

WndMessage . , , .

Windows , , , . , WM_COMMAND / . , . , , , , (controls) . , . , . , , , . .

. , .

, Win32 :

-          ( TASM32 TLINK32 TASM 5.0). patch, . Patch site www.borland.com ftp ftp.uralmet.ru.

-          ( Developer Studio brcc32.exe);

-          header , API Win32 , : Ideal MASM.

Win32, , , , multimedia . DOS, , , .

1. ,

resource.inc

IDD_DIALOG = 65 ; 101

IDR_NAME = 3E8 ; 1000

IDC_STATIC = -1

resource.h

#define IDD_DIALOG 101

#define IDR_NAME 1000

#define IDC_STATIC -1

dlg.def

NAME TEST

DESCRIPTION 'Demo dialog'

EXETYPE WINDOWS

EXPORTS DlgProc @1

makefile

# Make file for Demo dialog

# make -B

 

NAME = dlg

OBJS = $(NAME).obj

DEF = $(NAME).def

RES = $(NAME).res

 

TASMOPT=/m3 /mx /z /q /DWINVER=0400 /D_WIN32_WINNT=0400

 

!if $d(DEBUG)

TASMDEBUG=/zi

LINKDEBUG=/v

!else

TASMDEBUG=/l

LINKDEBUG=

!endif

 

!if $d(MAKEDIR)

IMPORT=$(MAKEDIR)\..\lib\import32

!else

IMPORT=import32

!endif

 

$(NAME).EXE: $(OBJS) $(DEF) $(RES)

tlink32 /Tpe /aa /c $(LINKDEBUG) $(OBJS),$(NAME),, $(IMPORT), $(DEF), $(RES)

 

.asm.obj:

tasm32 $(TASMDEBUG) $(TASMOPT) $&.asm

 

$(RES): $(NAME).RC

BRCC32 -32 $(NAME).RC

2. ,

mylib.def

LIBRARY MYLIB

DESCRIPTION 'DLL EXAMPLE, 1997'

EXPORTS Hex2Str @1

 

makefile

# Make file for Demo DLL# make B# make B DDEBUG for debug information

 

NAME = mylib

OBJS = $(NAME).obj

DEF = $(NAME).def

RES = $(NAME).res

 

TASMOPT=/m3 /mx /z /q /DWINVER=0400 /D_WIN32_WINNT=0400

 

!if $d(DEBUG)

TASMDEBUG=/zi

LINKDEBUG=/v

!else

TASMDEBUG=/l

LINKDEBUG=

!endif

 

!if $d(MAKEDIR)

IMPORT=$(MAKEDIR)\..\lib\import32

!else

IMPORT=import32

!endif

 

$(NAME).EXE: $(OBJS) $(DEF)

tlink32 /Tpd /aa /c $(LINKDEBUG) $(OBJS),$(NAME),, $(IMPORT), $(DEF)

 

.asm.obj:

tasm32 $(TASMDEBUG) $(TASMOPT) $&.asm

 

$(RES): $(NAME).RC

BRCC32 -32 $(NAME).RC

3. ,

dmenu.def

NAME TEST

DESCRIPTION 'Demo menu'

EXETYPE WINDOWS

EXPORTS WndProc @1

dmenu.rc

#include "resource.h

"MyMenu MENU DISCARDABLE

BEGIN POPUP "Files"

BEGIN

MENUITEM "Open", ID_OPEN

MENUITEM "Save", ID_SAVE

MENUITEM SEPARATOR

MENUITEM "Exit", ID_EXIT

END

MENUITEM "Other", 65535

END

resource.h

#define MyMenu 101

#define ID_OPEN 40001

#define ID_SAVE 40002

#define ID_EXIT 40003

makefile

# Make file for Turbo Assembler Demo menu

# make B

# make -B -DDEBUG -DVERN for debug information and version

NAME = dmenu

OBJS = $(NAME).obj

DEF = $(NAME).def

RES = $(NAME).res

!if $d(DEBUG)

TASMDEBUG=/zi

LINKDEBUG=/v

!else

TASMDEBUG=/l

LINKDEBUG=

!endif

 

!if $d(VER2)

TASMVER=/dVER2

!elseif $d(VER3)

TASMVER=/dVER3

!else

TASMVER=/dVER1

!endif

 

!if $d(MAKEDIR)

IMPORT=$(MAKEDIR)\..\lib\import32

!else

IMPORT=import32

!endif

 

$(NAME).EXE: $(OBJS) $(DEF) $(RES)

tlink32 /Tpe /aa /c $(LINKDEBUG) $(OBJS),$(NAME),, $(IMPORT), $(DEF), $(RES)

 

.asm.obj:

tasm32 $(TASMDEBUG) $(TASMVER) /m /mx /z /zd $&.asm

 

$(RES): $(NAME).RC

BRCC32 -32 $(NAME).RC











helloworld.ru © 2001-2016
Rambler's Top100 TopList Rambler's Top100