# Very basic MCI Example by Frank Gerritse # Based on templat0.asm by Vinaeus # Works with all mci supported media, such as avi, mpeg, wav, # (and if you have the right codecs installed:), mp3, divx, dvd, etc # E-mail me if you have any questions # Primairly tested on windows XP # frank@endoria.net begin imports #many frequently used functions are here [Kernel32.dll] GetModuleHandleA GetCommandLineA ExitProcess [user32.dll] RegisterClassExA CreateWindowExA ShowWindow UpdateWindow DefWindowProcA GetMessageA TranslateMessage DispatchMessageA SendMessageA LoadCursorA LoadIconA BeginPaint EndPaint PostQuitMessage MessageBoxA SetFocus [shell32.dll] ShellAboutA #I'm too lazy to make my own aboutbox, so I use the standard aboutbox from Windows :-) [comdlg32.dll] GetOpenFileNameA GetSaveFileNameA [crtdll.dll] malloc memset [winmm.dll] mciSendStringA end imports #-----------------Constants---------------------------------------------- begin const #many commonly used constants are here SW_HIDE 0 SW_SHOW 5 BS_FLAT 32768 #nice flat buttons :) WS_CHILD 1073741824 WS_VISIBLE 268435456 WS_SYSMENU 524288 WS_CLIENTEDGE 512 WS_MINIMIZEBOX 131072 WM_CREATE 1 WM_COMMAND 273 WM_DESTROY 2 WM_PAINT 15 WM_QUIT 18 WM_SIZE 5 WM_SETTEXT 12 IDC_CROSS 32515 OFN_EXPLORER 524288 OFN_HIDEREADONLY 4 OFN_LONGNAMES 2097152 OFN_PATHMUSTEXIST 2048 MB_ICONASTERISK 64 SS_CENTER 1 end const #-----------------Data Section------------------------------------------- begin data sequence ofnfname 256 string static static string btn1txt Open file... string btn2txt Play string btn3txt Pause string btn4txt Stop string btn5txt About string mcistring open " string mcistring2 " alias bestand string mcistring3 set bestand time format milliseconds string mcistring4 status bestand length string playstring play bestand string pausestring pause all string stopstring close all string length 0 dword hwndMain 0 string Class Window dword hInstance 0 string ClassName WinClass string AppName MCI example string btn button string text Edit string combo combobox string list listbox string about MCI Example in Empowered Programmer by Frank Gerritse, mail: Frank@endoria.net string crlf 00 string colon : dword quit 0 string WindowCaption MCI [frank@endoria.net] sequence buffer 256 sequence buf 48 sequence listbuf 48 sequence icobuf 24 sequence pt 8 sequence ofnfname 256 dword hbtn1 0 dword hbtn2 0 dword hbtn3 0 dword hbtn4 0 dword hbtn5 0 dword hst1 0 dword CommandLine 0 dword hmem 0 sequence wndclass 16 sequence msg 28 sequence ibuf 32 dword mem 0 string ofnfilter All Files string b2 *.* #Opendialog requires to zerobytes after strings; byte b3 0 byte b4 0 dword htrack 0 dword dataend 4294967295 end data #------------------------------------------------------------------------- begin code proc strlen dword q push ebp mov ebp esp mov edi [q] mov eax 0 mov ecx 0 cld search_loop: inc ecx scasb jne search_loop dec ecx mov eax ecx leave ret 4 endp #------------------------------------------------------------------------ proc strcat dword s1 dword s2 dword len1 0 dword len2 0 dword addr 0 dword len 0 push ebp mov ebp esp add esp -48 invoke strlen [s1] mov [len1] eax invoke strlen [s2] mov [len2] eax add eax [len1] inc eax len = eax invoke [malloc] eax invoke memset eax 0 len mov [addr] eax mov edi eax mov ecx [len1] mov esi [s1] rep_movsb mov ecx [len2] mov esi [s2] rep_movsb mov eax [addr] leave ret 8 endp #------------------------------------------------------------------------ proc showopen dword x dword fn 0 sequence editstream 12 sequence ofn 76 dword st 0 dword n 0 push ebp mov ebp esp add esp -180 [ofn]=76 eax=[hwndMain] [ofn+4]=eax [ofn+8]=0 [ofn+12]=ofnfilter #note: the last string in this buffer must be terminated [ofn+16]=0 #by 2 0 bytes. Please see the data section and note [ofn+20]=0 #bytes b3 & b4 which do this [ofn+24]=1 [ofn+28]=ofnfname [ofn+32]=256 [ofn+36]=0 [ofn+40]=0 [ofn+44]=0 [ofn+48]=0 eax={OFN_EXPLORER} or eax {OFN_HIDEREADONLY} or eax {OFN_LONGNAMES} or eax {OFN_PATHMUSTEXIST} [ofn+52]=eax [ofn+56]=0 [ofn+60]=0 [ofn+64]=0 [ofn+68]=0 [ofn+72]=0 lea eax [ofn] invoke GetOpenFileNameA eax if eax=0 jmp so_out endif n=strlen ofnfname if n < 4 jmp so_out endif so_out: leave ret 4 endp #------------------------------------------------------------------------- proc WndProc dword hwnd dword msg dword wparam dword lparam dword fn 0 dword hdc 4 sequence ps 64 sequence rect 16 dword ordata 0 dword n 0 dword m 0 dword x 0 dword y 0 push ebp mov ebp esp add esp -180 cmp msg {WM_CREATE} je wmcreate cmp msg {WM_PAINT} je wmpaint cmp msg {WM_COMMAND} je wmcommand cmp msg {WM_DESTROY} jne default push 0 call PostQuitMessage jmp exit wmcreate: # #label # mov eax {WS_CHILD} or eax {WS_VISIBLE} or eax {SS_CENTER} ordata= eax invoke CreateWindowExA 0 static WindowCaption ordata 00 00 220 25 hwnd 0 [hInstance] 0 mov hst1 eax # #btn1 # mov eax {WS_CHILD} or eax {WS_VISIBLE} or eax {BS_FLAT} ordata= eax invoke CreateWindowExA 0 btn btn1txt ordata 65 25 100 25 hwnd 0 hInstance 0 mov hbtn1 eax # #btn2 # invoke CreateWindowExA 0 btn btn2txt ordata 65 60 100 25 hwnd 0 hInstance 0 mov hbtn2 eax # #btn3 # invoke CreateWindowExA 0 btn btn3txt ordata 65 95 100 23 hwnd 0 hInstance 0 mov hbtn3 eax # #btn4 # invoke CreateWindowExA 0 btn btn4txt ordata 65 130 100 23 hwnd 0 hInstance 0 mov hbtn4 eax # #btn5 # invoke CreateWindowExA 0 btn btn5txt ordata 65 165 100 23 hwnd 0 hInstance 0 mov hbtn5 eax jmp exit wmpaint: lea eax ps invoke BeginPaint hwnd eax mov hdc eax lea eax ps invoke EndPaint hwnd eax jmp exit wmcommand: btn1: mov eax hbtn1 cmp lparam eax jne btn2 invoke showopen 0 fn=strcat mcistring ofnfname fn=strcat fn mcistring2 invoke mciSendStringA fn 0 0 0 invoke SendMessageA hst1 {WM_SETTEXT} 0 ofnfname jmp exit btn2: mov eax hbtn2 cmp lparam eax jne hst1 invoke mciSendStringA playstring jmp exit hst1: mov eax hst1 cmp lparam eax jne btn3 jmp exit btn3: mov eax hbtn3 cmp lparam eax jne btn4 invoke mciSendStringA pausestring jmp exit btn4: mov eax hbtn4 cmp lparam eax jne btn5 invoke mciSendStringA stopstring jmp exit btn5: mov eax hbtn5 cmp lparam eax jne default invoke ShellAboutA hwnd WindowCaption about jmp exit default: invoke DefWindowProcA hwnd msg wparam lparam leave ret 16 exit: xor eax eax leave ret 16 endp #------------------------------------------------------------------------ proc WinMain dword hinst dword previnst dword comline dword cmdshow sequence wc 48 dword ordata 0 dword len 0 push ebp mov ebp esp add esp -80 [wc]= 48 [wc+4] =3 [wc+8]= WndProc [wc+12]= 0 [wc+16] =0 eax =hInstance [wc+20]= eax push 1 push hInstance call LoadIconA [wc+24]= eax [wc+44]= eax push {IDC_CROSS} push 0 call LoadCursorA [wc+28] =eax [wc+32]= 16 [wc+36]= 0 [wc+40]= ClassName lea eax wc invoke RegisterClassExA eax or eax {WS_SYSMENU} ordata=eax invoke CreateWindowExA {WS_CLIENTEDGE} ClassName WindowCaption ordata 50 50 230 240 0 0 hInstance 0 hwndMain= eax #this is old style before the advent of invoke push 1 push hwndMain call ShowWindow push hwndMain call UpdateWindow MsgLoop: invoke GetMessageA msg 0 0 0 cmp eax 0 je exitprocess invoke TranslateMessage msg invoke DispatchMessageA msg jmp MsgLoop exitprocess: mov eax [msg+8] leave ret 16 endp #------------------------------------------------------------------------ EntryPoint #this is old style before the advent of invoke push 0 call GetModuleHandleA mov hInstance eax call GetCommandLineA mov CommandLine eax invoke WinMain hInstance 0 CommandLine 10 push eax call ExitProcess end code #-----------------Resources--------------------------------------- begin resources icon win32app.ico end resources