按照winamp的nsdn的资料,在c++中可以用
int index = SendMessage(hwnd_winamp, WM_USER, 0, IPC_GETLISTPOS);
char *name = SendMessage(hwnd_winamp, WM_USER, index, IPC_GETPLAYLISTFILE);
的方法返回文件名,但是在vb中如何得到我没有找到办法,因此自己尝试写一下,发现IPC_GETPLAYLISTFILE返回的是相对winamp进程的地址,所以想读出字符串必须通过跨进程内存存取的方法取回字符串,幸好只是读取一个字符串,仔细琢磨一下还是不难的。大概向下面这样就可以了。
Private Const MAX_PATH As Long = 255
Private hWndWinamp As Long
Private Function GetWinampWindow() As Long
GetWinampWindow = FindWindow( "Winamp v1.x", vbNullString)
End Function
Public Function GetPlayingFileName() As String
Dim strFileName As String
Dim lp As Long, lpWinamp As Long
Dim iIndex As Long
Dim PID As Long
Dim bRet As Long
Dim dwRead As Long
Dim strTMP As String
Dim Temp As String
'得到winamp窗口的句柄
hWndWinamp = GetWinampWindow
If hWndWinamp = 0 Then
GetPlayingFileName = ""
Exit Function
End If
'返回正在播放文件的在playlist中的索引
iIndex = SendMessage(hWndWinamp, WM_USER, 0, IPC_GETLISTPOS)
'得到此文件入口指针
lp = SendMessage(hWndWinamp, WM_USER, iIndex, IPC_GETPLAYLISTFILE)
If lp = 0 Then
GetPlayingFileName = ""
Exit Function
End If
'下面几步就是跨进程读取刚才返回地址的数据
Call GetWindowThreadProcessId(hWndWinamp, PID)
lpWinamp = OpenProcess(PROCESS_VM_READ, 0, PID)
If lpWinamp = 0 Then
GetPlayingFileName = ""
Exit Function
End If
strTMP = String(MAX_PATH, vbNullChar)
bRet = ReadProcessMemory(lpWinamp, lp, ByVal strTMP, MAX_PATH, dwRead)
Call CloseHandle(lpWinamp)
strFileName = Left$(strTMP, InStr(strTMP, Chr$(0)) - 1)
GetPlayingFileName = strFileName
End Function
|
API 声明略!
留言反馈
在这步之前的都能执行,并且正确。但这步没有返回正确的值不知为什么