[已解决]请教程序运行后如何关联相应文件播放
本帖最后由 kxing 于 2011-1-30 12:10 编辑我想写一个播放器。在双击某音乐文件时自动调用该波放器播放。
当该播放器已经处于运行状态时直接载入该音乐播放。不要另开进程。
重点在载入播放的问题上,希望高手们解答。
多谢! 这个不太懂的.. 这个东西好像从注册表入手 注册表的也只能做到关联调用程序.
但是程序运行后就没辙了!!!! 本帖最后由 xxoojoeooxx 于 2011-1-29 00:49 编辑
之前写过给个部分代码出来看看
透过传送wm_copydata讯息
GUIRegisterMsg(0x4A, '_Rec')
$FileN="" ;档名
$hWnd = WinGetHandle('Player ')
If NOT @error Then
$message = 'play' ;传送播放讯息
$struct = DllStructCreate('wchar var1')
DllStructSetData($struct, 1, $message&"|"& $FileN)
$pStruct = DllStructGetPtr($struct)
$struct2 = DllStructCreate('dword;dword;ptr')
DllStructSetData($struct2, 1, 0)
DllStructSetData($struct2, 2, 1000)
DllStructSetData($struct2, 3, $pStruct)
$pStruct2 = DllStructGetPtr($struct2)
_SendMessage($hWnd, 0x4A, 0, $pStruct2)
Exit 0;
EndIf
接收
Func _Rec($hWnd, $iMsg, $iwParam, $ilParam)
$S1 = DllStructCreate('dword var1;dword var2;ptr var3', $ilParam)
$S2 = DllStructGetData($S1, 3)
$S3 = DllStructCreate('wchar var1', $S2)
$S4 = DllStructGetData($S3, 1)
$Split= StringSplit($S4,'|')
$file = $Split
$message =$Split
;加入播放动作
EndFunc ;==>_Rec
many thanks!!! 能简单写个例子吗,小弟不才看不太明白.
#include <Sound.au3>
#include <Constants.au3>
#include <SendMessage.au3>
Opt("TrayMenuMode",1)
Dim $FileN
#Region
If $CmdLine >0 Then
$FileN= $CmdLine
$hWnd = WinGetHandle('Player ')
If NOT @error Then
$message = 'play'
$struct = DllStructCreate('wchar var1')
DllStructSetData($struct, 1, $message&"|"& $FileN)
$pStruct = DllStructGetPtr($struct)
$struct2 = DllStructCreate('dword;dword;ptr')
DllStructSetData($struct2, 1, 0)
DllStructSetData($struct2, 2, 1000)
DllStructSetData($struct2, 3, $pStruct)
$pStruct2 = DllStructGetPtr($struct2)
_SendMessage($hWnd, 0x4A, 0, $pStruct2)
Exit 0;
Else
$sound=_SoundOpen ($FileN, "Startup")
_SoundPlay($sound,0)
EndIf
EndIf
#EndRegion
#Region
GUICreate("Player ")
GUISetState(@SW_HIDE)
$Nameitem = TrayCreateItem($FileN)
TrayCreateItem("")
$Openitem = TrayCreateItem("Open")
$Playitem = TrayCreateItem("Play")
$Exititem = TrayCreateItem("Exit")
#EndRegion
;~ AutoItWinSetTitle("Player ")
ConsoleWrite(AutoItWinGetTitle())
GUIRegisterMsg(0x4A, '_Rec')
While 1
$msg = TrayGetMsg()
Select
Case $msg = $openitem
$File = FileOpenDialog("Choose file...","","Music (*.mp3;*.wma;*.wav)")
if $File<>"" then
if $FileN<>"" then _SoundClose ($sound)
$FileN=$File
$sound=_SoundOpen ($FileN)
_SoundPlay($sound,0)
TrayItemSetText($nameitem,$FileN)
Endif
Case $msg = $playitem
if $FileN<>"" then
_SoundPlay($sound,0)
Endif
Case $msg = $exititem
Exit 0
EndSelect
WEnd
Func _Rec($hWnd, $iMsg, $iwParam, $ilParam)
$S1 = DllStructCreate('dword var1;dword var2;ptr var3', $ilParam)
$S2 = DllStructGetData($S1, 3)
$S3 = DllStructCreate('wchar var1', $S2)
$S4 = DllStructGetData($S3, 1)
$Split= StringSplit($S4,'|')
$File = $Split
$message =$Split
if $File<>"" then
if $FileN<>"" then _SoundClose ($sound)
$FileN=$File
$sound=_SoundOpen ($FileN)
_SoundPlay($sound,0)
TrayItemSetText($nameitem,$FileN)
Endif
EndFunc ;==>_Rec
感谢老兄,十分感谢!!
页:
[1]