Vous êtes sur la page 1sur 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

MessageBoxA
DestroyWindow
MoveWindow
SendMessageA
LoadBitmapA
lstrcpyA
lstrcmpiA
DeleteObject
GetOpenFileNamePreviewA
AVIFileInit
AVIFileOpenA
AVIFileInfoA
AVIFileRelease
AVIFileExit

PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO

td_win32asm_220.asm
:DWORD,:DWORD,:DWORD,:DWORD
:DWORD
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
:DWORD,:DWORD,:DWORD,:DWORD
:DWORD,:DWORD
:DWORD,:DWORD
:DWORD,:DWORD
:DWORD
:DWORD
:DWORD,:DWORD,:DWORD,:DWORD
: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 address
WP1_hWnd
equ [ebp+8]
;handle of window who receives message
WP1_uMsg
equ [ebp+12]
;the message number
WP1_wParam
equ [ebp+16]
;extra info about the message
WP1_lParam
equ [ebp+20]
;extra info about the message
;==============================================================================
; .Data = the data area starts here, datas are defined but not fixed
;-----------------------------------------------------------------------------.Data
IconName
db "TDIcon",0
;icon name in rc file
MenuName
db "TDMenu",0
;menu name in rc file
ClassName
db "TDWinClass",0
;name of windows class
WindowName
db "Test Department",0
;window name titel bar
MB1_Titel
db "Message Box",0
;message box name
MB1_DllError
db "can not load DLL: msvfw32.dll",0;message box text
MB1_FunctionError
db "can not find Function: MCIWndCreate",0;msgbox text
MB1_AVIFileError
db "AVI file corrupted or Format not supported",0;
Library_Name
db "msvfw32.dll",0
;filename of the library
f_MCIWndCreate
db "MCIWndCreate",0
;function name in library
STATICClassName
db "STATIC",0
;predefined window class
BUTTONClassName
db "BUTTON",0
;predefined window class
STATIC0000_WindowName
db "Midi, Wave and Avi Player, enjoy ...",0;
BUTTON0500_WindowName
db "Bitmap",0
;default window name
STATIC0000_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

td_win32asm_220.asm
.data?
STATIC0000_hWnd
BUTTON0500_hWnd
hLibrary
p_MCIWndCreate
mcihWnd
hObject
mci_filehandle
fip
tempCallBack
LoadFileBuffer
TestFileName
MediaFileName

dd
dd
dd
dd
dd
dd
dd
dd
dd
db
db
db

?
?
?
?
?
?
?
?
?
104h dup(?)
104h dup(?)
104h dup(?)

;handle of STATIC window


;handle of BUTTON window
;loaded library handle
;pointer function inside DLL
;handle of mci window
;handle of bitmap
;
;
;temporary variable
;buffer for load filename
;buffer, filename
;buffer, filename

align 4
; - WndClassEx Structure ( API=RegisterClassExA ) cbSize
dd ?
;size in bytes of this structure
style
dd ?
;window style
lpfnWndProc
dd ?
;address of user proc function
cbclsExtra
dd ?
;extra bytes to allocate set to 0
cbWndExtra
dd ?
;extra bytes class directive, rc file
hInstance
dd ?
;program handle(API=GetModuleHandleA)
hIcon
dd ?
;handle of icon (API=LoadIconA)
hcursor
dd ?
;handle of cursor (API=LoadCursor)
hbrBackground
dd ?
;background color, 0=transparent
lpszMenuName
dd ?
;name of menu class in resource file
lpszClassName
dd ?
;name of windows this window class
hIconSm
dd ?
;iconhandle 0=search in resource file
align 4
; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structure
hWnd
dd ?
;handle of window who receives message
message
dd ?
;the message number
wParam
dd ?
;extra info about the message
lParam
dd ?
;extra info about the message
time
dd ?
;time the message was posted
xpt
dd ?
;cursor x-position, POINT struc
ypt
dd ?
;cursor x-position, POINT struc
align 4
; - OPENFILENAME Structure
lStructSize
dd
hWndOwner
dd
hInstance1
dd
lpstrFilter
dd
lpstrCustomFilter
dd
nMaxCustFilter
dd
nFilterIndex
dd
lpstrFile
dd
nMaxFile
dd
lpstrFileTitle
dd
nMaxFileTitle
dd
lpstrInitialDir
dd

( API=GetOpenFileNamePreviewA ) ?
;the length in bytes of structure
?
;handle window that owns dialog box
?
;handle, our program handle
?
;pointer to string + filter
?
;pointer to user defined filter
?
;size bytes/characters of above
?
;filter index of lpstrFilter
?
;pointer initialize filename, 0=no
?
;size bytes/characters of above
?
;pointer title of the selected file
?
;size of the lpstrFileTitle buffer
?
;pointer init file dir,0=default
Page 3

lpstrTitle
Flags
nFileOffset
nFileExtension
lpstrDefExt
lCustData
lpfnHook
lpTemplateName

dd
dd
dw
dw
dd
dd
dd
dd

?
?
?
?
?
?
?
?

td_win32asm_220.asm
;pointer title of the box
;the dialog box creation flags
;offset filename in string lpstrFile
;offset extension in string lpstrFile
;pointer to default extension of file
;?
;used if flag is OFN_ENABLETEMPLATE
;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 file
dwEditCount
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
;-----------------------------------------------------------------------------.Code
Main:
;==============================================================================
; Always get your program ID first (API=GetModuleHandleA)
;-----------------------------------------------------------------------------push
0h
;lpModuleHandle, 0=get program handle
call
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 module
call
LoadLibraryA
;- API Function cmp
eax,0h
;check if return value 0h=ERROR !
jne
Library_OK
;if no ERROR goto LABEL
mov
ebx,OFFSET MB1_DllError
;lpText,pointer to text message box
call
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

td_win32asm_220.asm
;-----------------------------------------------------------------------------push
OFFSET f_MCIWndCreate
;pProcName, name of function
push
hLibrary
;hModule, handle to DLL module
call
GetProcAddress
;- API Function cmp
eax,0h
;check if return value 0h=ERROR !
jne
Function_OK
;if no ERROR goto LABEL
mov
ebx,OFFSET MB1_FunctionError
;lpText,pointer to text message box
call
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 structure
mov
style,3h
;window style
mov
lpfnWndProc,OFFSET WP1
;address of user lpfnWndProc function
mov
cbclsExtra,0h
;extra bytes to allocate set to 0
mov
cbWndExtra,0h
;class directive in rc file
mov
hbrBackground,10h
;background,1=background(parameter+1)
mov
lpszMenuName,0h
;menu name in resource file,0=no menu
mov
lpszClassName,OFFSET ClassName ;name of windows class
mov
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 id
push
hInstance
;our program handle
call
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 dezimal
push
0h
;hInstance, 0=default system cursor
call
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 structure
call
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

push
push
push
push
push
push
push
push
push
push
push
push
call
mov

0h
hInstance
0h
0h
00000068h
00000136h
00000010h
00000050h
04CA0000h
OFFSET WindowName
OFFSET ClassName
0300h
CreateWindowExA
hWnd,eax

td_win32asm_220.asm
;lpParam, extra pointer data 0=no data
;hInstance, handle of our program
;hMenu, handle window menu 0=class menu
;hWndParent, handle parent window 0=no
;intnHeight, window height pixel
;intnWidth, window width pixel
;inty, vertical position window
;intx, horizontal position window
;dwStyle, look into WIN32.HLP
;lpWindowName, pointer to window name
;lpClassName, pointer to class name
;dwExStyle, extra window style 0=no
;- API Function ;hwnd,return value=handle of window

;==============================================================================
; API "ShowWindow" function sets the specified window's show state.
;-----------------------------------------------------------------------------push
1h
;nCmdShow, show state 1=SW_SHOWNORMAL
push
hWnd
;hwnd, handle of window
call
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 window
call
UpdateWindow
;- API Function ;==============================================================================
; API "GetMessageA" retrieves a message & places it in the specified structure.
;-----------------------------------------------------------------------------LoopGetMessage:
push
0h
;wMsgFilterMax, highest message value
push
0h
;wMsgFilterMin, lowest message value
push
0h
;hWnd, handle of window who gets msg.
push
OFFSET hWnd
;lpMsg, pointer to MSG structure
call
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 structure
call
TranslateMessage
;- API Function - keyboard code
;==============================================================================
; API "DispatchMessageA" function dispatches a message to a window procedure.
;-----------------------------------------------------------------------------push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
DispatchMessageA
;- API Function jmp
LoopGetMessage
;check for message again, goto LABEL
Page 6

td_win32asm_220.asm
;-----------------------------------------------------------------------------; API FreeLibrary unmaps the modul from address space of the calling process
;-----------------------------------------------------------------------------FreeLib:
push
hLibrary
;hLibModule, handle loaded lib. module
call
FreeLibrary
;- API Function ;==============================================================================
; Next we terminate our program (API=ExitProcess)
;-----------------------------------------------------------------------------ExitPrg:
push
hInstance
;push our programm handle to exit
call
ExitProcess
;- API Function ;##############################################################################
; The Window Procedure (API=RegisterClassExA) for this registered window.
;-----------------------------------------------------------------------------WP1:
push
ebp
;create stack frame
mov
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 recieved
jne
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 file
push
54400008h
;dwStyle, defines the window style
push
hInstance
;hInstance, handle of module instance
push
WP1_hWnd
;hwndParent, handle parent window 0=no
call
[p_MCIWndCreate]
;- API Function mov
mcihWnd,eax
;handle of MCI window
pop
eax
;clear stack !
pop
eax
pop
eax
pop
eax
call
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

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 data
push
hInstance
;hInstance, handle of our program
push
0500h
;hMenu, the child-window ID
push
WP1_hWnd
;hWndParent, handle parent window 0=no
push
00000018h
;intnHeight, window height pixel
push
00000018h
;intnWidth, window width pixel
push
00000004h
;inty, vertical position window
push
00000004h
;intx, horizontal position window
push
54000080h
;dwStyle, button style
push
OFFSET BUTTON0500_WindowName
;lpWindowName, pointer to window name
push
OFFSET BUTTONClassName
;lpClassName, pointer to class name
push
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 ID
push
hInstance
;hInstance, handle of modul instance
call
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 bitmap
push
0h
;wParam, first message ( IMAGE_BITMAP )
push
0F7h
;uMsg, message to send ( BM_SETIMAGE )
push
BUTTON0500_hWnd
;hWnd, handle of destination window
call
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 data
push
hInstance
;hInstance, handle of our program
push
0h
;hMenu, handle window menu 0=class menu
push
WP1_hWnd
;hWndParent, handle parent window 0=no
push
00000016h
;intnHeight, window height pixel
push
00000108h
;intnWidth, window width pixel
push
00000005h
;inty, vertical position window
push
00000020h
;intx, horizontal position window
push
54000000h
;dwStyle, look WIN32.HLP + windows.inc
push
OFFSET STATIC0000_WindowName
;lpWindowName, pointer to window name
push
OFFSET STATICClassName
;lpClassName, pointer to class name
push
0300h
;dwExStyle,look WIN32.HLP + windows.inc
call
CreateWindowExA
;- API Function mov
STATIC0000_hWnd,eax
;hwnd,return value=handle of window
Page 8

td_win32asm_220.asm
jmp

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 LABEL
call
My_CleanSystem
;- SubRoutine ;-----------------------------------------------------------------------------; API "PostQuitMessage" indicates to Windows a request to terminate
;-----------------------------------------------------------------------------push
0h
;nExitCode, exit code=wParam
call
PostQuitMessage
;- API Function popad
;pop all register back from stack
xor
eax,eax
;set eax to 0 to exit our program
mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
10h
;return and clear stack
;==============================================================================
; WM_COMMAND (value=111h) message recieved ?
;-----------------------------------------------------------------------------WP1_uMsg_111h:
cmp
eax,111h
;check if WM_COMMAND message recieved
jne
WP1_uMsg_112h
;if not goto label
mov
eax,WP1_wParam
;extra info about the message in ax
cmp
ax,500h
;check if button ID=0500h clicked
jne
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 structure
mov
eax,WP1_hWnd
mov
hWndOwner,eax
;id window that owns dialog box
mov
eax,hInstance
mov
hInstance1,eax
;handle, our program id
mov
lpstrFilter,OFFSET LoadFileFilte;pointer to string + filter, 0= no
mov
lpstrCustomFilter,0h
;pointer to user defined filter
mov
nMaxCustFilter,0h
;size bytes/characters of above
mov
nFilterIndex,0h
;filter index of lpstrFilter
mov
lpstrFile,OFFSET LoadFileBuffer ;pointer to filename buffer
mov
nMaxFile,104h
;max size bytes/characters of above
mov
lpstrFileTitle,0h
;pointer title of the selected file
mov
nMaxFileTitle,0h
;size of the lpstrFileTitle buffer
mov
lpstrInitialDir,0h
;pointer init file dir,0=default
mov
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

td_win32asm_220.asm
mov
lpfnHook,0h
;? used if flag is OFN_ENABLETEMPLATE
mov
lpTemplateName,0h
;? used if flag is OFN_ENABLETEMPLATE
mov
lpstrDefExt,0h
;pointer default extension file, 0=no
push
OFFSET lStructSize
;lpofn, pointer OPENFILENAME structure
call
GetOpenFileNamePreviewA
;- API Function cmp
eax,0h
;check if an error occurs
je
WP1_return
;exit on error
mov
mci_filehandle,eax
;handle of new file
;-----------------------------------------------------------------------------; API "lstrcpyA" copy's a string from source to destination.
;-----------------------------------------------------------------------------mov
ax,nFileOffset
;given from OPENFILENAME structure
cwde
;convert word in AX into doubleword EAX
mov
ebx,lpstrFile
;given from OPENFILENAME structure
add
ebx,eax
;calculate OFFSET filename
push
ebx
;lpString2, pointer source string
push
OFFSET TestFileName
;lpString1, pointer destination string
call
lstrcpyA
;- API Function ;-----------------------------------------------------------------------------; API "lstrcmpiA" compares two strings, check if loaded file is an AVI file.
;-----------------------------------------------------------------------------mov
ax,nFileExtension
;given from OPENFILENAME structure
cwde
;convert word in AX into doubleword EAX
mov
ebx,lpstrFile
;given from OPENFILENAME structure
add
ebx,eax
;calculate OFFSET filename extender
push
ebx
;lpString2, pointer second string
push
OFFSET AVIextender
;lpString1, pointer first string
call
lstrcmpiA
;- API Function cmp
eax,0h
;check if strings are equal
je
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 file
push
54400008h
;dwStyle, defines the window style
push
hInstance
;hInstance, handle of module instance
push
WP1_hWnd
;hwndParent, handle parent window 0=no
call
[p_MCIWndCreate]
;- API Function mov
mcihWnd,eax
;handle of MCI window
pop
eax
;clear stack !
pop
eax
pop
eax
pop
eax
call
My_MoveWindow
;- SUBROUTINE ;-----------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of STATIC child window.
Page 10

td_win32asm_220.asm
;-----------------------------------------------------------------------------push
01h
;bRepaint, repaint flag
push
16h
;nHeight, height
push
108h
;nWidth, width
push
5h
;Y, vertical position
push
20h
;X, horizontal position
push
STATIC0000_hWnd
;hWnd, handle of window
call
MoveWindow
;- API Function ;-----------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of the specified window.
;-----------------------------------------------------------------------------push
01h
;bRepaint, repaint flag
push
68h
;nHeight, height
push
136h
;nWidth, width
push
10h
;Y, vertical position
push
50h
;X, horizontal position
push
WP1_hWnd
;hWnd, handle of window
call
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 window
call
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=sys
push
0h
;mode, access mode to use, OF_READ = 0h
push
OFFSET TestFileName
;szFile, string - the name of the file
push
OFFSET fip
;ppfile, address file interface pointer
call
AVIFileOpenA
;- API Function cmp
eax,0h
;check if an ERROR occured
je
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 Button
push
OFFSET MB1_Titel
;lpCaption,pointer to title text
push
OFFSET MB1_AVIFileError
;lpText,pointer to text message box
push
WP1_hWnd
;handle of owner window 0=no owner
call
MessageBoxA
;- API Function ;-----------------------------------------------------------------------------; API "AVIFileExit" exits the AVIFile library and decrements the
; reference count for the library.
Page 11

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 structure
push
OFFSET dwMaxBytesPerSec
;pfi, address of AVIFILEINFO structure
push
fip
;pfile, handle of an open AVI file
call
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 file
call
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 file
push
50000008h
;dwStyle, defines the window style
push
hInstance
;hInstance, handle of module instance
push
WP1_hWnd
;hwndParent, handle parent window 0=no
call
[p_MCIWndCreate]
;- API Function mov
mcihWnd,eax
;handle of MCI window
pop
eax
;clear stack !
pop
eax
pop
eax
pop
eax
;-----------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of STATIC child window.
;-----------------------------------------------------------------------------push
01h
;bRepaint, repaint flag
push
16h
;nHeight, height
mov
eax,dwWidth
;calculate width of STATIC child window
sub
eax,1Ah
push
eax
;nWidth, width
push
5h
;Y, vertical position
push
20h
;X, horizontal position
push
STATIC0000_hWnd
;hWnd, handle of window
Page 12

td_win32asm_220.asm
call
MoveWindow
;- API Function ;-----------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of the MCI window.
;-----------------------------------------------------------------------------push
01h
;bRepaint, repaint flag
mov
eax,dwHeight
;calculate height of the mci window
add
eax,1Ah
push
eax
;nHeight, height
push
dwWidth
;nWidth, width
push
20h
;Y, vertical position
push
4h
;X, horizontal position
push
mcihWnd
;hWnd, handle of window
call
MoveWindow
;- API Function ;-----------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of the MAIN window.
;-----------------------------------------------------------------------------push
01h
;bRepaint, repaint flag
mov
eax,dwHeight
;calculate height of the main window
add
eax,64h
push
eax
;nHeight, height
mov
eax,dwWidth
;calculate width of the main window
add
eax,12h
push
eax
;nWidth, width
push
10h
;Y, vertical position
push
50h
;X, horizontal position
push
WP1_hWnd
;hWnd, handle of window
call
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 window
call
UpdateWindow
;- API Function jmp
WP1_return
;==============================================================================
; WM_SYSCOMMAND (value=112h) message recieved ?
;-----------------------------------------------------------------------------WP1_uMsg_112h:
cmp
eax,112h
;check if WM_COMMAND message recieved
jne
WP1_return
;if not goto label
mov
eax,WP1_wParam
;extra info about the message
cmp
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

td_win32asm_220.asm
WP1_return:
popad
;pop all register from stack
push
WP1_lParam
;extra info about the message
push
WP1_wParam
;extra info about the message
push
WP1_uMsg
;the message number
push
WP1_hWnd
;handle of window who receives message
call
DefWindowProcA
;- API Function mov
esp,ebp
;delete stack frame
pop
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 object
call
DeleteObject
;- API Function ret
My_MessageBoxA:
;-----------------------------------------------------------------------------; API "MessageBox" creates, displays, and operates a message box.
;-----------------------------------------------------------------------------push
0h
;uType, style, 0=MB_OK Button
push
OFFSET MB1_Titel
;lpCaption,pointer to title text
push
ebx
;lpText,pointer to text message box
push
hWnd
;handle of owner window 0=no owner
call
MessageBoxA
;- API Function ret
My_MoveWindow:
;-----------------------------------------------------------------------------; API "MoveWindow" changes the position and dimensions of the specified window.
;-----------------------------------------------------------------------------push
01h
;bRepaint, repaint flag
push
20h
;nHeight, height
push
12Ch
;nWidth, width
push
20h
;Y, vertical position
push
0h
;X, horizontal position
push
mcihWnd
;hWnd, handle of window
call
MoveWindow
;- API Function ret
My_SendMessageA:
;-----------------------------------------------------------------------------; API "SendMessageA" sends a WM_CLOSE message directly to the open MCI window
;-----------------------------------------------------------------------------Page 14

push
push
push
push
call
ret

0h
0h
10h
mcihWnd
SendMessageA

td_win32asm_220.asm
;lParam, second message parameter
;wParam, first message parameter
;uMsg, message to send ( WM_CLOSE )
;hwnd, handle of destination window
;- API Function -

My_StringRoutine:
;-----------------------------------------------------------------------------; API "lstrcpyA" copy's a string from source to destination.
;-----------------------------------------------------------------------------mov
ax,nFileOffset
;given from OPENFILENAME structure
cwde
;convert word in AX into doubleword EAX
mov
ebx,lpstrFile
;given from OPENFILENAME structure
add
ebx,eax
;calculate OFFSET filename
push
ebx
;lpString2, pointer source string
push
OFFSET MediaFileName
;lpString1, pointer destination string
call
lstrcpyA
;- API Function ;-----------------------------------------------------------------------------; API "SendMessageA" sends a WM_SETTEXT message to change the text in STATIC
;-----------------------------------------------------------------------------push
OFFSET MediaFileName
;lParam, pointer to window-text string
push
0h
;wParam, not used must be 0h
push
0Ch
;uMsg, send WM_SETTEXT message
push
STATIC0000_hWnd
;hwnd, handle of destination window
call
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

Vous aimerez peut-être aussi