1.下載 Do Re Mi.wav 之音樂檔
2. 打開Code Blocks 創建新的Console application專案
3.Key上程式碼
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
PlaySoundA("Do.wav", NULL, SND_SYNC);
PlaySoundA("Re.wav", NULL, SND_SYNC);
PlaySoundA("Mi.wav", NULL, SND_SYNC);
return 0;
}
4.按右鍵=>選Build options
5.Add winmm
6.將音樂檔壓縮放到Code Blocks資料夾裡
7.執行後會播放音樂
作業二
1.打開Code Blocks 創建新的Console application專案
2.Key上程式碼
#include <iostream>
#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
using namespace std;
void display()
{
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1') PlaySoundA("Do.wav",NULL,SND_ASYNC);
if(key=='2') PlaySoundA("Re.wav",NULL,SND_ASYNC);
if(key=='3') PlaySoundA("Mi.wav",NULL,SND_ASYNC);
if(key=='4') PlaySoundA("Fa.wav",NULL,SND_ASYNC);
if(key=='5') PlaySoundA("Sol.wav",NULL,SND_ASYNC);
if(key=='6') PlaySoundA("La.wav",NULL,SND_ASYNC);
if(key=='7') PlaySoundA("Si.wav",NULL,SND_ASYNC);
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("3D sound version");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
3.按右鍵=>選Build options
4.新增
freeglut
opengl32
glu32
gdi32
winmm
5.新增 freeglut\include
6.新增 freeglut\lib
7.執行後會發出聲音










沒有留言:
張貼留言