之前并没有考虑要扩展支持多种音频格式,对于多种格式支持时出现了小麻烦。
开始时,准备用In_Module中的
int (*IsOurFile)(char *szFile); // 检查文件格式
发现不好用,无论与否好像都返回0,这样我就没办法了,并且占CPU很多。
于是自己搞个扩展名识别也行的,如对于.mp3和.flac格式分别调用各自的模块就搞定了。
所以要实现扩展名识别。
------------------------------------
PathFindExtension //得到文件扩展名api
Searches a path for an extension.
LPTSTR PathFindExtension(
LPCTSTR pPath //输入参数是一个路径地址,返回扩展名首址;
//如"D:\masm32\lcd\lcd.asm",则可返回".asm"的首址
); //汇编中返回值在eax中
Parameters
pPath
[in] Pointer to a null-terminated string of maximum length MAX_PATH that
contains the path that contains the extension for which to search.
Return Values
Returns the address of the "." preceding the extension within pPath
if an extension is found, or the address of the trailing NULL character otherwise.
Requirements
Version 4.71 and later of Shlwapi.dll
Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with Internet Explorer 4.0 or later).
Windows 95/98/Me: Requires Windows 98 (or Windows 95 with Internet Explorer 4.0 or later).
Header: Declared in Shlwapi.h. //masm32中用include Shlwapi.inc
Import Library: Shlwapi.lib.
------------------------------------
功能实现如下:
.data
stOpenFileName OPENFILENAME <?>
szTitleSave db "Open MUSIC file...",0
szExt db '*.*',0
szMp3 db '.mp3',0
szFilter db 'MUSIC Files(*.mp3,*.flac)',0,'*.*',0,0
.data?
szBuffer db 256 dup (?)
.........
;*******************************************************************
//利用托此控件来得到我们所要的路径地址(在szBuffer缓存中)
_GetFileName proc
mov stOpenFileName.Flags,OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST
mov stOpenFileName.lStructSize,SIZEOF stOpenFileName
mov eax,hDlg
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
ret
_GetFileName endp
;********************************************************************
invoke _GetFileName
invoke PathFindExtension,offset szBuffer//得到扩展名地址(返回值在eax中)
invoke lstrcmpi, offset szMp3, eax //进行比较两个扩展名字符串是否相等(如果相等则返回0)
.if eax==0
........//做出相应动作