+ All Categories
Home > Documents > Td Win32asm 221.Asm

Td Win32asm 221.Asm

Date post: 05-Jan-2016
Category:
Upload: z4rm4r
View: 231 times
Download: 0 times
Share this document with a friend
Description:
Skola asemblera TD zakon
22
td_win32asm_221.asm ;============================================================================== ; Test Department's WINDOWS 32 BIT x86 ASSEMBLY EXAMPLE's 221 ;============================================================================== ;============================================================================== ; ==> Part 221 : Multimedia Player ;------------------------------------------------------------------------------ ; Welcome, ; first of all you must imagine that we do not decode datas here, that is not ; our job, our job is to program a multimedia player. ; All this slave decoding job is done by windows or any other better OS. ; The WinXP codec's must be installed to view videos. ; ; This program may not work proper under WinXP. ; ; Supported : CDAUDIO, aif, au, avi, mid, mov, mpg, rmi, wav and more... ;============================================================================== ; 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 comctl32.lib includelib winmm.lib includelib vfw32.lib ;============================================================================== ; Declaration of used API functions,take a look into WIN32.HLP and *.inc files ;------------------------------------------------------------------------------ GetModuleHandleA PROTO :DWORD InitCommonControls PROTO 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 Page 1
Transcript
Page 1: Td Win32asm 221.Asm

td_win32asm_221.asm;==============================================================================; Test Department's WINDOWS 32 BIT x86 ASSEMBLY EXAMPLE's 221;==============================================================================

;==============================================================================; ==> Part 221 : Multimedia Player;------------------------------------------------------------------------------; Welcome,; first of all you must imagine that we do not decode datas here, that is not; our job, our job is to program a multimedia player.; All this slave decoding job is done by windows or any other better OS.; The WinXP codec's must be installed to view videos.;; This program may not work proper under WinXP.;; Supported : CDAUDIO, aif, au, avi, mid, mov, mpg, rmi, wav and more...

;==============================================================================; 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 comctl32.libincludelib winmm.libincludelib vfw32.lib

;==============================================================================; Declaration of used API functions,take a look into WIN32.HLP and *.inc files;------------------------------------------------------------------------------GetModuleHandleA PROTO :DWORDInitCommonControls PROTOLoadLibraryA 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,:DWORD

Page 1

Page 2: Td Win32asm 221.Asm

td_win32asm_221.asmFreeLibrary PROTO :DWORDExitProcess PROTO :DWORDMessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORDDestroyWindow PROTO :DWORDCreateToolbarEx PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD, :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORDMoveWindow PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORDGetWindowTextA PROTO :DWORD,:DWORD,:DWORDSetWindowTextA PROTO :DWORD,:DWORDSetTimer PROTO :DWORD,:DWORD,:DWORD,:DWORDKillTimer PROTO :DWORD,:DWORDSendMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORDlstrcpyA PROTO :DWORD,:DWORDlstrcmpiA PROTO :DWORD,:DWORDGetOpenFileNamePreviewA PROTO :DWORDAVIFileInit PROTOAVIFileOpenA PROTO :DWORD,:DWORD,:DWORD,:DWORDAVIFileInfoA PROTO :DWORD,:DWORD,:DWORDAVIFileRelease PROTO :DWORDAVIFileExit PROTOmciSendCommandA PROTO :DWORD,:DWORD,:DWORD,:DWORD

;==============================================================================; .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's Multimedia Player",0;window nameMB2_Text db "Supported Formats : CDAUDIO, aif, au, avi, mid, mov, mpg, rmi, wav and more.",0;MB1_DllError db "can not load DLL: msvfw32.dll",0;message box textMB1_FunctionError db "can not find Function: MCIWndCreate",0;MB1_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 inside librarytoolbar00_str_C0 db "Play Media File",0 ;toolbar button texttoolbar00_str_C1 db "Play Audio CD",0 ;toolbar button texttoolbar00_str_C10 db "Supported Formats",0; toolbar button textLoadFileFilte db "Media Files (*.*)",0,"*.*",0,0;LoadFileTitle db "Select a File",0 ;AVIextender db "avi",0 ;AVI file extender

Page 2

Page 3: Td Win32asm 221.Asm

td_win32asm_221.asmCDAextender db "cda",0 ;CDA file extenderCDAdevice db "cdaudio",0 ;name of deviceMOVdevice db "MPEGVideo",0 ;name of device

align 4; - TBBUTTON structure ( API=CreateToolbarEx ) - ARRAY !!!iBitmap_00 dd 0h ;zero-based index of button imageidCommand_00 dd 0h ;ID or, if fsStyle=TBSTYLE_SEP, zerofsState_00 db 4h ;state flags,4h=TBSTATE_ENABLEDfsStyle_00 db 1h ;button style,1h=TBSTYLE_SEPbReserved_00 db 2h dup (0) ;reserved byte,error in WIN32.HLP ?dwData_00 dd 0h ;application-defined valueiString_00 dd 0h ;zero-based index of button string

iBitmap_01 dd 1h ;zero-based index of button imageidCommand_01 dd 0C0h ;ID of button, WM_COMMAND uMsg/wParamfsState_01 db 4h ;state flags,4h=TBSTATE_ENABLEDfsStyle_01 db 0h ;button style,0h=TBSTYLE_BUTTONbReserved_01 db 2h dup (0) ;reserved byte,error in WIN32.HLP ?dwData_01 dd 0h ;application-defined valueiString_01 dd 0h ;zero-based index of button string

iBitmap_02 dd 2h ;zero-based index of button imageidCommand_02 dd 0C1h ;ID of button, WM_COMMAND uMsg/wParamfsState_02 db 4h ;state flags,4h=TBSTATE_ENABLEDfsStyle_02 db 0h ;button style,0h=TBSTYLE_BUTTONbReserved_02 db 2h dup (0) ;reserved byte,error in WIN32.HLP ?dwData_02 dd 0h ;application-defined valueiString_02 dd 0h ;zero-based index of button string

iBitmap_03 dd 3h ;zero-based index of button imageidCommand_03 dd 0h ;ID or, if fsStyle=TBSTYLE_SEP, zerofsState_03 db 4h ;state flags,4h=TBSTATE_ENABLEDfsStyle_03 db 1h ;button style,1h=TBSTYLE_SEPbReserved_03 db 2h dup (0) ;reserved byte,error in WIN32.HLP ?dwData_03 dd 0h ;application-defined valueiString_03 dd 0h ;zero-based index of button string

iBitmap_04 dd 4h ;zero-based index of button imageidCommand_04 dd 0C10h ;ID of button, WM_COMMAND uMsg/wParamfsState_04 db 4h ;state flags,4h=TBSTATE_ENABLEDfsStyle_04 db 0h ;button style,0h=TBSTYLE_BUTTONbReserved_04 db 2h dup (0) ;reserved byte,error in WIN32.HLP ?dwData_04 dd 0h ;application-defined valueiString_04 dd 0h ;zero-based index of button string

iBitmap_05 dd 5h ;zero-based index of button imageidCommand_05 dd 0h ;ID or, if fsStyle=TBSTYLE_SEP, zerofsState_05 db 4h ;state flags,4h=TBSTATE_ENABLEDfsStyle_05 db 1h ;button style,1h=TBSTYLE_SEPbReserved_05 db 2h dup (0) ;reserved byte,error in WIN32.HLP ?dwData_05 dd 0h ;application-defined valueiString_05 dd 0h ;zero-based index of button string

Page 3

Page 4: Td Win32asm 221.Asm

td_win32asm_221.asm

;==============================================================================; .Data? = the data? area starts here, not defined and not fixed;------------------------------------------------------------------------------.data?toolbar00_hWnd dd ? ;handle of the toolbarhLibrary dd ? ;loaded library handlep_MCIWndCreate dd ? ;pointer function inside DLLmcihWnd dd ? ;handle of mci windowmci_filehandle dd ? ;filehandle media filefip dd ? ;AVI file interface pointerErrorFlag dd ?temp_00 dd ?TrackNumber dd ?LoadFileBuffer 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 of the 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=no

Page 4

Page 5: Td Win32asm 221.Asm

td_win32asm_221.asmnMaxFile 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=defaultlpstrTitle 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

align 4; - MCI_GENERIC_PARMS Structure ( API=mciSendCommand ) -generic_dwCallback dd ?

align 4; - MCI_OPEN_PARMS Structure ( API=mciSendCommand ) -open_dwCallback dd ?open_wDeviceID dd ?open_lpstrDeviceType dd ?open_lpstrElementName dd ?open_lpstrAlias dd ?open_dwStyle dd ?open_hWndParent dd ?

align 4; - MCI_SET_PARMS Structure ( API=mciSendCommand ) -set_dwCallback dd ?set_dwTimeFormat dd ?set_dwAudio dd ?

align 4; - MCI_STATUS_PARMS Structure ( API=mciSendCommand ) -status_dwCallback dd ?status_dwReturn dd ?status_dwItem dd ?

Page 5

Page 6: Td Win32asm 221.Asm

td_win32asm_221.asmstatus_dwTrack dd ?

align 4; - MCI_DGV_RECT_PARMS Structure ( API=mciSendCommand ) -dgv_generic_dwCallback dd ?dgv_left dd ?dgv_top dd ?dgv_right dd ?dgv_bottom dd ?

;==============================================================================; .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 "CreateToolbarEx" is part of common controls, force init ...;------------------------------------------------------------------------------call InitCommonControls ;- API Function -

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

Page 6

Page 7: Td Win32asm 221.Asm

td_win32asm_221.asm

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;OFFSET MenuName ;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).;------------------------------------------------------------------------------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 0000006Ah ;intnHeight, window height pixelpush 0000013Eh ;intnWidth, window width pixelpush 00000008h ;inty, vertical position windowpush 00000030h ;intx, horizontal position windowpush 04CA0000h ;dwStyle, look into WIN32.HLP

Page 7

Page 8: Td Win32asm 221.Asm

td_win32asm_221.asmpush 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

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

;==============================================================================

Page 8

Page 9: Td Win32asm 221.Asm

td_win32asm_221.asm; 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 LABELcall My_MCIWndCreate ;- SUBROUTINE -call My_MoveWindow_MCI ;- SUBROUTINE -;------------------------------------------------------------------------------; API "CreateToolbarExA" creates a child window ( TOOLBAR ).; Set "uStructSize" to 14h, not 12h because bReserved bytes, bug in WIN32.HLP ?; Take a look to TBBUTTON structure in the .DATA area above. ; Parameter "ws" defines the child windows style; it also enables tooltiptext.; In "wID" we PUSH the ID of the child window ( a value of your your choice ).; Take a look into WIN32.HLP ( CreateToolbarEx ) and Windows.inc.; The return value in EAX is the handle of the created toolbar.;------------------------------------------------------------------------------push 14h ;uStructSize,size TBBUTTON structurepush 14h ;dyBitmap,height pixels of the imagespush 14h ;dxBitmap,width pixels of the imagespush 14h ;dyButton,height pixels of the buttonspush 14h ;dxButton,width pixels of the buttonspush 06h ;iNumButtons,Number buttons in toolbarpush OFFSET iBitmap_00 ;lpButtons,pointer TBBUTTON structurepush 80h ;wBMID,ID for the bitmap resourcepush hInstance ;hBMInst,instance bitmap resourcepush 1h ;nBitmaps,number of button image filepush 500h ;wID,control identifier for toolbarpush 50400900h ;ws,windows styles in WIN32.HLPpush WP1_hWnd ;hwnd,handle owner window 0=no ownercall CreateToolbarEx ;- API Function -mov toolbar00_hWnd,eax ;handle of toolbar child window;==============================================================================; API "ShowWindow" function sets the specified window's show state. ;------------------------------------------------------------------------------push 5h ;nCmdShow, show state 5h=SW_SHOWpush toolbar00_hWnd ;hwnd, handle of windowcall ShowWindow ;- API Function -

Page 9

Page 10: Td Win32asm 221.Asm

td_win32asm_221.asmjmp WP1_return

;==============================================================================; WM_DESTROY (value=02h) message received ?;------------------------------------------------------------------------------WP1_uMsg_02h:cmp eax,2h ;check if value=2h (WM_DESTROY)jne WP1_uMsg_05h ;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_Size (value=05h) message, used to resize the window area;------------------------------------------------------------------------------WP1_uMsg_05h:cmp eax,05h ;check if WM_SIZE message recievedjne WP1_uMsg_4Eh ;if not goto label;------------------------------------------------------------------------------; API "SendMessageA" sends a message, TB_AUTOSIZE to fit toolbar and bitmaps;------------------------------------------------------------------------------push 0h ;lParam, second message parameterpush 0h ;wParam, first message parameter (ID)push 421h ;uMsg, send TB_AUTOSIZE messagepush toolbar00_hWnd ;hwnd, handle of destination windowcall SendMessageA ;- API Function -jmp WP1_return

;==============================================================================; WM_NOTIFY (value=4Eh) message, here used to show the toolbar tip !; With a WM_NOTIFY message Windows gives you pointer to a NMHDR structure.;------------------------------------------------------------------------------WP1_uMsg_4Eh:cmp eax,4Eh ;check if WM_NOTIFY message recievedjne WP1_uMsg_111h ;if not goto label;------------------------------------------------------------------------------; The NMHDR structure contains information about a notification message.; The TOOLTIPTEXT structure identifies a tool for which text is to be displayed; and receives the text for the tool.; We must fill it with the CORRECT values ...; The POINTER to this structure is specified as lParam member of WM_NOTIFY.; This POINTER is given to us with the WM_NOTIFY message by Windows.;------------------------------------------------------------------------------; - NMHDR structure -; hwndFrom = [WP1_lParam+0] ;handle to control sending message

Page 10

Page 11: Td Win32asm 221.Asm

td_win32asm_221.asm; idFrom = [WP1_lParam+4] ;identifier of control sending message; code = [WP1_lParam+8] ;notification code; - TOOLTIPTEXT structure -; hdr = placeholder for NMHDR ;required for all WM_NOTIFY messages; lpszText = [WP1_lParam+12] ;Pointer string or resource ID; szText[80]= [WP1_lParam+16] ;buffer for text, alternate to lpszText; hinst = [WP1_lParam+20] ;handle instance, 0 if lpszText=pointer; uFlags = [WP1_lParam+24] ;Flag indicates how to interpret idFrom;------------------------------------------------------------------------------mov ebx,WP1_lParam ;pointer to struc, given by windows !mov eax,[ebx+8] ;move code ( NMHDR structure ) into EAXcmp eax,0FFFFFDF8h ;check if code TTN_NEEDTEXT receivedjne WP1_return ;if not goto labelmov eax,[ebx+4] ;move idFrom ( NMHDR structure ) to EAXcmp eax,0C0h ;is it toolbar button ID=0C0hjne next_01 ;if not goto labelmov [ebx+12],OFFSET toolbar00_str_C0;move our text pointer to lpszTextnext_01:cmp eax,0C1h ;is it toolbar button ID=0C1hjne next_02 ;if not goto labelmov [ebx+12],OFFSET toolbar00_str_C1;move our text pointer to lpszTextnext_02:cmp eax,0C10h ;is it toolbar button ID=0C10hjne next_03 ;if not goto labelmov [ebx+12],OFFSET toolbar00_str_C10;move our text pointer to lpszTextnext_03:jmp WP1_return

;==============================================================================; 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,0C0h ;check if toolbar button ID=C0h clickedjne WP1_lParam_0_0C1h ;if not 0C0h 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 above

Page 11

Page 12: Td Win32asm 221.Asm

td_win32asm_221.asmmov 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 ;? mov 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 for Audio CD.;------------------------------------------------------------------------------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 extendermov temp_00,ebx ;store pointer for future usepush ebx ;lpString2, pointer second stringpush OFFSET CDAextender ;lpString1, pointer first stringcall lstrcmpiA ;- API Function -cmp eax,0h ;check if strings are equaljne _CHECK_AVI ;if equal go to LABEL;------------------------------------------------------------------------------; calculate choosen Audio CD Track;------------------------------------------------------------------------------mov eax,0hmov TrackNumber,0hmov ebx,temp_00dec ebxdec ebxmov al,[ebx]cmp al,2Fhjbe _AUDIO_CD_TRACK1cmp al,3Ahjae _AUDIO_CD_TRACK1sub al,30h

Page 12

Page 13: Td Win32asm 221.Asm

td_win32asm_221.asmadd TrackNumber,eaxmov eax,0hdec ebxmov al,[ebx]cmp al,2Fhjbe _AUDIO_CD_TRACK1cmp al,3Ahjae _AUDIO_CD_TRACK1sub al,30hmov bl,0Ahmul blcwdeadd TrackNumber,eaxjmp _AUDIO_CD

_CHECK_AVI:;------------------------------------------------------------------------------; API "lstrcmpiA" compares two strings, check if 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

_MPG:call My_MCI_Stop ;- SUBROUTINE -call My_KillTimer ;- SUBROUTINE -call My_SendMessageA ;- SUBROUTINE -call My_StringRoutine ;- SUBROUTINE -;------------------------------------------------------------------------------; API "mciSendCommandA" here opens the device with a specified filename;------------------------------------------------------------------------------mov eax,OFFSET MOVdevice ;fill MCI_OPEN_PARMS structuremov open_lpstrDeviceType,eax ;device type = MPEGVideomov eax,OFFSET MediaFileName ;mov open_lpstrElementName,eax ;name of file to openpush OFFSET open_dwCallback ;dwParam, address MCI_OPEN_PARMS struc.push 2300h ;fdwCommand, ;MCI_OPEN_TYPE = 2000h ;MCI_OPEN_ELEMENT = 200h ;MCI_OPEN_SHAREABLE = 100hpush 0803h ;uMsg, command message, MCI_OPENpush 0h ;IDDevice, not used with MCI_OPENcall mciSendCommandA ;- API Function -cmp eax,0hjne _AUDIO_FILE;------------------------------------------------------------------------------; API "mciSendCommandA" obtains the clipping rectangle for the video device

Page 13

Page 14: Td Win32asm 221.Asm

td_win32asm_221.asm;------------------------------------------------------------------------------push OFFSET dgv_generic_dwCallback ;dwParam, MCI_DGV_RECT_PARMS structurepush 40000h ;fdwCommand, ;MCI_DGV_WHERE_DESTINATION = 40000hpush 0843h ;uMsg, command message, MCI_WHEREpush open_wDeviceID ;IDDevice, given from MCI_OPENcall mciSendCommandA ;- API Function -mov ErrorFlag,eax ;store return value in variable;------------------------------------------------------------------------------; API "mciSendCommandA" here releases access to a device or file.;------------------------------------------------------------------------------push OFFSET generic_dwCallback ;dwParam, MCI_GENERIC_PARMS structurepush 0h ;fdwCommand, 0h=no commandpush 0804h ;uMsg, command message, MCI_CLOSEpush open_wDeviceID ;IDDevice, given from MCI_OPENcall mciSendCommandA ;- API Function -cmp ErrorFlag,0h ;check ErrorFlag 0h = no errorjne _AUDIO_FILE ;call My_MCIWndCreate ;- SUBROUTINE -;------------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of the MCI window.;------------------------------------------------------------------------------push 01h ;bRepaint, repaint flagadd dgv_bottom,20h ;calculate height of the mci windowpush dgv_bottom ;nHeight, heightadd dgv_right,6h ;calculate width of the mci windowpush dgv_right ;nWidth, widthpush 24h ;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 flagadd dgv_bottom,4Ah ;calculate height of the main windowpush dgv_bottom ;nHeight, heightadd dgv_right,12h ;calculate width of the main windowpush dgv_right ;nWidth, widthpush 08h ;Y, vertical positionpush 30h ;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 -call My_MCI_Play ;- SUBROUTINE -call My_SetTimer ;- SUBROUTINE -jmp WP1_return

Page 14

Page 15: Td Win32asm 221.Asm

td_win32asm_221.asm_AUDIO_FILE:call My_MCI_Stop ;- SUBROUTINE -call My_KillTimer ;- SUBROUTINE -call My_SendMessageA ;- SUBROUTINE -call My_StringRoutine ;- SUBROUTINE -call My_MCIWndCreate ;- SUBROUTINE -call My_MoveWindow_MCI ;- SUBROUTINE -call My_MoveWindow_MAIN ;- SUBROUTINE -;------------------------------------------------------------------------------; 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 -call My_MCI_Play ;- SUBROUTINE -call My_SetTimer ;- SUBROUTINE -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 WindowName ;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.;------------------------------------------------------------------------------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.;------------------------------------------------------------------------------

Page 15

Page 16: Td Win32asm 221.Asm

td_win32asm_221.asmpush 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 -cmp dwHeight,1h ;check if AVI file have a video streamjbe _AUDIO_FILE ;if not goto LABELcall My_MCI_Stop ;- SUBROUTINE -call My_KillTimer ;- SUBROUTINE -call My_SendMessageA ;- SUBROUTINE -call My_StringRoutine ;- SUBROUTINE -call My_MCIWndCreate ;- SUBROUTINE -;------------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of the MCI window.;------------------------------------------------------------------------------push 01h ;bRepaint, repaint flagadd dwHeight,20h ;calculate height of the mci windowpush dwHeight ;nHeight, heightadd dwWidth,6h ;calculate width of the mci windowpush dwWidth ;nWidth, widthpush 24h ;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 flagadd dwHeight,4Ah ;calculate height of the main windowpush dwHeight ;nHeight, heightadd dwWidth,12h ;calculate width of the main windowpush dwWidth ;nWidth, widthpush 08h ;Y, vertical positionpush 30h ;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 -call My_MCI_Play ;- SUBROUTINE -

Page 16

Page 17: Td Win32asm 221.Asm

td_win32asm_221.asmcall My_SetTimer ;- SUBROUTINE -jmp WP1_return

WP1_lParam_0_0C1h:cmp ax,0C1h ;check if button ID=0C1h clickedjne WP1_lParam_0_C10h ;if not 0C1h goto LABEL_AUDIO_CD_TRACK1:mov TrackNumber,1h ;;------------------------------------------------------------------------------; API "mciSendCommandA" here opens the device.;------------------------------------------------------------------------------mov open_lpstrDeviceType,516 ;fill MCI_OPEN_PARMS structure ;MCI_DEVTYPE_CD_AUDIO = 516push OFFSET open_dwCallback ;dwParam, address MCI_OPEN_PARMS struc.push 3100h ;fdwCommand, ;MCI_OPEN_TYPE = 2000h ;MCI_OPEN_TYPE_ID = 1000h ;MCI_OPEN_SHAREABLE = 100hpush 0803h ;uMsg, command message, MCI_OPENpush 0h ;IDDevice, not used with MCI_OPENcall mciSendCommandA ;- API Function -;------------------------------------------------------------------------------; API "mciSendCommandA" here retrieves information if a media is present.;------------------------------------------------------------------------------mov status_dwItem,05h ;structure, MCI_STATUS_MEDIA_PRESENTpush OFFSET status_dwCallback ;dwParam, MCI_STATUS_PARMS structurepush 0100h ;fdwCommand, MCI_STATUS_ITEM = 0100hpush 0814h ;uMsg, command message, MCI_STATUSpush open_wDeviceID ;IDDevice, given from MCI_OPENcall mciSendCommandA ;- API Function -;------------------------------------------------------------------------------; API "mciSendCommandA" here closes the device.;------------------------------------------------------------------------------push OFFSET generic_dwCallback ;dwParam, MCI_GENERIC_PARMS structurepush 0h ;fdwCommand, 0h=no commandpush 0804h ;uMsg, command message, MCI_CLOSEpush open_wDeviceID ;IDDevice, given from MCI_OPENcall mciSendCommandA ;- API Function -

cmp status_dwReturn,1h ;value from MCI_STATUS_PARMS structureje _AUDIO_CD ;media is present so play itjmp WP1_return

_AUDIO_CD:call My_MCI_Stop ;- SUBROUTINE -call My_KillTimer ;- SUBROUTINE -call My_SendMessageA ;- 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.;------------------------------------------------------------------------------push OFFSET CDAdevice ;szFile, name MCI device or data file

Page 17

Page 18: Td Win32asm 221.Asm

td_win32asm_221.asmpush 54400078h ;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_MCI ;- SUBROUTINE -call My_MoveWindow_MAIN ;- SUBROUTINE -;------------------------------------------------------------------------------; 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 -;------------------------------------------------------------------------------; API "mciSendCommandA" here sets the time format and audio format ( TMSF );------------------------------------------------------------------------------mov set_dwTimeFormat,0Ah ;fill MCI_SET_PARMS structure ;MCI_FORMAT_TMSF = 0Ahmov set_dwAudio,6401h ;fill MCI_SET_PARMS structure ;MCI_SET_AUDIO_ALL = 4001h ;MCI_SET_ON = 2000h ;MCI_SET_TIME_FORMAT= 400hpush OFFSET set_dwCallback ;dwParam, address MCI_SET_PARMS struc.push 6401h ;fdwCommand, same as above push 080Dh ;uMsg, command message, MCI_SETpush -1 ;IDDevice, MCI_ALL_DEVICE_ID = -1call mciSendCommandA ;- API Function -;------------------------------------------------------------------------------; API "SendMessageA" sends a MCI_SEEK message, seek to track number;------------------------------------------------------------------------------push TrackNumber ;lParam, seek to trackpush 0h ;wParam, not usedpush 807h ;uMsg, send MCI_SEEK messagepush mcihWnd ;hwnd, handle of destination windowcall SendMessageA ;- API Function -call My_MCI_Play ;- SUBROUTINE -call My_SetTimer ;- SUBROUTINE -jmp WP1_return

WP1_lParam_0_C10h:cmp ax,0C10h ;check if toolbarbutton ID=C10h clickedjne WP1_return ;if not 0C10h goto LABEL;==============================================================================; API "MessageBoxA" creates a message box, displaying the supported formats;------------------------------------------------------------------------------push 0h ;uType, style, 0=MB_OK Buttonpush OFFSET WindowName ;lpCaption,pointer to title textpush OFFSET MB2_Text ;lpText,pointer to text message boxpush WP1_hWnd ;handle of owner window 0=no owner

Page 18

Page 19: Td Win32asm 221.Asm

td_win32asm_221.asmcall MessageBoxA ;- API Function -jmp WP1_return ;

;==============================================================================; WM_SYSCOMMAND (value=112h) message recieved ?;------------------------------------------------------------------------------WP1_uMsg_112h:cmp eax,112h ;check if WM_COMMAND message recievedjne WP1_wParam_113h ;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

;==============================================================================; WM_TIMER (value=113h) message received ?;------------------------------------------------------------------------------WP1_wParam_113h:cmp eax,113h ;check if WM_TIMER message recievedjne WP1_return ;if not goto label;------------------------------------------------------------------------------; API "GetWindowTextA" copies the text of the specified window's title bar.;------------------------------------------------------------------------------push 30h ;nMaxCount, max number of chars to copypush OFFSET TestFileName ;lpString, address of buffer for textpush mcihWnd ;hWnd, handle of window or controlcall GetWindowTextA ;- API Function -;------------------------------------------------------------------------------; API "SetWindowTextA" set's the text of the specified window's title bar.;------------------------------------------------------------------------------push OFFSET TestFileName ;lpsz, address of stringpush WP1_hWnd ;hwnd, handle of window or controlcall SetWindowTextA ;- API Function -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;##############################################################################

Page 19

Page 20: Td Win32asm 221.Asm

td_win32asm_221.asm

;******************************************************************************; My own subroutine(s) for a compacter code resist here ...;------------------------------------------------------------------------------My_CleanSystem:call My_MCI_Stop ;- SUBROUTINE -ret

My_MCIWndCreate:;------------------------------------------------------------------------------; 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 54400078h ;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 eaxret

My_MCI_Play:;------------------------------------------------------------------------------; API "SendMessageA" sends a MCI_PLAY message to autoplay file;------------------------------------------------------------------------------push 0h ;lParam, not usedpush 0h ;wParam, not usedpush 806h ;uMsg, send MCI_PLAY messagepush mcihWnd ;hwnd, handle of destination windowcall SendMessageA ;- API Function -ret

My_MCI_Stop:;------------------------------------------------------------------------------; API "mciSendCommandA" here stops playing cdaudio (!); If we do not call this function CDAUDIO plays always if you close this prg.;------------------------------------------------------------------------------push OFFSET generic_dwCallback ;dwParam, MCI_GENERIC_PARMS structurepush 0h ;fdwCommand, 0h=no commandpush 0808h ;uMsg, command message, MCI_STOPpush -1 ;IDDevice, -1 = close all devicescall mciSendCommandA ;- API Function -ret

My_MessageBoxA:push 0h ;uType, style, 0=MB_OK Button

Page 20

Page 21: Td Win32asm 221.Asm

td_win32asm_221.asmpush OFFSET WindowName ;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_MCI:;------------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of the specified window.;------------------------------------------------------------------------------push 01h ;bRepaint, repaint flagpush 20h ;nHeight, heightpush 12Ch ;nWidth, widthpush 24h ;Y, vertical positionpush 4h ;X, horizontal positionpush mcihWnd ;hWnd, handle of windowcall MoveWindow ;- API Function -ret

My_MoveWindow_MAIN:;------------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of the specified window.;------------------------------------------------------------------------------push 01h ;bRepaint, repaint flagpush 6Ah ;nHeight, heightpush 13Eh ;nWidth, widthpush 08h ;Y, vertical positionpush 30h ;X, horizontal positionpush WP1_hWnd ;hWnd, handle of windowcall MoveWindow ;- API Function -ret

My_SendMessageA:;------------------------------------------------------------------------------; API "SendMessageA" sends a WM_CLOSE message directly to the open MCI window;------------------------------------------------------------------------------push 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 string

Page 21

Page 22: Td Win32asm 221.Asm

td_win32asm_221.asmcall lstrcpyA ;- API Function -ret

My_SetTimer:;------------------------------------------------------------------------------; API "SetTimer" creates a timer with the specified time-out value.;------------------------------------------------------------------------------push 0h ;tmprc, address timer procedure,0=thispush 1000 ;uTimeout, time-out value millisecondspush 10h ;idTimer, timer identifier, nonzeropush WP1_hWnd ;hwnd, handle of window for timer msg.call SetTimer ;- API Function -ret

My_KillTimer:;------------------------------------------------------------------------------; API "KillTimer" destroys the specified timer.;------------------------------------------------------------------------------push 10h ;uIDEvent, timer identifierpush WP1_hWnd ;hWnd, handle of window installed timercall KillTimer ;- API Function -;------------------------------------------------------------------------------; API "SetWindowTextA" set's the text of the specified window's title bar.;------------------------------------------------------------------------------push OFFSET WindowName ;lpsz, address of stringpush WP1_hWnd ;hwnd, handle of window or controlcall SetWindowTextA ;- 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_221.asm ;asm command; rc.exe /v rsrc.rc ;rc command; cvtres.exe /machine:ix86 rsrc.res; link.exe /subsystem:windows td_win32asm_221.obj rsrc.obj ;link command;==============================================================================

Page 22


Recommended