| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 738 人关注过本帖
标题:[求助]怎样播放资源文件中的MIDI文件.
只看楼主 加入收藏
gkimjatl
Rank: 1
等 级:新手上路
帖 子:106
专家分:0
注 册:2007-3-20
收藏
 问题点数:0 回复次数:2 
[求助]怎样播放资源文件中的MIDI文件.
同标题.
搜索更多相关主题的帖子: MIDI 资源 文件 播放 
2007-05-28 14:44
kobe412
Rank: 1
来 自:网络的另一边
等 级:新手上路
威 望:1
帖 子:322
专家分:0
注 册:2006-6-12
收藏
得分:0 

可以将资源文件中包含的MIDI再还原成MIDI文件然后在进行播放。在源代下载栏目中有配套代码。下面是例子:
1、程序包含一个窗体,及两个按钮。
2、程序还包含一个资源文件其中还包含一个类型为MIDI,标示号为101的MIDI文件。

\'Form Code

Private Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrCommand As String) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

Private Const GENERIC_WRITE = &H40000000
Private Const CREATE_ALWAYS = 2
Private Const FILE_ATTRIBUTE_NORMAL = &H80

Private Sub Command1_Click()
Dim hNewFile As Long, bBytes() As Byte
Dim nSize As Long
If Dir("C:\\Love.mid") <> "Love.mid" Then
bBytes = LoadResData(101, "MIDI")
hNewFile = CreateFile("C:\\Love.mid", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
nSize = UBound(bBytes) - LBound(bBytes) + 1 \'Byte =GetFileSize(hOrgFile, 0)
WriteFile hNewFile, bBytes(0), nSize, nSize, ByVal 0&
CloseHandle hNewFile
End If
mciExecute "play C:\\Love.mid"
End Sub

Private Sub Command2_Click()
mciExecute "Close C:\\Love.mid"
End Sub


俺这么帅气的人,俺为了挖矿打光棍俺容易吗?
2007-05-28 15:24
gkimjatl
Rank: 1
等 级:新手上路
帖 子:106
专家分:0
注 册:2007-3-20
收藏
得分:0 
出错拉.

图片附件: 游客没有浏览图片的权限,请 登录注册

2007-05-28 21:22
快速回复:[求助]怎样播放资源文件中的MIDI文件.
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027167 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved