td win32asm 220.asm

15
td_win32asm_220.asm ;============================================================================== ; Test Department's WINDOWS 32 BIT x86 ASSEMBLY EXAMPLE's 220 ;============================================================================== ;============================================================================== ; ==> Part 220 : Wave, Midi and AVI Player ;------------------------------------------------------------------------------ ; Buenos dias Companero's, ; today I am lazy and I don't like to write a description. ; If you have any question please refer to all my other examples or email me. ; For API MCIWndCreate we push 4 doublewords to the stack, we remove them ; after calling !!! ; "lpfnWndProc" is a pointer to the subroutine label "WindowProc" ( WP1 ) where ; all the action code for this main window resist. ; "lpfnWndProc" is part of WndClassEx structure used by API RegisterClassEx. ;============================================================================== ; Assembler directives ;------------------------------------------------------------------------------ .386 ; specifies the processor our program want run on .Model Flat ,StdCall ; always the same for Win95 (32 Bit) 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 winmm.lib includelib vfw32.lib ;============================================================================== ; Declaration of used API functions,take a look into WIN32.HLP and *.inc files ;------------------------------------------------------------------------------ GetModuleHandleA PROTO :DWORD LoadLibraryA PROTO :DWORD GetProcAddress PROTO :DWORD,:DWORD LoadIconA PROTO :DWORD,:DWORD LoadCursorA PROTO :DWORD,: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 FreeLibrary PROTO :DWORD ExitProcess PROTO :DWORD Page 1

Upload: z4rm4r

Post on 03-Dec-2015

212 views

Category:

Documents


0 download

DESCRIPTION

Skola asemblera TD zakon

TRANSCRIPT

Page 1: Td Win32asm 220.Asm

td_win32asm_220.asm;==============================================================================; Test Department's WINDOWS 32 BIT x86 ASSEMBLY EXAMPLE's 220;==============================================================================

;==============================================================================; ==> Part 220 : Wave, Midi and AVI Player;------------------------------------------------------------------------------; Buenos dias Companero's,; today I am lazy and I don't like to write a description.; If you have any question please refer to all my other examples or email me.; For API MCIWndCreate we push 4 doublewords to the stack, we remove them; after calling !!!; "lpfnWndProc" is a pointer to the subroutine label "WindowProc" ( WP1 ) where; all the action code for this main window resist.; "lpfnWndProc" is part of WndClassEx structure used by API RegisterClassEx.

;==============================================================================; Assembler directives;------------------------------------------------------------------------------.386 ; specifies the processor our program want run on.Model Flat ,StdCall ; always the same for Win95 (32 Bit)option 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 winmm.libincludelib vfw32.lib

;==============================================================================; Declaration of used API functions,take a look into WIN32.HLP and *.inc files;------------------------------------------------------------------------------GetModuleHandleA PROTO :DWORDLoadLibraryA PROTO :DWORDGetProcAddress PROTO :DWORD,:DWORDLoadIconA PROTO :DWORD,:DWORDLoadCursorA PROTO :DWORD,: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,:DWORDFreeLibrary PROTO :DWORDExitProcess PROTO :DWORD

Page 1

Page 2: Td Win32asm 220.Asm

td_win32asm_220.asmMessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORDDestroyWindow PROTO :DWORDMoveWindow PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORDSendMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORDLoadBitmapA PROTO :DWORD,:DWORDlstrcpyA PROTO :DWORD,:DWORDlstrcmpiA PROTO :DWORD,:DWORDDeleteObject PROTO :DWORDGetOpenFileNamePreviewA PROTO :DWORDAVIFileInit PROTOAVIFileOpenA PROTO :DWORD,:DWORD,:DWORD,:DWORDAVIFileInfoA PROTO :DWORD,:DWORD,:DWORDAVIFileRelease PROTO :DWORDAVIFileExit 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 rc fileMenuName db "TDMenu",0 ;menu name in rc fileClassName db "TDWinClass",0 ;name of windows classWindowName db "Test Department",0 ;window name titel barMB1_Titel db "Message Box",0 ;message box nameMB1_DllError db "can not load DLL: msvfw32.dll",0;message box textMB1_FunctionError db "can not find Function: MCIWndCreate",0;msgbox textMB1_AVIFileError db "AVI file corrupted or Format not supported",0;Library_Name db "msvfw32.dll",0 ;filename of the libraryf_MCIWndCreate db "MCIWndCreate",0 ;function name in librarySTATICClassName db "STATIC",0 ;predefined window classBUTTONClassName db "BUTTON",0 ;predefined window classSTATIC0000_WindowName db "Midi, Wave and Avi Player, enjoy ...",0;BUTTON0500_WindowName db "Bitmap",0 ;default window nameSTATIC0000_text db "filename.ext",0 ;BUTTON0500_text db "Open",0 ;LoadFileFilte db "*.mid, *.wav, *.avi",0,"*.mid;*.wav;*.avi",0,0;LoadFileTitle db "Select a File",0 ;AVIextender db "avi",0 ;def. video file extender

;==============================================================================; .Data? = the data? area starts here, not defined and not fixed;------------------------------------------------------------------------------

Page 2

Page 3: Td Win32asm 220.Asm

td_win32asm_220.asm.data?STATIC0000_hWnd dd ? ;handle of STATIC windowBUTTON0500_hWnd dd ? ;handle of BUTTON windowhLibrary dd ? ;loaded library handlep_MCIWndCreate dd ? ;pointer function inside DLLmcihWnd dd ? ;handle of mci windowhObject dd ? ;handle of bitmapmci_filehandle dd ? ;fip dd ? ;tempCallBack dd ? ;temporary variableLoadFileBuffer db 104h dup(?) ;buffer for load filenameTestFileName db 104h dup(?) ;buffer, filenameMediaFileName db 104h dup(?) ;buffer, filename

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 file

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 time dd ? ;time the message was posted xpt dd ? ;cursor x-position, POINT strucypt dd ? ;cursor x-position, POINT struc

align 4; - OPENFILENAME Structure ( API=GetOpenFileNamePreviewA ) -lStructSize dd ? ;the length in bytes of structure hWndOwner dd ? ;handle window that owns dialog box hInstance1 dd ? ;handle, our program handlelpstrFilter dd ? ;pointer to string + filterlpstrCustomFilter dd ? ;pointer to user defined filternMaxCustFilter dd ? ;size bytes/characters of abovenFilterIndex dd ? ;filter index of lpstrFilter lpstrFile dd ? ;pointer initialize filename, 0=nonMaxFile dd ? ;size bytes/characters of abovelpstrFileTitle dd ? ;pointer title of the selected filenMaxFileTitle dd ? ;size of the lpstrFileTitle buffer lpstrInitialDir dd ? ;pointer init file dir,0=default

Page 3

Page 4: Td Win32asm 220.Asm

td_win32asm_220.asmlpstrTitle dd ? ;pointer title of the box Flags dd ? ;the dialog box creation flags nFileOffset dw ? ;offset filename in string lpstrFile nFileExtension dw ? ;offset extension in string lpstrFile lpstrDefExt dd ? ;pointer to default extension of file lCustData dd ? ;? lpfnHook dd ? ;used if flag is OFN_ENABLETEMPLATElpTemplateName dd ? ;used if flag is OFN_ENABLETEMPLATE

align 4; - AVIFILEINFO Structure ( API=AVIFileInfoA ) -dwMaxBytesPerSec dd ? ;maximum data rate of the AVI file dwFlags dd ? ;applicable flags dwCaps dd ? ;capability flags dwStreams dd ? ;number of streams in the file dwSuggestedBufferSize dd ? ;buffer size in bytes for reading file dwWidth dd ? ;width in pixels of the AVI file dwHeight dd ? ;height in pixels of the AVI file dwScale dd ? ;time scale applicable for entire file dwRate dd ? ;dwRate / dwScale = samples per second dwLength dd ? ;length of the AVI filedwEditCount dd ? ;# streams added/deleted from AVI file szFileType db 40h dup(?) ;string containing file type infos

;==============================================================================; .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

;==============================================================================; API LoadLibraryA maps the specified exe or dll module into the address space; of the calling process.;------------------------------------------------------------------------------push OFFSET Library_Name ;lpLibFileName, pointer filename modulecall LoadLibraryA ;- API Function -cmp eax,0h ;check if return value 0h=ERROR !jne Library_OK ;if no ERROR goto LABELmov ebx,OFFSET MB1_DllError ;lpText,pointer to text message boxcall My_MessageBoxA ;- SUBROUTINE -jmp ExitPrg

Library_OK:mov hLibrary,eax ;store handle of library in variable;==============================================================================; API "GetProcAddress" gets the address of the specified function !

Page 4

Page 5: Td Win32asm 220.Asm

td_win32asm_220.asm;------------------------------------------------------------------------------push OFFSET f_MCIWndCreate ;pProcName, name of functionpush hLibrary ;hModule, handle to DLL modulecall GetProcAddress ;- API Function -cmp eax,0h ;check if return value 0h=ERROR !jne Function_OK ;if no ERROR goto LABELmov ebx,OFFSET MB1_FunctionError ;lpText,pointer to text message boxcall My_MessageBoxA ;- SUBROUTINE -jmp FreeLib

Function_OK:mov p_MCIWndCreate,eax ;store given pointer to the 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 filemov hbrBackground,10h ;background,1=background(parameter+1)mov lpszMenuName,0h ;menu name in resource file,0=no menumov lpszClassName,OFFSET ClassName ;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 ;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;------------------------------------------------------------------------------push 32512 ;lpCursorName,default value in dezimalpush 0h ;hInstance, 0=default system cursorcall LoadCursorA ;- API Function -mov hcursor,eax ;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).;------------------------------------------------------------------------------

Page 5

Page 6: Td Win32asm 220.Asm

td_win32asm_220.asmpush 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 00000068h ;intnHeight, window height pixelpush 00000136h ;intnWidth, window width pixelpush 00000010h ;inty, vertical position windowpush 00000050h ;intx, horizontal position windowpush 04CA0000h ;dwStyle, look into WIN32.HLPpush OFFSET WindowName ;lpWindowName, pointer to window namepush OFFSET ClassName ;lpClassName, pointer to class namepush 0300h ;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 -

;==============================================================================; API "GetMessageA" retrieves a message & places it in the specified structure.;------------------------------------------------------------------------------LoopGetMessage: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 -cmp eax,0h ;check if return value=0 (exit)je FreeLib ;if return value is 0 goto LABEL

;==============================================================================; API "TranslateMessage" translates key code into ASCII 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

Page 6

Page 7: Td Win32asm 220.Asm

td_win32asm_220.asm

;------------------------------------------------------------------------------; API FreeLibrary unmaps the modul from address space of the calling process;------------------------------------------------------------------------------FreeLib:push hLibrary ;hLibModule, handle loaded lib. modulecall FreeLibrary ;- API Function -

;==============================================================================; Next we terminate our program (API=ExitProcess);------------------------------------------------------------------------------ExitPrg: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 MCIWndCreate registers the MCIWnd window class and creates an MCIWnd; child window for using MCI services.; API MCIWndCreate can also open an MCI device or file and associate it with; the MCIWnd window.; For API MCIWndCreate we push 4 doublewords to the stack, we remove them; after calling !!!;------------------------------------------------------------------------------push OFFSET MediaFileName ;szFile, name MCI device or data filepush 54400008h ;dwStyle, defines the window stylepush hInstance ;hInstance, handle of module instancepush WP1_hWnd ;hwndParent, handle parent window 0=nocall [p_MCIWndCreate] ;- API Function -mov mcihWnd,eax ;handle of MCI windowpop eax ;clear stack !pop eaxpop eaxpop eaxcall My_MoveWindow ;- SUBROUTINE -;------------------------------------------------------------------------------; In this case API "CreateWindowExA" creates a child window with a predefined; window class name, here BUTTON !; Parameter dwStyle defines the button: BS_PUSHBUTTON (0h) OR BS_BITMAP (80h)

Page 7

Page 8: Td Win32asm 220.Asm

td_win32asm_220.asm; dwStyle defines also WS_VISIBLE ( 10000000h ) OR WS_CHILD ( 40000000h ); Don't forget to take a look into WIN32.HLP ( CreateWindow ) and Windows.inc.; In hMenu we PUSH the ID of the child window ( a value of your your choice ); The return value in EAX is the handle of the new child window.;------------------------------------------------------------------------------push 0h ;lpParam, extra pointer data 0=no datapush hInstance ;hInstance, handle of our programpush 0500h ;hMenu, the child-window IDpush WP1_hWnd ;hWndParent, handle parent window 0=nopush 00000018h ;intnHeight, window height pixelpush 00000018h ;intnWidth, window width pixelpush 00000004h ;inty, vertical position windowpush 00000004h ;intx, horizontal position windowpush 54000080h ;dwStyle, button stylepush OFFSET BUTTON0500_WindowName ;lpWindowName, pointer to window namepush OFFSET BUTTONClassName ;lpClassName, pointer to class namepush 0h ;dwExStyle,call CreateWindowExA ;- API Function -mov BUTTON0500_hWnd,eax ;return value=handle of window;------------------------------------------------------------------------------; API "LoadBitmapA" loads a bitmap from the resource file;------------------------------------------------------------------------------push 80h ;lpBitmapName, bitmap resource IDpush hInstance ;hInstance, handle of modul instancecall LoadBitmapA ;- API Function -mov hObject,eax ;hObject, handle of graphic object;------------------------------------------------------------------------------; API "SendMessageA" sends a message to the Window Procedure lpfnWndProc;------------------------------------------------------------------------------push eax ;lParam, handle of bitmappush 0h ;wParam, first message ( IMAGE_BITMAP )push 0F7h ;uMsg, message to send ( BM_SETIMAGE )push BUTTON0500_hWnd ;hWnd, handle of destination windowcall SendMessageA ;- API Function -;------------------------------------------------------------------------------; API "CreateWindowExA" creates an overlapped, pop-up, or child window with an; extended style here with a predefined class name ( STATIC ).; The return value in EAX is the handle of the new window.;------------------------------------------------------------------------------push 0h ;lpParam, extra pointer data 0=no datapush hInstance ;hInstance, handle of our programpush 0h ;hMenu, handle window menu 0=class menupush WP1_hWnd ;hWndParent, handle parent window 0=nopush 00000016h ;intnHeight, window height pixelpush 00000108h ;intnWidth, window width pixelpush 00000005h ;inty, vertical position windowpush 00000020h ;intx, horizontal position windowpush 54000000h ;dwStyle, look WIN32.HLP + windows.incpush OFFSET STATIC0000_WindowName ;lpWindowName, pointer to window namepush OFFSET STATICClassName ;lpClassName, pointer to class namepush 0300h ;dwExStyle,look WIN32.HLP + windows.inccall CreateWindowExA ;- API Function -mov STATIC0000_hWnd,eax ;hwnd,return value=handle of window

Page 8

Page 9: Td Win32asm 220.Asm

td_win32asm_220.asmjmp WP1_return

;==============================================================================; WM_DESTROY (value=02h) message received ?;------------------------------------------------------------------------------WP1_uMsg_02h:cmp eax,2h ;check if value=2h (WM_DESTROY)jne WP1_uMsg_111h ;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_COMMAND (value=111h) message recieved ?;------------------------------------------------------------------------------WP1_uMsg_111h:cmp eax,111h ;check if WM_COMMAND message recievedjne WP1_uMsg_112h ;if not goto labelmov eax,WP1_wParam ;extra info about the message in axcmp ax,500h ;check if button ID=0500h clickedjne WP1_return ;if not 1h goto LABEL;------------------------------------------------------------------------------; API "GetOpenFileNamePreviewA" selects a file by using the Open dialog box.; The dialog box also allows the user to preview the currently specified file.; Look for parameter names into WIN32.HLP + parameter values into windows.inc.;------------------------------------------------------------------------------mov lStructSize,4Ch ;length in bytes of structuremov eax,WP1_hWndmov hWndOwner,eax ;id window that owns dialog boxmov eax,hInstancemov hInstance1,eax ;handle, our program idmov lpstrFilter,OFFSET LoadFileFilte;pointer to string + filter, 0= nomov lpstrCustomFilter,0h ;pointer to user defined filtermov nMaxCustFilter,0h ;size bytes/characters of abovemov nFilterIndex,0h ;filter index of lpstrFilter mov lpstrFile,OFFSET LoadFileBuffer ;pointer to filename buffermov nMaxFile,104h ;max size bytes/characters of abovemov lpstrFileTitle,0h ;pointer title of the selected filemov nMaxFileTitle,0h ;size of the lpstrFileTitle buffer mov lpstrInitialDir,0h ;pointer init file dir,0=defaultmov lpstrTitle,OFFSET LoadFileTitle ;pointer title of the box mov Flags,00281804h ;the dialog box creation flags mov nFileOffset,0h ;offset filename in string lpstrFile mov nFileExtension,0h ;offset extension in string lpstrFile mov lCustData,0h ;?

Page 9

Page 10: Td Win32asm 220.Asm

td_win32asm_220.asmmov lpfnHook,0h ;? used if flag is OFN_ENABLETEMPLATEmov lpTemplateName,0h ;? used if flag is OFN_ENABLETEMPLATEmov lpstrDefExt,0h ;pointer default extension file, 0=nopush OFFSET lStructSize ;lpofn, pointer OPENFILENAME structurecall GetOpenFileNamePreviewA ;- API Function -cmp eax,0h ;check if an error occursje WP1_return ;exit on errormov mci_filehandle,eax ;handle of new file;------------------------------------------------------------------------------; API "lstrcpyA" copy's a string from source to destination.;------------------------------------------------------------------------------mov ax,nFileOffset ;given from OPENFILENAME structurecwde ;convert word in AX into doubleword EAXmov ebx,lpstrFile ;given from OPENFILENAME structureadd ebx,eax ;calculate OFFSET filenamepush ebx ;lpString2, pointer source stringpush OFFSET TestFileName ;lpString1, pointer destination stringcall lstrcpyA ;- API Function -;------------------------------------------------------------------------------; API "lstrcmpiA" compares two strings, check if loaded file is an AVI file.;------------------------------------------------------------------------------mov ax,nFileExtension ;given from OPENFILENAME structurecwde ;convert word in AX into doubleword EAXmov ebx,lpstrFile ;given from OPENFILENAME structureadd ebx,eax ;calculate OFFSET filename extenderpush ebx ;lpString2, pointer second stringpush OFFSET AVIextender ;lpString1, pointer first stringcall lstrcmpiA ;- API Function -cmp eax,0h ;check if strings are equalje AVI ;if equal go to LABEL

call My_SendMessageA ;- SUBROUTINE -call My_StringRoutine ;- SUBROUTINE -;------------------------------------------------------------------------------; API "MCIWndCreate" registers the MCIWnd window class and creates an MCIWnd; child window for using MCI services.; It can also open an MCI device or file and associate it with the MCI window.; For API MCIWndCreate we push 4 doublewords to the stack, we remove them; after calling !!!;------------------------------------------------------------------------------push OFFSET MediaFileName ;szFile, name MCI device or data filepush 54400008h ;dwStyle, defines the window stylepush hInstance ;hInstance, handle of module instancepush WP1_hWnd ;hwndParent, handle parent window 0=nocall [p_MCIWndCreate] ;- API Function -mov mcihWnd,eax ;handle of MCI windowpop eax ;clear stack !pop eaxpop eaxpop eaxcall My_MoveWindow ;- SUBROUTINE -;------------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of STATIC child window.

Page 10

Page 11: Td Win32asm 220.Asm

td_win32asm_220.asm;------------------------------------------------------------------------------push 01h ;bRepaint, repaint flagpush 16h ;nHeight, heightpush 108h ;nWidth, widthpush 5h ;Y, vertical positionpush 20h ;X, horizontal positionpush STATIC0000_hWnd ;hWnd, handle of windowcall MoveWindow ;- API Function -;------------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of the specified window.;------------------------------------------------------------------------------push 01h ;bRepaint, repaint flagpush 68h ;nHeight, heightpush 136h ;nWidth, widthpush 10h ;Y, vertical positionpush 50h ;X, horizontal positionpush WP1_hWnd ;hWnd, handle of windowcall MoveWindow ;- 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 WP1_hWnd ;hwnd, handle of windowcall UpdateWindow ;- API Function -jmp WP1_return ;

AVI:;------------------------------------------------------------------------------; API "AVIFileInit" initializes the AVIFile library.;------------------------------------------------------------------------------call AVIFileInit ;- API Function -;------------------------------------------------------------------------------; API "AVIFileOpenA" opens an AVI file and returns the address of a; file interface used to access it.;------------------------------------------------------------------------------push 0h ;pclsidHandler, address class ID, 0=syspush 0h ;mode, access mode to use, OF_READ = 0hpush OFFSET TestFileName ;szFile, string - the name of the filepush OFFSET fip ;ppfile, address file interface pointercall AVIFileOpenA ;- API Function -cmp eax,0h ;check if an ERROR occuredje AVI_OK ;no error, go to LABEL ;==============================================================================; API "MessageBoxA" creates a message box, ERROR, AVI file format not supported;------------------------------------------------------------------------------push 0h ;uType, style, 0=MB_OK Buttonpush OFFSET MB1_Titel ;lpCaption,pointer to title textpush OFFSET MB1_AVIFileError ;lpText,pointer to text message boxpush WP1_hWnd ;handle of owner window 0=no ownercall MessageBoxA ;- API Function -;------------------------------------------------------------------------------; API "AVIFileExit" exits the AVIFile library and decrements the; reference count for the library.

Page 11

Page 12: Td Win32asm 220.Asm

td_win32asm_220.asm;------------------------------------------------------------------------------call AVIFileExit ;- API Function -jmp WP1_return ;on error nothing to do, exit

AVI_OK:;------------------------------------------------------------------------------; API "AVIFileInfoA" obtains infos about an AVI file in the AVIFILEINFO struct.;------------------------------------------------------------------------------push 6Ch ;lSize, size in bytes of the structurepush OFFSET dwMaxBytesPerSec ;pfi, address of AVIFILEINFO structurepush fip ;pfile, handle of an open AVI filecall AVIFileInfoA ;- API Function -;------------------------------------------------------------------------------; API "AVIFileRelease" decrements the reference count of an AVI file interface; handle and closes the file if the count reaches zero.;------------------------------------------------------------------------------push fip ;pfile, handle of an open AVI filecall AVIFileRelease ;- API Function -;------------------------------------------------------------------------------; API "AVIFileExit" exits the AVIFile library and decrements the; reference count for the library.;------------------------------------------------------------------------------call AVIFileExit ;- API Function -call My_SendMessageA ;- SUBROUTINE -call My_StringRoutine ;- SUBROUTINE -;------------------------------------------------------------------------------; API "MCIWndCreate" registers the MCIWnd window class and creates an MCIWnd; child window for using MCI services.; It can also open an MCI device or file and associate it with the MCI window.; For API MCIWndCreate we push 4 doublewords to the stack, we remove them; after calling !!!;------------------------------------------------------------------------------push OFFSET MediaFileName ;szFile, name MCI device or data filepush 50000008h ;dwStyle, defines the window stylepush hInstance ;hInstance, handle of module instancepush WP1_hWnd ;hwndParent, handle parent window 0=nocall [p_MCIWndCreate] ;- API Function -mov mcihWnd,eax ;handle of MCI windowpop eax ;clear stack !pop eaxpop eaxpop eax;------------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of STATIC child window.;------------------------------------------------------------------------------push 01h ;bRepaint, repaint flagpush 16h ;nHeight, heightmov eax,dwWidth ;calculate width of STATIC child windowsub eax,1Ahpush eax ;nWidth, widthpush 5h ;Y, vertical positionpush 20h ;X, horizontal positionpush STATIC0000_hWnd ;hWnd, handle of window

Page 12

Page 13: Td Win32asm 220.Asm

td_win32asm_220.asmcall MoveWindow ;- API Function -;------------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of the MCI window.;------------------------------------------------------------------------------push 01h ;bRepaint, repaint flagmov eax,dwHeight ;calculate height of the mci windowadd eax,1Ahpush eax ;nHeight, heightpush dwWidth ;nWidth, widthpush 20h ;Y, vertical positionpush 4h ;X, horizontal positionpush mcihWnd ;hWnd, handle of windowcall MoveWindow ;- API Function -;------------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of the MAIN window.;------------------------------------------------------------------------------push 01h ;bRepaint, repaint flagmov eax,dwHeight ;calculate height of the main windowadd eax,64hpush eax ;nHeight, heightmov eax,dwWidth ;calculate width of the main windowadd eax,12hpush eax ;nWidth, widthpush 10h ;Y, vertical positionpush 50h ;X, horizontal positionpush WP1_hWnd ;hWnd, handle of windowcall MoveWindow ;- 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 WP1_hWnd ;hwnd, handle of windowcall UpdateWindow ;- API Function -jmp 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.;------------------------------------------------------------------------------

Page 13

Page 14: Td Win32asm 220.Asm

td_win32asm_220.asmWP1_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 "DeleteObject" deletes a logical pen, brush, font, bitmap, region, or; palette, freeing all system resources associated with the object.; After the object is deleted, the specified handle is no longer valid.;------------------------------------------------------------------------------push hObject ;hObject, handle of graphic objectcall DeleteObject ;- API Function -ret

My_MessageBoxA:;------------------------------------------------------------------------------; API "MessageBox" creates, displays, and operates a message box.;------------------------------------------------------------------------------push 0h ;uType, style, 0=MB_OK Buttonpush OFFSET MB1_Titel ;lpCaption,pointer to title textpush ebx ;lpText,pointer to text message boxpush hWnd ;handle of owner window 0=no ownercall MessageBoxA ;- API Function -ret

My_MoveWindow:;------------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of the specified window.;------------------------------------------------------------------------------push 01h ;bRepaint, repaint flagpush 20h ;nHeight, heightpush 12Ch ;nWidth, widthpush 20h ;Y, vertical positionpush 0h ;X, horizontal positionpush mcihWnd ;hWnd, handle of windowcall MoveWindow ;- API Function -ret

My_SendMessageA:;------------------------------------------------------------------------------; API "SendMessageA" sends a WM_CLOSE message directly to the open MCI window;------------------------------------------------------------------------------

Page 14

Page 15: Td Win32asm 220.Asm

td_win32asm_220.asmpush 0h ;lParam, second message parameterpush 0h ;wParam, first message parameterpush 10h ;uMsg, message to send ( WM_CLOSE )push mcihWnd ;hwnd, handle of destination windowcall SendMessageA ;- API Function -ret

My_StringRoutine:;------------------------------------------------------------------------------; API "lstrcpyA" copy's a string from source to destination.;------------------------------------------------------------------------------mov ax,nFileOffset ;given from OPENFILENAME structurecwde ;convert word in AX into doubleword EAXmov ebx,lpstrFile ;given from OPENFILENAME structureadd ebx,eax ;calculate OFFSET filenamepush ebx ;lpString2, pointer source stringpush OFFSET MediaFileName ;lpString1, pointer destination stringcall lstrcpyA ;- API Function -;------------------------------------------------------------------------------; API "SendMessageA" sends a WM_SETTEXT message to change the text in STATIC;------------------------------------------------------------------------------push OFFSET MediaFileName ;lParam, pointer to window-text stringpush 0h ;wParam, not used must be 0hpush 0Ch ;uMsg, send WM_SETTEXT messagepush STATIC0000_hWnd ;hwnd, handle of destination windowcall SendMessageA ;- 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_220.asm ;asm command; rc.exe /v rsrc.rc ;rc command; cvtres.exe /machine:ix86 rsrc.res; link.exe /subsystem:windows td_win32asm_220.obj rsrc.obj ;link command;==============================================================================

Page 15