I already worked on Version 0.30 of my zPlayer... but now I'm gonna develop a complete new Version, wich supports mp3 and video files.
Because this new Version will use a complete different way for playing Video & Audio files, I post the source for the "old" on here.
Please post comments, how you like this Player / coding style :grin:

Have fun with it!

regards,
bAZiK


P.S.: You can ALWAYS ask me for the source of my apps via email!



; ######################################

.486
.model flat, stdcall
option casemap :none

; ######################################

include \masm32\include\windows.inc

include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comctl32.inc
include \masm32\include\comdlg32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\comdlg32.lib

; ######################################

MCIWNDF_NOMENU equ 8h
; MCIWNDF_NOPLAYBAR equ 2h
MCIWNDF_NOTIFYPOS equ 200h

MCIWNDM_NOTIFYPOS equ WM_USER + 201
MCIWNDM_SENDSTRING equ WM_USER + 101
MCIWNDM_GETLENGTH equ WM_USER + 104

CMD_OPEN equ 100
CMD_ABOUT equ 101

; ######################################

.data
szClassName db "zPlayer_Class", 0

wc WNDCLASSEX <sizeof wc, CS_HREDRAW \
or CS_VREDRAW or CS_BYTEALIGNWINDOW, \
offset WndProc, 0, 0, 400000h, \
0, 0, COLOR_BTNFACE + 1, 0, \
offset szClassName, 0>

szAppName db "zPlayer v0.30", 0

szPosition db "%s - %lu / %lu - %s", 0

szOpen db "&Open", 0
szAbout db "&About", 0

szAboutMsg db "zPlayer - smallest Video Player of the world!", 13, 10, \
" ? 2001 by bAZiK ", 13, 10, \
" programmed in 100% Assembly language (MASM) ", 0

szMCIdll db "msvfw32.dll", 0
szMCIWndCreate db "MCIWndCreate", 0

szFilter db "Movies (*.avi, *.mpeg, *.mpg)", 0, "*.avi;*.mpeg;*.mpg", 0, "All files (*.*)", 0, "*.*", 0

; szTestMovie db "D:\DEVELOPMENT\test.mpg", 0
; szTestMovie db "F:\DivX\Passwort Swordfish.avi", 0
; szTestMovie db "D:\DEVELOPMENT\test.avi", 0

; ######################################

.data?
hWnd dd ?
hMCIWnd dd ?
hMenu dd ?

nLength dd ?

szOFNBuffer db 512 dup (?)
szMovieFile db 512 dup (?)
szNewCaption db 128 dup (?)

msg MSG <?>
rect RECT <?>
item MENUITEMINFO <?>
ofn OPENFILENAME <?>

; ######################################

.code

zPlayer:
call WinMain
call InitCommonControls
invoke ExitProcess, eax

; ######################################

WinMain proc
invoke LoadIcon, 400000h, 100
mov wc.hIcon, eax
invoke LoadCursor, 0, IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, addr wc
invoke GetSystemMetrics, SM_CXSCREEN
mov esi,eax
invoke GetSystemMetrics, SM_CYSCREEN
shr esi, 1
shr eax, 1
sub eax, 200/2
sub esi, 300/2

invoke CreateWindowEx, WS_EX_TOPMOST,
addr szClassName,
addr szAppName,
WS_CAPTION or WS_MINIMIZEBOX or WS_SYSMENU or WS_VISIBLE,
esi, eax, 300, 200, 0, 0, 400000h, 0
mov hWnd, eax
invoke ShowWindow, hWnd, SW_SHOWNORMAL
invoke UpdateWindow, hWnd
mov esi, offset msg
@@:
invoke GetMessage, esi, 0, 0, 0
or eax, eax
je @F
invoke TranslateMessage, esi
invoke DispatchMessage, esi
jmp @B
@@:
mov eax, msg.wParam
ret
WinMain endp

; ######################################

WndProc proc hWin :DWORD,uMsg :DWORD, wParam :DWORD, lParam :DWORD

.if uMsg == WM_CREATE

call CreateMenu
mov hMenu, eax

mov item.cbSize, sizeof MENUITEMINFO
mov item.fMask, MIIM_ID or MIIM_TYPE or MIIM_STATE
mov item.fType, MFT_STRING

mov item.wID, CMD_OPEN
mov item.fState, MFS_ENABLED
mov item.dwTypeData, offset szOpen
mov item.cch, sizeof szOpen
invoke InsertMenuItem, hMenu, 0, 0, addr item

mov item.wID, CMD_ABOUT
mov item.fState, MFS_ENABLED
mov item.dwTypeData, offset szAbout
mov item.cch, sizeof szAbout
invoke InsertMenuItem, hMenu, 1, 0, addr item

invoke SetMenu, hWin, hMenu

.elseif uMsg == WM_COMMAND

.if wParam == CMD_OPEN

mov ofn.lStructSize, sizeof OPENFILENAME
push hWin
pop ofn.hwndOwner
mov ofn.hInstance, 40000h
mov ofn.lpstrFilter, offset szFilter
mov ofn.lpstrFile, offset szOFNBuffer
mov ofn.nMaxFile, 512
mov ofn.lpstrTitle, offset szAppName
mov ofn.Flags, OFN_EXPLORER or OFN_FILEMUSTEXIST or OFN_HIDEREADONLY

invoke GetOpenFileName, addr ofn

mov al, byte ptr [szOFNBuffer]
or al, al
jz @F
invoke lstrcpy, addr szMovieFile, addr szOFNBuffer
invoke RtlZeroMemory, addr szOFNBuffer, 512

invoke SendMessage, hWin, WM_SETTEXT, 0, addr szAppName
invoke SendMessage, hMCIWnd, WM_CLOSE, 0, 0

invoke LoadLibrary, addr szMCIdll
push eax
invoke GetProcAddress, eax, addr szMCIWndCreate

push offset szMovieFile
push MCIWNDF_NOTIFYPOS or MCIWNDF_NOMENU ; MCIWNDF_NOPLAYBAR or
push 400000h
push hWin
call eax
mov hMCIWnd, eax
call FreeLibrary

invoke GetWindowRect, hMCIWnd, addr rect
mov eax, rect.top
mov ebx, rect.bottom
sub ebx, eax ; ebx enth?lt h?he
push ebx

mov ecx, rect.left
mov edx, rect.right
sub edx, ecx ; edx enth?lt breite
push edx

invoke MoveWindow, hMCIWnd, 0, 0, edx, ebx, 1
invoke GetWindowRect, hWin, addr rect

pop edx
pop ebx

add ebx, 50
add edx, 5

invoke MoveWindow, hWin, rect.left, rect.top, edx, ebx, 1

mov item.cbSize, sizeof MENUITEMINFO
mov item.fMask, MIIM_STATE
mov item.fState, MFS_ENABLED
invoke SetMenuItemInfo, hMenu, 1, 1, addr item
invoke DrawMenuBar, hWin

invoke SendMessage, hMCIWnd, MCIWNDM_GETLENGTH, 0, 0
mov nLength, eax

@@:

.elseif wParam == CMD_ABOUT
invoke MessageBox, hWin, addr szAboutMsg, addr szAppName, 0

.endif



.elseif uMsg == MCIWNDM_NOTIFYPOS

invoke wsprintf, addr szNewCaption, addr szPosition, addr szAppName, lParam, nLength, addr szMovieFile
invoke SendMessage, hWin, WM_SETTEXT, 0, addr szNewCaption

.elseif uMsg == WM_DESTROY

invoke PostQuitMessage, 0
xor eax, eax
ret

.endif

invoke DefWindowProc, hWin, uMsg, wParam, lParam

ret

WndProc endp

; ######################################

end zPlayer

; ######################################

Posted on 2001-12-29 13:45:11 by bazik
Hi baZiK, I thought I'd bring this thread to the top again because there's a bug in the source (better late then never :)). I don't know if you're still working on this little player but here's it anyway, so you won't have problems with this later.

According to vfw.h, some functions (MCIWndCreate) are using the C calling convention instead of stdcall. Your code calls MCIWndCreate with a couple of pushes and a call, but it needs to cleanup the stack afterwards as well (add esp, 4*4).

I came accross this bug as I was using the MCI control in a C project and dynamically loaded the function as I do not need it all the time. However I declared the function pointer as a stdcall function. Somehow this gave no problems in the debug build (even with visual C's stack checks off) but the release build crashed. I traced the code and found out MCIWndCreate did not change esp so it couldn't be a stdcall function.

Thomas
Posted on 2002-04-29 14:47:29 by Thomas