td win32asm 230.asm

8
td_win32asm_230.asm ;============================================================================== ; Test Department's WINDOWS 32 BIT x86 ASSEMBLY example 230 ;============================================================================== ;============================================================================== ; ==> Part 230 : The Animate Class ;------------------------------------------------------------------------------ ; Hello, ; Test Department presents: Dancer in the Dark. ; It seems that the animation is suspended by several reasons. ; Please imagine that this class is not the same then playing AVI files via ; the Multimedia Library ! ; You can only play AVI file without (!) sound. ; But it is a simple way to include an animation in your program. ; Search in Win32.hlp for ANIMATE_CLASS. ; ; Test Department [email protected] ;============================================================================== ; Assembler directives ;------------------------------------------------------------------------------ .386 ; specifies the processor our program want run on .Model Flat ,StdCall ; Flat for Win9x (32 Bit), Calling Convention option casemap:none ; case sensitive ! ;============================================================================== ; Include all files where API functins resist you want use, set correct path ;------------------------------------------------------------------------------ include D:\Masm32\include\windows.inc includelib kernel32.lib includelib user32.lib includelib gdi32.lib includelib comctl32.lib ;============================================================================== ; Declaration of used API functions,take a look into WIN32.HLP and *.inc files ;------------------------------------------------------------------------------ GetModuleHandleA PROTO :DWORD LoadIconA PROTO :DWORD,:DWORD LoadCursorA PROTO :DWORD,:DWORD CreateSolidBrush PROTO :DWORD RegisterClassExA PROTO :DWORD CreateWindowExA PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD, :DWORD,:DWORD,:DWORD,:DWORD,:DWORD ShowWindow PROTO :DWORD,:DWORD UpdateWindow PROTO :DWORD GetMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORD TranslateMessage PROTO :DWORD DispatchMessageA PROTO :DWORD PostQuitMessage PROTO :DWORD DefWindowProcA PROTO :DWORD,:DWORD,:DWORD,:DWORD ExitProcess PROTO :DWORD InvalidateRect PROTO :DWORD,:DWORD,:DWORD Page 1

Upload: z4rm4r

Post on 05-Jan-2016

226 views

Category:

Documents


1 download

DESCRIPTION

Skola asemblera TD zakon

TRANSCRIPT

td_win32asm_230.asm;==============================================================================; Test Department's WINDOWS 32 BIT x86 ASSEMBLY example 230;==============================================================================

;==============================================================================; ==> Part 230 : The Animate Class;------------------------------------------------------------------------------; Hello,; Test Department presents: Dancer in the Dark.; It seems that the animation is suspended by several reasons.; Please imagine that this class is not the same then playing AVI files via; the Multimedia Library !; You can only play AVI file without (!) sound.; But it is a simple way to include an animation in your program.; Search in Win32.hlp for ANIMATE_CLASS.;; Test Department [email protected]

;==============================================================================; Assembler directives;------------------------------------------------------------------------------.386 ; specifies the processor our program want run on.Model Flat ,StdCall ; Flat for Win9x (32 Bit), Calling Conventionoption casemap:none ; case sensitive !

;==============================================================================; Include all files where API functins resist you want use, set correct path;------------------------------------------------------------------------------include D:\Masm32\include\windows.incincludelib kernel32.libincludelib user32.libincludelib gdi32.libincludelib comctl32.lib

;==============================================================================; Declaration of used API functions,take a look into WIN32.HLP and *.inc files;------------------------------------------------------------------------------GetModuleHandleA PROTO :DWORDLoadIconA PROTO :DWORD,:DWORDLoadCursorA PROTO :DWORD,:DWORDCreateSolidBrush PROTO :DWORDRegisterClassExA PROTO :DWORDCreateWindowExA PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD, :DWORD,:DWORD,:DWORD,:DWORD,:DWORDShowWindow PROTO :DWORD,:DWORDUpdateWindow PROTO :DWORDGetMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORDTranslateMessage PROTO :DWORDDispatchMessageA PROTO :DWORDPostQuitMessage PROTO :DWORDDefWindowProcA PROTO :DWORD,:DWORD,:DWORD,:DWORDExitProcess PROTO :DWORDInvalidateRect PROTO :DWORD,:DWORD,:DWORD

Page 1

td_win32asm_230.asmDestroyWindow PROTO :DWORDSendMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORDInitCommonControls PROTO

;==============================================================================; .const = the constants area starts here,constants are defined and fixed;------------------------------------------------------------------------------.const; - Parameter MAIN WINDOW CallBack Procedure ( API=RegisterClassExA ) -WP1_CallBack equ [ebp+4] ;return addressWP1_hWnd equ [ebp+8] ;handle of window who receives messageWP1_uMsg equ [ebp+12] ;the message numberWP1_wParam equ [ebp+16] ;extra info about the messageWP1_lParam equ [ebp+20] ;extra info about the message

;==============================================================================; .Data = the data area starts here, datas are defined but not fixed;------------------------------------------------------------------------------.DataIconName db "TDIcon",0 ;icon name in resourceAviName db "TDAvi",0 ;avi name in resourceClass db "TDWinClass",0 ;name of window classWindowName db "Test Department - http://surf.to/TestD",0class_ANIMATE_CLASS db "SysAnimate32",0 ;predefined class

;==============================================================================; .Data? = the data? area starts here, not defined and not fixed;------------------------------------------------------------------------------.data?hWnd_Animate dd ? ;handle animate control

align 4; - WndClassEx Structure ( API=RegisterClassExA ) -cbSize dd ? ;size in bytes of this structurestyle dd ? ;window stylelpfnWndProc dd ? ;address of user proc functioncbclsExtra dd ? ;extra bytes to allocate set to 0cbWndExtra dd ? ;extra bytes class directive, rc filehInstance dd ? ;program handle(API=GetModuleHandleA)hIcon dd ? ;handle of icon (API=LoadIconA)hcursor dd ? ;handle of cursor (API=LoadCursor)hbrBackground dd ? ;background color, 0=transparentlpszMenuName dd ? ;name of menu class in resource filelpszClassName dd ? ;name of windows this window classhIconSm dd ? ;iconhandle 0=search in resource filehdcDest dd ? ;handle of dest. device context

align 4; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structurehWnd dd ? ;handle of window who receives messagemessage dd ? ;the message numberwParam dd ? ;extra info about the messagelParam dd ? ;extra info about the message

Page 2

td_win32asm_230.asmtime dd ? ;time the message was postedxpt dd ? ;cursor x-position, POINT strucypt dd ? ;cursor x-position, POINT struc

;==============================================================================; .CODE = our code area starts here Main = label of our program code;------------------------------------------------------------------------------.CodeMain:

;==============================================================================; Always get your program ID first (API=GetModuleHandleA);------------------------------------------------------------------------------push 0h ;lpModuleHandle, 0=get program handlecall GetModuleHandleA ;- API Function -mov hInstance,eax ;return value in eax=handle of program

;==============================================================================; Animate Class seems to be part of common controls, force to init...;------------------------------------------------------------------------------call InitCommonControls ;- API Function -

;==============================================================================; The API function "RegisterClassExA" registers a window class.; This API needs a "WNDCLASSEX" structure so we fill it with correct values.;------------------------------------------------------------------------------mov cbSize,30h ;size in bytes of WNDCLASSEX structuremov style,3h ;window stylemov lpfnWndProc,OFFSET WP1 ;address of user lpfnWndProc functionmov cbclsExtra,0h ;extra bytes to allocate set to 0mov cbWndExtra,0h ;class directive in rc file;------------------------------------------------------------------------------; API "CreateSolidBrush" creates a logical brush with the specified solid color;------------------------------------------------------------------------------push 00000000h ;crColor, brush color value BLACK POWER ;)call CreateSolidBrush ;- API Function -mov hbrBackground,eax ;background colormov lpszMenuName,0h ;menu name in resource file,0=no menumov lpszClassName,OFFSET Class ;name of windows classmov hIconSm,0h ;iconhandle 0=search in rc file;------------------------------------------------------------------------------; API "LoadIconA" loads an icon defined in the resource file and stores the; handle in the "WNDCLASSEX" structure;------------------------------------------------------------------------------push OFFSET IconName ;icon-string or icon resource idpush hInstance ;our program handlecall LoadIconA ;- API Function -mov hIcon,eax ;store handle of newly loaded icon;------------------------------------------------------------------------------; API "LoadCursorA" loads a default system cursor, in this case we must set; hInstance to 0 and lpCursorName to a default system cursor value, here 32512; Then we store the cursor handle in the "WNDCLASSEX" structure;------------------------------------------------------------------------------

Page 3

td_win32asm_230.asmpush 32512 ;lpCursorName, default value in dezimalpush 0h ;hInstance, 0=default system cursorcall LoadCursorA ;- API Function -mov hcursor,eax ;store handle of the cursor;------------------------------------------------------------------------------; Now, after filled the "WNDCLASSEX" structure we call API "RegisterClassEx";------------------------------------------------------------------------------push OFFSET cbSize ;pointer to WNDCLASSEX structurecall RegisterClassExA ;- API Function -

;==============================================================================; API "CreateWindowExA" creates an overlapped, pop-up, or child window with an; extended style. The return value in EAX is the handle of the new window.; This API sends a WM_CREATE message to the window procedure (WP1).;------------------------------------------------------------------------------push 0h ;lpParam, extra pointer data 0=no datapush hInstance ;hInstance, handle of our programpush 0h ;hMenu, handle window menu 0=class menupush 0h ;hWndParent, handle parent window 0=nopush 0A8h ;intnHeight, window height pixelpush 0140h ;intnWidth, window width pixelpush 040h ;inty, vertical position windowpush 080h ;intx, horizontal position windowpush 04CA0000h ;dwStyle, look into WIN32.HLPpush OFFSET WindowName ;lpWindowName, pointer to window namepush OFFSET Class ;lpClassName, pointer to class namepush 0100h ;dwExStyle, extra window style 0=nocall CreateWindowExA ;- API Function -mov hWnd,eax ;hwnd,return value=handle of window

;==============================================================================; API "ShowWindow" function sets the specified window's show state. ;------------------------------------------------------------------------------push 1h ;nCmdShow, show state 1=SW_SHOWNORMALpush hWnd ;hwnd, handle of windowcall ShowWindow ;- API Function -

;==============================================================================; API "UpdateWindow" updates the area of the specified window by sending a; WM_PAINT message to the window if the window's update region is not empty.;------------------------------------------------------------------------------push hWnd ;hwnd, handle of windowcall UpdateWindow ;- API Function -

LoopGetMessage:;==============================================================================; API "GetMessageA" retrieves a message + places it in the specified structure.;------------------------------------------------------------------------------push 0h ;wMsgFilterMax, highest message valuepush 0h ;wMsgFilterMin, lowest message valuepush 0h ;hWnd, handle of window who gets msg.push OFFSET hWnd ;lpMsg, pointer to MSG structurecall GetMessageA ;- API Function -

Page 4

td_win32asm_230.asmcmp eax,0h ;check if return value=0 (exit)je ExitPrg ;if return value is 0 goto LABEL

;==============================================================================; API "TranslateMessage" translates virtual-key messages in character messages;------------------------------------------------------------------------------push OFFSET hWnd ;lpMSG, pointer to msg structurecall TranslateMessage ;- API Function - keyboard code

;==============================================================================; API "DispatchMessageA" function dispatches a message to a window procedure.;------------------------------------------------------------------------------push OFFSET hWnd ;lpMSG, pointer to msg structurecall DispatchMessageA ;- API Function -jmp LoopGetMessage ;check for message again, goto LABEL

ExitPrg:;==============================================================================; Next we terminate our program (API=ExitProcess);------------------------------------------------------------------------------push hInstance ;push our programm handle to exitcall ExitProcess ;- API Function -

;##############################################################################; The Window Procedure (API=RegisterClassExA) for this registered window.;------------------------------------------------------------------------------WP1:push ebp ;create stack framemov ebp,esp ;pushad ;push all register to the stack

mov eax,WP1_uMsg ;move the message number to eax;==============================================================================; WM_CREATE (value=01h) message received ?;------------------------------------------------------------------------------WP1_uMsg_01h:cmp eax,1h ;check if WM_CREATE message recievedjne WP1_uMsg_02h ;if not goto LABEL;------------------------------------------------------------------------------; API "CreateWindowExA" creates a window with a predefined class name (ANIMATE);------------------------------------------------------------------------------push 0h ;lpParam, extra pointer data 0=no datapush hInstance ;hInstance, handle of our programpush 1000h ;hMenu, the child-window IDpush WP1_hWnd ;hWndParent, handle parent window 0=nopush 0h ;intnHeight, window height pixelpush 0h ;intnWidth, window width pixelpush 4h ;inty, vertical position windowpush 050h ;intx, horizontal position windowpush 50000000h ;dwStyle, ACS_AUTOPLAY=4, ACS_TRANSPARENT=2push 0h ;lpWindowName, pointer to window namepush OFFSET class_ANIMATE_CLASS ;lpClassName, pointer to class namepush 0h ;dwExStyle,

Page 5

td_win32asm_230.asmcall CreateWindowExA ;- API Function -mov hWnd_Animate,eax ;return value=handle of window;------------------------------------------------------------------------------; API "SendMessageA" sends a message to the main Window Procedure;------------------------------------------------------------------------------push OFFSET AviName ;lParam, pointer to avi name in resourcepush 0h ;wParam, not used, must be zeropush 1124 ;uMsg, ACM_OPEN = WM_USER(400h)+100push hWnd_Animate ;hwnd, handle of destination windowcall SendMessageA ;- API Function -;------------------------------------------------------------------------------; You must not call this if you choose ACS_AUTOPLAY;------------------------------------------------------------------------------push 0FFFF0000h ;lParam, 0FFFFh=end with last frame (-1) ; 0000h=start with first frame push 0FFFFFFFFh ;wParam, cRepeat, -1 = indefinitelypush 1125 ;uMsg, ACM_PLAY = WM_USER(400h)+101push hWnd_Animate ;hwnd, handle of destination windowcall SendMessageA ;- API Function -jmp WP1_return

;==============================================================================; WM_DESTROY (value=02h) message received ?;------------------------------------------------------------------------------WP1_uMsg_02h:cmp eax,2h ;check if value=2h (WM_DESTROY)jne WP1_uMsg_7Eh ;if not 2h go to LABELcall My_CleanSystem ;- SubRoutine -;------------------------------------------------------------------------------; API "PostQuitMessage" indicates to Windows a request to terminate;------------------------------------------------------------------------------push 0h ;nExitCode, exit code=wParamcall PostQuitMessage ;- API Function -popad ;pop all register back from stackxor eax,eax ;set eax to 0 to exit our programmov esp,ebp ;delete stack framepop ebp ;ret 10h ;return and clear stack

;==============================================================================; WM_DISPLAYCHANGE (value=7Eh) message, used to repaint the window area;------------------------------------------------------------------------------WP1_uMsg_7Eh:cmp eax,7Eh ;check if WM_DISPLAYCHANGE message recievedjne WP1_uMsg_112h ;if not goto label;------------------------------------------------------------------------------; API "InvalidateRect" adds a rectangle to specified window's update region.; This function performs a WM_PAINT message.;------------------------------------------------------------------------------push 0h ;bErase, erase-background flagpush 0h ;lpRect, rect structure, 0h=client areapush WP1_hWnd ;hWnd, handle window update regioncall InvalidateRect ;- API Function -

Page 6

td_win32asm_230.asmjmp WP1_return

;==============================================================================; WM_SYSCOMMAND (value=112h) message recieved ?;------------------------------------------------------------------------------WP1_uMsg_112h:cmp eax,112h ;check if WM_COMMAND message recievedjne WP1_return ;if not goto labelmov eax,WP1_wParam ;extra info about the messagecmp eax,0F060h ;SC_CLOSE=0F060h received ?jne WP1_return ;call My_CleanSystem ;- SubRoutine -jmp WP1_return

;==============================================================================; API "DefWindowProcA" calls the window procedure to provide default processing; for any window messages that an application does not process.; This function ensures that every message is processed.; It is called with the same parameters received by the window procedure.;------------------------------------------------------------------------------WP1_return:popad ;pop all register from stackpush WP1_lParam ;extra info about the messagepush WP1_wParam ;extra info about the messagepush WP1_uMsg ;the message numberpush WP1_hWnd ;handle of window who receives messagecall DefWindowProcA ;- API Function -mov esp,ebp ;delete stack framepop ebp ;ret 10h ;return and clear stack;##############################################################################

;******************************************************************************; My own subroutine(s) for a compacter code resist here ...;------------------------------------------------------------------------------My_CleanSystem:;------------------------------------------------------------------------------; API "DestroyWindow" function destroys the given window;------------------------------------------------------------------------------push hWnd_Animate ;hwnd, handle of window to destroycall DestroyWindow ;- API Function -ret;******************************************************************************

;==============================================================================; end Main = end of our program code;------------------------------------------------------------------------------end Main ;end of our program code, entry point

;==============================================================================; To create the exe file use this commands with your Microsoft Assembler/Linker;------------------------------------------------------------------------------; ml.exe /c /coff td_win32asm_230.asm ;asm command

Page 7

td_win32asm_230.asm; rc.exe /v rsrc.rc ;rc command; cvtres.exe /machine:ix86 rsrc.res; link.exe /subsystem:windows td_win32asm_230.obj rsrc.obj ;link command;==============================================================================

Page 8