设为首页收藏本站

如鹏网

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 2106|回复: 12

资源嵌入的问题

[复制链接]

1

主题

0

好友

455

积分

中级会员

Rank: 3Rank: 3

发表于 2009-3-15 10:22:54 |显示全部楼层
我在VC里面调用了一个WAV资源,结果不报错,也能运行,就是不响。我是把这个音乐资源嵌入到程序里面去了。我调用时写的是 PlaySound(TEXT("IDR_WAVE2"),hinstance,SND_RESOURCE|SND_ASYNC);

0

主题

0

好友

1798

积分

金牌会员

Guitar

Rank: 6Rank: 6

发表于 2009-3-15 15:27:04 |显示全部楼层
把你的代码都贴出来看看

    如果你调用的是 PlaySound(XXX , hinstance , XXX , SND_RESOURCE|SND_ASYNC)的资源,应该是没错的啊!

     会不会是没有把音乐文件引入到工程文件夹?

     你编译的时候,有没有报什么错?

0

主题

0

好友

1933

积分

金牌会员

Rank: 6Rank: 6

发表于 2009-3-15 18:30:14 |显示全部楼层
我在vc弄了半天,也不知道怎么添加wave文件资源!他不想cfree有相关的资源编辑器!不过一定要添加mmsystem.h和winmm.lib!

1

主题

0

好友

455

积分

中级会员

Rank: 3Rank: 3

发表于 2009-3-15 21:46:31 |显示全部楼层
代码太长了,主要调用的就是这两句,
HINSTANCE hinstance=(HINSTANCE)GetWindowLong(mvHnd,GWL_HINSTANCE);   
PlaySound(TEXT("IDR_WAVE1"),hinstance,SND_RESOURCE|SND_ASYNC);   
编译可以通过,没有报错,能够正常运行,但就是没有声音。而且如果不嵌入的话,是可以有声音的。这和CFree可是不一样啊

184

主题

0

好友

1万

积分

超级版主

Rank: 8Rank: 8

发表于 2009-3-15 23:12:29 |显示全部楼层
改成这样的方式就可以了:
HINSTANCE hinstance=(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE);   
PlaySound(MAKEINTRESOURCE(IDR_WAVE1),hinstance,SND_RESOURCE|SND_ASYNC);   

至于原因我还需要研究一下。
从这篇文章得到的启发:http://www.qqgb.com/Program/VC/VCJQ/Program_163651.html

1

主题

0

好友

455

积分

中级会员

Rank: 3Rank: 3

发表于 2009-3-16 09:47:28 |显示全部楼层
我试过了,果然好用。

2

主题

0

好友

1049

积分

金牌会员

Rank: 6Rank: 6

发表于 2009-3-16 10:38:11 |显示全部楼层
看来VC也不是很好用嘛,有时候就是没错他就编译不过,你再原原本本重输一次吧,他就能运行起来了,哎感觉还是没有C_Free好用呀!

0

主题

0

好友

158

积分

注册会员

Rank: 2

发表于 2009-5-31 09:58:31 |显示全部楼层
老实说,这种问题是最困扰我们初学者的

因为不知道它的原理在哪,也就很难解决

好在这里从菜鸟 -  老鸟 都热情相助,呵呵

1

主题

0

好友

455

积分

中级会员

Rank: 3Rank: 3

发表于 2009-5-31 12:55:16 |显示全部楼层
我现在觉得初学者不应该把精力放在这上面,应该注重核心内容。

0

主题

0

好友

393

积分

中级会员

Rank: 3Rank: 3

发表于 2009-5-31 13:19:55 |显示全部楼层
The PlaySound function plays a sound specified by the given filename, resource, or system event. (A system event may be associated with a sound in the registry or in the WIN.INI file.)
BOOL PlaySound(  LPCSTR pszSound,    HMODULE hmod,       DWORD fdwSound    );Parameters
pszSound
A string that specifies the sound to play. The maximum length, including the null terminator, is 256 characters. If this parameter is NULL, any currently playing waveform sound is stopped. To stop a non-waveform sound, specify SND_PURGE in the fdwSound parameter.
Three flags in fdwSound (SND_ALIAS, SND_FILENAME, and SND_RESOURCE) determine whether the name is interpreted as an alias for a system event, a filename, or a resource identifier. If none of these flags are specified, PlaySound searches the registry or the WIN.INI file for an association with the specified sound name. If an association is found, the sound event is played. If no association is found in the registry, the name is interpreted as a filename.
.............................................
此问题,还是msdn说的清楚:Three flags in fdwSound (SND_ALIAS, SND_FILENAME, and SND_RESOURCE) determine whether the name is interpreted as an alias for a system event, a filename, or a resource identifier
就是第一个参数是一个文件名还是资源id,取决于第三个参数,由于你第三个参数是SND_RESOURCE,所以第一个参数不能用文件名形式,而要采用资源id这种形式!

0

主题

0

好友

393

积分

中级会员

Rank: 3Rank: 3

发表于 2009-5-31 13:22:05 |显示全部楼层
原帖由 suning 于 2009-5-31 12:55 发表
我现在觉得初学者不应该把精力放在这上面,应该注重核心内容。

我倒不这样认为,有疑问想办法解决,那么就掌握了一定的学习方法,以后学习就比较主动了!

1

主题

0

好友

455

积分

中级会员

Rank: 3Rank: 3

发表于 2009-5-31 14:53:55 |显示全部楼层

1

主题

0

好友

12

积分

新手上路

Rank: 1

发表于 2011-6-2 15:01:53 |显示全部楼层
其他的都不变,把老大那两句改成如下语句:(原理我正在查),如果老大能理解原理,跟大家分享一下

HRSRC hr=FindResource(apphinstance,"IDR_WAVE1","WAVE"); //找到声音资源,IDR_WAVE1是你要通过资源标签要导入的声音资源;apphinstance:全局变量
        HGLOBAL hg=LoadResource(apphinstance,hr); //加载声音资源
        LPSTR lp=(LPSTR)LockResource(hg);
        sndPlaySound(lp,SND_MEMORY|SND_SYNC);//播放
        FreeResource(hg);
您需要登录后才可以回帖 登录 | 注册

手机版|Archiver|如鹏网 ( 粤ICP备09013919号 )   360网站安全检测平台

GMT+8, 2012-5-19 15:41

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部