;==============================================================================
;	    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.
; Example   : if windows already had registered *.mpg files in system.ini [MCI]
;	      you could play mpg files, if not, it seems, you can not.
; Supported : CDAUDIO, aif, au, avi, mid, mov, mpg, rmi, snd, 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 \masm32\include\windows.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\winmm.lib
includelib \masm32\lib\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
FreeLibrary 		PROTO :DWORD
ExitProcess		PROTO :DWORD
MessageBoxA		PROTO :DWORD,:DWORD,:DWORD,:DWORD
DestroyWindow 		PROTO :DWORD
CreateToolbarEx 	PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
			      :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
MoveWindow		PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
GetWindowTextA		PROTO :DWORD,:DWORD,:DWORD
SetWindowTextA		PROTO :DWORD,:DWORD
SetTimer		PROTO :DWORD,:DWORD,:DWORD,:DWORD
KillTimer		PROTO :DWORD,:DWORD
SendMessageA 		PROTO :DWORD,:DWORD,:DWORD,:DWORD
lstrcpyA		PROTO :DWORD,:DWORD
lstrcmpiA		PROTO :DWORD,:DWORD
GetOpenFileNamePreviewA PROTO :DWORD
AVIFileInit		PROTO
AVIFileOpenA		PROTO :DWORD,:DWORD,:DWORD,:DWORD
AVIFileInfoA		PROTO :DWORD,:DWORD,:DWORD
AVIFileRelease		PROTO :DWORD
AVIFileExit		PROTO
mciSendCommandA   	PROTO :DWORD,:DWORD,:DWORD,:DWORD

;==============================================================================
; .const 	= the constants area starts here,constants are defined & fixed
;------------------------------------------------------------------------------
.const

;==============================================================================
; .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's Multimedia Player",0;window name
MB2_Text		db "Supported Formats : CDAUDIO, aif, au, avi, mid, mov, mpg, rmi, snd, wav and more.",0;
MB1_DllError		db "can not load DLL: msvfw32.dll",0;message box text
MB1_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 library
f_MCIWndCreate		db "MCIWndCreate",0	;function name inside library
toolbar00_str_C0	db "Play Media File",0	;toolbar button text
toolbar00_str_C1	db "Play Audio CD",0	;toolbar button text
toolbar00_str_C10	db "Supported Formats",0;toolbar button text
LoadFileFilte		db "Media Files (*.*)",0,"*.*",0,0;
LoadFileTitle		db "Select a File",0	;
AVIextender		db "avi",0		;AVI file extender
CDAextender		db "cda",0		;CDA file extender
CDAdevice		db "cdaudio",0		;name of device
MOVdevice		db "MPEGVideo",0	;name of device

; - TBBUTTON structure ( API=CreateToolbarEx ) - ARRAY !!!
iBitmap_00		dd 0h		;zero-based index of button image
idCommand_00		dd 0h		;ID or, if fsStyle=TBSTYLE_SEP, zero
fsState_00		db 4h		;state flags,4h=TBSTATE_ENABLED
fsStyle_00		db 1h		;button style,1h=TBSTYLE_SEP
bReserved_00		db 2h dup (0)	;reserved byte,error in WIN32.HLP ?
dwData_00		dd 0h		;application-defined value
iString_00		dd 0h		;zero-based index of button string

iBitmap_01		dd 1h		;zero-based index of button image
idCommand_01		dd 0C0h		;ID of button, WM_COMMAND uMsg/wParam
fsState_01		db 4h		;state flags,4h=TBSTATE_ENABLED
fsStyle_01		db 0h		;button style,0h=TBSTYLE_BUTTON
bReserved_01		db 2h dup (0)	;reserved byte,error in WIN32.HLP ?
dwData_01		dd 0h		;application-defined value
iString_01		dd 0h		;zero-based index of button string

iBitmap_02		dd 2h		;zero-based index of button image
idCommand_02		dd 0C1h		;ID of button, WM_COMMAND uMsg/wParam
fsState_02		db 4h		;state flags,4h=TBSTATE_ENABLED
fsStyle_02		db 0h		;button style,0h=TBSTYLE_BUTTON
bReserved_02		db 2h dup (0)	;reserved byte,error in WIN32.HLP ?
dwData_02		dd 0h		;application-defined value
iString_02		dd 0h		;zero-based index of button string

iBitmap_03		dd 3h		;zero-based index of button image
idCommand_03		dd 0h		;ID or, if fsStyle=TBSTYLE_SEP, zero
fsState_03		db 4h		;state flags,4h=TBSTATE_ENABLED
fsStyle_03		db 1h		;button style,1h=TBSTYLE_SEP
bReserved_03		db 2h dup (0)	;reserved byte,error in WIN32.HLP ?
dwData_03		dd 0h		;application-defined value
iString_03		dd 0h		;zero-based index of button string

iBitmap_04		dd 4h		;zero-based index of button image
idCommand_04		dd 0C10h	;ID of button, WM_COMMAND uMsg/wParam
fsState_04		db 4h		;state flags,4h=TBSTATE_ENABLED
fsStyle_04		db 0h		;button style,0h=TBSTYLE_BUTTON
bReserved_04		db 2h dup (0)	;reserved byte,error in WIN32.HLP ?
dwData_04		dd 0h		;application-defined value
iString_04		dd 0h		;zero-based index of button string

iBitmap_05		dd 5h		;zero-based index of button image
idCommand_05		dd 0h		;ID or, if fsStyle=TBSTYLE_SEP, zero
fsState_05		db 4h		;state flags,4h=TBSTATE_ENABLED
fsStyle_05		db 1h		;button style,1h=TBSTYLE_SEP
bReserved_05		db 2h dup (0)	;reserved byte,error in WIN32.HLP ?
dwData_05		dd 0h		;application-defined value
iString_05		dd 0h		;zero-based index of button string

;==============================================================================
; .Data?	= the data? area starts here, not defined and not fixed
;------------------------------------------------------------------------------
.data?
toolbar00_hWnd		dd ?			;handle of the toolbar
hLibrary		dd ?			;loaded library handle
p_MCIWndCreate		dd ?			;pointer function inside DLL
mcihWnd			dd ?			;handle of mci window
mci_filehandle		dd ?			;filehandle media file
fip			dd ?			;AVI file interface pointer
ErrorFlag		dd ?			;
temp_00			dd ?			;
TrackNumber		dd ?			;
LoadFileBuffer		db 104h dup(?)		;buffer for load filename
TestFileName		db 104h dup(?)		;buffer, filename
MediaFileName		db 104h dup(?)		;buffer, filename

; - 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

; - Push Parameter done by lpfnWndProc Function ( API=RegisterClassExA )
WP1_CallBack		dd ?		;return address of calling routine
WP1_hWnd		dd ?		;handle of window who receives message
WP1_uMsg		dd ?		;the message number 
WP1_wParam		dd ?		;extra info about the message 
WP1_lParam		dd ?		;extra info about the message 

; - 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 

; - 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 handle
lpstrFilter		dd ?	;pointer to string + filter
lpstrCustomFilter	dd ?	;pointer to user defined filter
nMaxCustFilter		dd ?	;size bytes/characters of above
nFilterIndex		dd ?	;filter index of lpstrFilter 
lpstrFile		dd ?	;pointer initialize filename, 0=no
nMaxFile		dd ?	;size bytes/characters of above
lpstrFileTitle		dd ?	;pointer title of the selected file
nMaxFileTitle		dd ?	;size of the lpstrFileTitle buffer 
lpstrInitialDir		dd ?	;pointer  init file dir,0=default
lpstrTitle		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 ?	;only used if flag is OFN_ENABLETEMPLATE
lpTemplateName		dd ?	;only used if flag is OFN_ENABLETEMPLATE

; - 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 the 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 the entire file 
dwRate			dd ?	;dwRate / dwScale gives the samples per second 
dwLength		dd ?	;length of the AVI file
dwEditCount		dd ?	;number streams added/deleted from AVI file 
szFileType		db 40h dup(?);string containing file type infos

; - MCI_GENERIC_PARMS Structure ( API=mciSendCommand ) -
generic_dwCallback	dd ?		;

; - 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 ?		;

; - MCI_SET_PARMS Structure ( API=mciSendCommand ) -
set_dwCallback		dd ?		;
set_dwTimeFormat	dd ?		;
set_dwAudio		dd ?		;

; - 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
;------------------------------------------------------------------------------
.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 "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 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				;LABEL

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 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				;LABEL

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;OFFSET MenuName	;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).
;------------------------------------------------------------------------------
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	0h				;hWndParent, handle parent window 0=no
push	00000062h			;intnHeight, window height pixel
push	0000013Eh			;intnWidth, window width pixel
push	00000008h			;inty, vertical position window
push	00000030h			;intx, horizontal position window
push	04CA0000h			;dwStyle, look into WIN32.HLP
push	OFFSET WindowName		;lpWindowName, pointer to window name
push	OFFSET ClassName		;lpClassName, pointer to class name
push	0300h				;dwExStyle, extra window style 0=no
call	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_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

;------------------------------------------------------------------------------
; 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 -

;##############################################################################
;==============================================================================
; This is the Window Procedure lpfnWndProc (API=RegisterClassExA) for this
; registered window.
; The WindowProc function is an application-defined callback function that
; processes messages sent to a window. 
; Here our code for checking the receiving messages resist.
; In the future it is the main work for us to react to the recieved messages.
; First we POP all parameter given by Windows from the stack and store them in
; variables for future use.
; !!!!! Next we PUSH the WP1_CallBack return address back to the stack !!!!!
; !!! WP1_CallBack must be avaible on the stack in this window procedure !!!
; It is also a good idea to PUSHAD all register, because than we are free to
; use all register in this window procedure.
; Before we leave this subroutine we must POPAD them back. 
;------------------------------------------------------------------------------
WP1:
pop 	WP1_CallBack			;POP return address lpfnWndProc
pop	WP1_hWnd			;handle of window who receives message
pop	WP1_uMsg			;the message number
pop	WP1_wParam			;extra info about the message
pop	WP1_lParam			;extra info about the message
push	WP1_CallBack			;PUSH return address lpfnWndProc !!!!!
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
call	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 structure
push	14h				;dyBitmap,height pixels of the images
push	14h				;dxBitmap,width pixels of the images
push	14h				;dyButton,height pixels of the buttons
push	14h				;dxButton,width pixels of the buttons
push	06h				;iNumButtons,Number buttons in toolbar
push	OFFSET iBitmap_00		;lpButtons,pointer TBBUTTON structure
push	80h				;wBMID,ID for the bitmap resource
push	hInstance			;hBMInst,instance bitmap resource
push	1h				;nBitmaps,number of button image file
push	500h				;wID,control identifier for toolbar
push	50400900h			;ws,windows styles in WIN32.HLP
push	WP1_hWnd			;hwnd,handle owner window 0=no owner
call 	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_SHOW
push 	toolbar00_hWnd			;hwnd, handle of window
call 	ShowWindow			;- API Function -
jmp	WP1_return

;==============================================================================
; WM_DESTROY (value=02h) message received ?
;------------------------------------------------------------------------------
WP1_uMsg_02h:
cmp	eax,2h				;check if value=2h (WM_DESTROY)
jne	WP1_uMsg_05h			;if not 2h go to LABEL
;------------------------------------------------------------------------------
; API "PostQuitMessage" indicates to Windows a request to terminate
;------------------------------------------------------------------------------
call	My_MCI_Stop			;- SUBROUTINE -
popad					;pop all register back from stack
push	0h				;nExitCode, exit code=wParam
call 	PostQuitMessage			;- API Function -
xor	eax,eax				;set eax to 0 to exit our program
ret					;return to lpfnWndProc

;==============================================================================
; WM_Size (value=05h) message, used to resize the window area
;------------------------------------------------------------------------------
WP1_uMsg_05h:
cmp	eax,05h				;check if WM_SIZE message recieved
jne	WP1_uMsg_0Fh			;if not goto label
;------------------------------------------------------------------------------
; API "SendMessageA" sends a message, TB_AUTOSIZE to fit toolbar and bitmaps
;------------------------------------------------------------------------------
push	0h				;lParam, second message parameter
push	0h				;wParam, first message parameter (ID)
push	421h				;uMsg, send TB_AUTOSIZE message
push	toolbar00_hWnd			;hwnd, handle of destination window
call	SendMessageA			;- API Function -
jmp	WP1_return			;

;==============================================================================
; WM_PAINT (value=0Fh) message, used to repaint the window area
;------------------------------------------------------------------------------
WP1_uMsg_0Fh:
cmp	eax,0Fh				;check if WM_PAINT message recieved
jne	WP1_uMsg_4Eh			;if not goto label
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 recieved
jne	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 
; 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 EAX
cmp	eax,0FFFFFDF8h			;check if code TTN_NEEDTEXT received
jne	WP1_return			;if not goto label
mov	eax,[ebx+4]			;move idFrom ( NMHDR structure ) to EAX
cmp	eax,0C0h			;is it toolbar button ID=0C0h
jne	next_01				;if not goto label
mov	[ebx+12],OFFSET toolbar00_str_C0;move our text pointer to lpszText
next_01:				;
cmp	eax,0C1h			;is it toolbar button ID=0C1h
jne	next_02				;if not goto label
mov	[ebx+12],OFFSET toolbar00_str_C1;move our text pointer to lpszText
next_02:				;
cmp	eax,0C10h			;is it toolbar button ID=0C10h
jne	next_03				;if not goto label
mov	[ebx+12],OFFSET toolbar00_str_C10;move our text pointer to lpszText
next_03:				;
jmp	WP1_return			;

;==============================================================================
; WM_COMMAND (value=111h) message recieved ?
; On WM_COMMAND message we check if it is posted by a menu control ( lParam=0 )
; or by a child window control ( lParam not 0 )!
;
;                 Low word of wParam    High word wParam    lParam
; Menu          - Menu ID               0                   0
; Child window  - Control ID            Notification code   Child Window Handle
;------------------------------------------------------------------------------
WP1_uMsg_111h:
cmp	eax,111h			;check if WM_COMMAND message recieved
jne	WP1_wParam_113h			;if not goto label
mov	eax,WP1_lParam			;check if menu control ( lParam=0 )
jne	WP1_lParam_1_0600h		;if not 0 goto label
;==============================================================================
; WM_COMMAND message	lParam = 0	- menu control or user message
;------------------------------------------------------------------------------
WP1_lParam_0_0C0h:			;LABEL
mov	eax,WP1_wParam			;extra info about the message in ax
cmp	ax,0C0h				;check if toolbar button ID=C0h clicked
jne	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 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			;? 
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 for Audio CD.
;------------------------------------------------------------------------------
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
mov	temp_00,ebx			;store pointer for future use
push	ebx				;lpString2, pointer second string
push	OFFSET CDAextender		;lpString1, pointer first string
call	lstrcmpiA			;- API Function -
cmp	eax,0h				;check if strings are equal
jne	_CHECK_AVI			;if equal go to LABEL
;------------------------------------------------------------------------------
; calculate choosen Audio CD Track
;------------------------------------------------------------------------------
mov	eax,0h
mov	TrackNumber,0h
mov	ebx,temp_00
dec	ebx
dec	ebx
mov	al,[ebx]
cmp	al,2Fh
jbe	_AUDIO_CD_TRACK1
cmp	al,3Ah
jae	_AUDIO_CD_TRACK1
sub	al,30h
add	TrackNumber,eax

mov	eax,0h
dec	ebx
mov	al,[ebx]
cmp	al,2Fh
jbe	_AUDIO_CD_TRACK1
cmp	al,3Ah
jae	_AUDIO_CD_TRACK1
sub	al,30h
mov	bl,0Ah
mul	bl
cwde
add	TrackNumber,eax
jmp	_AUDIO_CD

_CHECK_AVI:
;------------------------------------------------------------------------------
; API "lstrcmpiA" compares two strings, check if 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

_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 structure
mov	open_lpstrDeviceType,eax	;device type = MPEGVideo
mov	eax,OFFSET MediaFileName	;
mov	open_lpstrElementName,eax	;name of file to open
push	OFFSET open_dwCallback        	;dwParam, address MCI_OPEN_PARMS struc.
push	2300h                         	;fdwCommand,
					;MCI_OPEN_TYPE		= 2000h
					;MCI_OPEN_ELEMENT	=  200h
					;MCI_OPEN_SHAREABLE	=  100h
push	0803h                      	;uMsg, command message, MCI_OPEN
push	0h                            	;IDDevice, not used with MCI_OPEN
call	mciSendCommandA               	;- API Function -
cmp	eax,0h				;
jne	_AUDIO_FILE			;
;------------------------------------------------------------------------------
; API "mciSendCommandA" obtains the clipping rectangle for the video device
;------------------------------------------------------------------------------
push	OFFSET dgv_generic_dwCallback	;dwParam, MCI_DGV_RECT_PARMS structure
push	40000h				;fdwCommand,
					;MCI_DGV_WHERE_DESTINATION = 40000h
push	0843h				;uMsg, command message, MCI_WHERE
push	open_wDeviceID			;IDDevice, given from MCI_OPEN
call	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 structure
push	0h				;fdwCommand, 0h=no command
push	0804h				;uMsg, command message, MCI_CLOSE
push	open_wDeviceID			;IDDevice, given from MCI_OPEN
call	mciSendCommandA			;- API Function -
cmp	ErrorFlag,0h			;check ErrorFlag 0h = no error
jne	_AUDIO_FILE			;
call	My_MCIWndCreate			;- SUBROUTINE -
;------------------------------------------------------------------------------
; API "MoveWindow" changes the position and dimensions of the MCI window.
;------------------------------------------------------------------------------
push	01h				;bRepaint, repaint flag
add	dgv_bottom,20h			;calculate height of the mci window
push	dgv_bottom			;nHeight, height
add	dgv_right,6h			;calculate width of the mci window
push	dgv_right			;nWidth, width
push	24h				;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
add	dgv_bottom,42h			;calculate height of the main window
push	dgv_bottom			;nHeight, height
add	dgv_right,12h			;calculate width of the main window
push	dgv_right			;nWidth, width
push	08h				;Y, vertical position
push	30h				;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 -
call	My_MCI_Play			;
call	My_SetTimer			;
jmp	WP1_return			;

_AUDIO_FILE:
call	My_MCI_Stop			;- SUBROUTINE -
call	My_KillTimer			;
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 window
call	UpdateWindow			;- API Function -
call	My_MCI_Play			;
call	My_SetTimer			;
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 WindowName		;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.
;------------------------------------------------------------------------------
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 -
cmp	dwHeight,1h			;check if AVI file have a video stream
jbe	_AUDIO_FILE			;if not goto LABEL
call	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 flag
add	dwHeight,20h			;calculate height of the mci window
push	dwHeight			;nHeight, height
add	dwWidth,6h			;calculate width of the mci window
push	dwWidth				;nWidth, width
push	24h				;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
add	dwHeight,42h			;calculate height of the main window
push	dwHeight			;nHeight, height
add	dwWidth,12h			;calculate width of the main window
push	dwWidth				;nWidth, width
push	08h				;Y, vertical position
push	30h				;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 -
call	My_MCI_Play			;
call	My_SetTimer			;
jmp	WP1_return			;

WP1_lParam_0_0C1h:
cmp	ax,0C1h				;check if button ID=0C1h clicked
jne	WP1_lParam_0_C10h		;if not 0C1h goto LABEL
_AUDIO_CD_TRACK1:
mov	TrackNumber,1h			;
_AUDIO_CD:
call	My_MCI_Stop			;- SUBROUTINE -
call	My_KillTimer			;
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.
; It seems that API MCIWndCreate pushes 4 doublewords to the stack, we don't
; need them and remove them after calling !!!
;------------------------------------------------------------------------------
push	OFFSET CDAdevice		;szFile, name MCI device or data file
push	54400078h			;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_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 window
call	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	= 0Ah
mov	set_dwAudio,6401h		;fill MCI_SET_PARMS structure
					;MCI_SET_AUDIO_ALL	= 4001h
					;MCI_SET_ON		= 2000h
					;MCI_SET_TIME_FORMAT	= 400h
push	OFFSET set_dwCallback		;dwParam, address MCI_SET_PARMS struc.
push	6401h				;fdwCommand, same as above 
push	080Dh				;uMsg, command message, MCI_SET
push	-1				;IDDevice, MCI_ALL_DEVICE_ID = -1
call	mciSendCommandA			;- API Function -
;------------------------------------------------------------------------------
; API "SendMessageA" sends a MCI_SEEK message, seek to track number
;------------------------------------------------------------------------------
push	TrackNumber			;lParam, seek to track
push	0h				;wParam, not used
push	807h				;uMsg, send MCI_SEEK message
push	mcihWnd				;hwnd, handle of destination window
call	SendMessageA			;- API Function -
call	My_MCI_Play			;
call	My_SetTimer			;
jmp	WP1_return			;

WP1_lParam_0_C10h:
cmp	ax,0C10h			;check if toolbarbutton ID=C10h clicked
jne	WP1_return			;if not 0C10h goto LABEL
;==============================================================================
; API "MessageBoxA" creates a message box, displaying the supported formats
;------------------------------------------------------------------------------
push	0h				;uType, style, 0=MB_OK Button
push	OFFSET WindowName		;lpCaption,pointer to title text
push	OFFSET MB2_Text			;lpText,pointer to text message box
push	WP1_hWnd			;handle of owner window 0=no owner
call	MessageBoxA			;- API Function -
jmp	WP1_return			;

;==============================================================================
; WM_COMMAND message	lParam not 0	- child window		DUMMY !!!
;------------------------------------------------------------------------------
WP1_lParam_1_0600h:			;LABEL
jmp	WP1_return			;DUMMY !!!

;==============================================================================
; WM_TIMER (value=113h) message received ?
;------------------------------------------------------------------------------
WP1_wParam_113h:
cmp	eax,113h			;check if WM_TIMER message recieved
jne	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 copy
push	OFFSET TestFileName		;lpString, address of buffer for text
push	mcihWnd				;hWnd, handle of window or control
call	GetWindowTextA			;- API Function -
;------------------------------------------------------------------------------
; API "SetWindowTextA" set's the text of the specified window's title bar.
;------------------------------------------------------------------------------
push	OFFSET TestFileName		;lpsz, address of string
push	WP1_hWnd			;hwnd, handle of window or control
call	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 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 -
ret					;return to lpfnWndProc (multitask os)
;==============================================================================
;##############################################################################

;******************************************************************************
;==============================================================================
; My own subroutine(s) for a compacter code resist here ...
;------------------------------------------------------------------------------
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.
; It seems that API MCIWndCreate pushes 4 doublewords to the stack, we don't
; need them and remove them after calling !!!
;------------------------------------------------------------------------------
push	OFFSET MediaFileName		;szFile, name MCI device or data file
push	54400078h			;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				;
ret					;

My_MCI_Play:
;------------------------------------------------------------------------------
; API "SendMessageA" sends a MCI_PLAY message to autoplay file
;------------------------------------------------------------------------------
push	0h				;lParam, not used
push	0h				;wParam, not used
push	806h				;uMsg, send MCI_PLAY message
push	mcihWnd				;hwnd, handle of destination window
call	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 structure
push	0h				;fdwCommand, 0h=no command
push	0808h				;uMsg, command message, MCI_STOP
push	-1				;IDDevice, -1 = close all devices
call	mciSendCommandA			;- API Function -
ret

My_MessageBoxA:
push	0h				;uType, style, 0=MB_OK Button
push	OFFSET WindowName		;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_MCI:
;------------------------------------------------------------------------------
; 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	24h				;Y, vertical position
push	4h				;X, horizontal position
push	mcihWnd				;hWnd, handle of window
call	MoveWindow			;- API Function -
ret					;

My_MoveWindow_MAIN:
;------------------------------------------------------------------------------
; API "MoveWindow" changes the position and dimensions of the specified window.
;------------------------------------------------------------------------------
push	01h				;bRepaint, repaint flag
push	62h				;nHeight, height
push	13Eh				;nWidth, width
push	08h				;Y, vertical position
push	30h				;X, horizontal position
push	WP1_hWnd			;hWnd, handle of window
call	MoveWindow			;- API Function -
ret					;

My_SendMessageA:
;------------------------------------------------------------------------------
; API "SendMessageA" sends a WM_CLOSE message directly to the open MCI window
;------------------------------------------------------------------------------
push	0				;lParam, second message parameter
push    0				;wParam, first message parameter
push    10h				;uMsg, message to send ( WM_CLOSE )
push    mcihWnd				;hwnd, handle of destination window
call    SendMessageA			;- API Function -
ret					;

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 -
ret					;

My_SetTimer:
;------------------------------------------------------------------------------
; API "SetTimer" creates a timer with the specified time-out value.
;------------------------------------------------------------------------------
push	0h				;tmprc, address timer procedure,0=this
push	1000				;uTimeout, time-out value milliseconds
push	10h				;idTimer, timer identifier, nonzero
push	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 identifier
push	WP1_hWnd			;hWnd, handle of window installed timer
call	KillTimer			;- API Function -
;------------------------------------------------------------------------------
; API "SetWindowTextA" set's the text of the specified window's title bar.
;------------------------------------------------------------------------------
push	OFFSET WindowName		;lpsz, address of string
push	WP1_hWnd			;hwnd, handle of window or control
call	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__221.asm					;asm command
; rc.exe /v rsrc.rc						;rc command
; cvtres.exe /machine:ix86 rsrc.res
; link.exe /subsystem:windows td__221.obj rsrc.obj		;link command
;==============================================================================