C# 弹钢琴程序

来源:互联网 发布:大数据的分析方法 编辑:程序博客网 时间:2024/05/01 00:26

网上的flash钢琴老要在浏览器玩,觉得不爽,就写了个window程序,代码如下,至于a-z.mp3,在这里链接http://dl.dbank.com/c0xfx2gjvf
using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
using System.Runtime.InteropServices;


namespace tangangqin
{


   
    public partial class Form1 : Form
    {
        //public static uint SND_ASYNC = 0x0001; //
        //public static uint SND_FILENAME = 0x00020000;


        [DllImport("winmm.dll")]
        public static extern uint mciSendString(string lpstrCommand,
        string lpstrReturnString, uint uReturnLength, uint hWndCallback); 


        public Form1()
        {
            InitializeComponent();
            //mciSendString("status movie volume to 0", null, 0, 0);            
        }


        private void A(object sender, KeyPressEventArgs e)
        {
//A-G.mp3低音   H-N.mp3中音 O-U.mp3高音 V-Z.mp3超高音
//1-A 1-H 1-O 1-V
//2-B 2-I 2-P 2-W
//3-C 3-J 3-Q 3-X
//4-D 4-K 4-R 4-Y
//5-E 5-L 5-S 5-Z
//6-F 6-M 6-T 6-
//7-G 7-N 7-U 7-
            if (char.IsLetter(e.KeyChar))//如果按的是字符
            {
                //D:\Download\Silverlightkey\codefans.net\键盘钢琴\AphroditePiano\Sound\目录,保存了A.mp3  B.mp3  C.mp3到Z.mp3,分别存放了不同的音阶MP3文件
                string keyname = char.ToUpper(e.KeyChar)+".mp3";
                string path = @"D:\Download\Silverlightkey\codefans.net\键盘钢琴\AphroditePiano\Sound\";
                string alldir = path + keyname;


                mciSendString(@"close temp_alias", null, 0, 0);
                mciSendString(@"open "+alldir+" alias temp_alias", null, 0, 0);
                //("play temp_alias repeat", null, 0, 0);
                mciSendString("play temp_alias ", null, 0, 0); 
            }
        }
    }
}
原创粉丝点击