只问耕耘
分类: WINDOWS
2010-03-04 17:02:49
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 是否包括调试代码
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DEBUG = 0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Programmed by 罗云彬,
; Website:
; LuoYunBin's Win32 ASM page (罗云彬的编程乐园)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 版本信息
; Mp3 播放测试程序 Ver 1.0 - 2000/06/08
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat, stdcall
option casemap :none ; case sensitive
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 数据
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
include kernel32.inc
include comctl32.inc
include comdlg32.inc
include winmm.inc
includelib user32.lib
includelib kernel32.lib
includelib comctl32.lib
includelib comdlg32.lib
includelib winmm.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Equ 数据
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DLG_MAIN equ 1000
ID_BROWSE equ 1001
ID_FILE equ 1002
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
dwFlag dd ?
hWinMain dd ?
hInstance dd ?
hDevice dd ?
szBuffer db 256 dup (?)
stOpenFileName OPENFILENAME >
.data
szCaption db "Error...",0
szError db "Error to play MP3 file!",0
szPlay db "&Play",0
szStop db "&Stop",0
szDevice db "MPEGVideo",0
szTitleSave db "Open MP3 file...",0
szExt db '*.mp3',0
szFilter db 'MP3 Files(*.mp3)',0,'*.mp3',0,'All Files(*.*)',0,'*.*',0,0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 子程序声明
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcDlgMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
if DEBUG
include Debug.asm
endif
include Win.asm
;********************************************************************
_GetFileName proc
mov stOpenFileName.Flags,OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST
mov stOpenFileName.lStructSize,SIZEOF stOpenFileName
mov eax,hWinMain
mov stOpenFileName.hWndOwner,eax
mov stOpenFileName.lpstrFilter,offset szFilter ;扩展名
mov stOpenFileName.lpstrFile,offset szBuffer ;文件名缓冲
mov stOpenFileName.nMaxFile,255 ;文件名缓冲长度
mov stOpenFileName.lpstrInitialDir,0
mov stOpenFileName.lpstrTitle,offset szTitleSave
mov stOpenFileName.lpstrDefExt,offset szExt
invoke GetOpenFileName,offset stOpenFileName
.if eax == FALSE
ret
.endif
invoke SetDlgItemText,hWinMain,ID_FILE,addr szBuffer
call _StopPlayMP3
ret
_GetFileName endp
;********************************************************************
_PlayMP3 proc
local @stMCIOpen:MCI_OPEN_PARMS
local @stMCIPlay:MCI_PLAY_PARMS
mov @stMCIOpen.lpstrDeviceType,offset szDevice
mov @stMCIOpen.lpstrElementName,offset szBuffer
invoke mciSendCommand,0,MCI_OPEN,MCI_OPEN_TYPE or MCI_OPEN_ELEMENT,addr @stMCIOpen
mov eax,@stMCIOpen.wDeviceID
mov hDevice,eax
mov eax,hWinMain
mov @stMCIPlay.dwCallback,eax
invoke mciSendCommand,hDevice,MCI_PLAY,MCI_NOTIFY,addr @stMCIPlay
.if eax == 0
invoke SetDlgItemText,hWinMain,IDOK,offset szStop
mov dwFlag,1
.else
invoke MessageBox,hWinMain,addr szError,addr szCaption,MB_OK
.endif
ret
_PlayMP3 endp
;********************************************************************
_StopPlayMP3 proc
local @stMCIStop:MCI_GENERIC_PARMS
mov eax,hWinMain
mov @stMCIStop.dwCallback,eax
invoke mciSendCommand,hDevice,MCI_STOP,MCI_NOTIFY,addr @stMCIStop
invoke mciSendCommand,hDevice,MCI_CLOSE,MCI_NOTIFY,addr @stMCIStop
invoke SetDlgItemText,hWinMain,IDOK,offset szPlay
mov dwFlag,0
ret
_StopPlayMP3 endp
;********************************************************************
_ProcDlgMain proc uses ebx edi esi, \
hWnd:DWORD,wMsg:DWORD,wParam:DWORD,lParam:DWORD
mov eax,wMsg
.if eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif eax == WM_INITDIALOG
mov eax,hWnd
mov hWinMain,eax
invoke _CenterWindow,eax
invoke SendDlgItemMessage,hWinMain,ID_FILE,EM_SETREADONLY,TRUE,NULL
.elseif eax == WM_COMMAND
mov eax,wParam
.if eax == ID_BROWSE
call _GetFileName
.elseif eax == IDOK
.if dwFlag == 0
call _PlayMP3
.else
call _StopPlayMP3
.endif
.endif
.else
;********************************************************************
; 注意:对话框的消息处理后,要返回 TRUE,对没有处理的消息
; 要返回 FALSE
;********************************************************************
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
;********************************************************************
start:
invoke InitCommonControls
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,0
invoke ExitProcess,NULL
end start